[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/chromeos/enterprise_extension_observer.h" | ||||
6 | |||||
[email protected] | e29a92a9d | 2011-10-20 05:23:57 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 8 | #include "base/file_util.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 9 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 11 | #include "chromeos/dbus/dbus_thread_manager.h" |
12 | #include "chromeos/dbus/session_manager_client.h" | ||||
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 13 | #include "content/public/browser/browser_thread.h" |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 14 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 15 | using content::BrowserThread; |
16 | |||||
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 17 | namespace chromeos { |
18 | |||||
19 | EnterpriseExtensionObserver::EnterpriseExtensionObserver(Profile* profile) | ||||
20 | : profile_(profile) { | ||||
21 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | ||||
22 | registrar_.Add(this, | ||||
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 23 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 24 | content::Source<Profile>(profile_)); |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 25 | } |
26 | |||||
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 27 | void EnterpriseExtensionObserver::Observe( |
28 | int type, | ||||
29 | const content::NotificationSource& source, | ||||
30 | const content::NotificationDetails& details) { | ||||
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 31 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 32 | DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED); |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 33 | if (content::Source<Profile>(source).ptr() != profile_) { |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 34 | return; |
35 | } | ||||
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 36 | const extensions::Extension* extension = |
37 | content::Details<const extensions::InstalledExtensionInfo>(details)-> | ||||
38 | extension; | ||||
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 39 | if (extension->location() != |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 40 | extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD) { |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 41 | return; |
42 | } | ||||
43 | BrowserThread::PostTask( | ||||
44 | BrowserThread::FILE, | ||||
45 | FROM_HERE, | ||||
[email protected] | e29a92a9d | 2011-10-20 05:23:57 | [diff] [blame] | 46 | base::Bind( |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 47 | &EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd, |
48 | extension->path())); | ||||
49 | } | ||||
50 | |||||
51 | // static | ||||
52 | void EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd( | ||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 53 | const base::FilePath& path) { |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 54 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 55 | if (base::PathExists( |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 56 | path.Append(FILE_PATH_LITERAL("isa-cros-policy")))) { |
57 | BrowserThread::PostTask( | ||||
58 | BrowserThread::UI, | ||||
59 | FROM_HERE, | ||||
[email protected] | e29a92a9d | 2011-10-20 05:23:57 | [diff] [blame] | 60 | base::Bind(&EnterpriseExtensionObserver::NotifyEntd)); |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 61 | } |
62 | } | ||||
63 | |||||
64 | // static | ||||
65 | void EnterpriseExtensionObserver::NotifyEntd() { | ||||
66 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | ||||
[email protected] | 089e3035 | 2011-10-29 05:25:51 | [diff] [blame] | 67 | DBusThreadManager::Get()->GetSessionManagerClient()->RestartEntd(); |
[email protected] | 62cb994 | 2010-12-01 13:09:32 | [diff] [blame] | 68 | } |
69 | |||||
70 | } // namespace chromeos |