blob: 5ae21c555325634b301404d70c3434379a43c309 [file] [log] [blame]
[email protected]64e199252012-04-06 01:54:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]62cb9942010-12-01 13:09:322// 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]e29a92a9d2011-10-20 05:23:577#include "base/bind.h"
[email protected]62cb9942010-12-01 13:09:328#include "base/file_util.h"
[email protected]fdf40f3e2013-07-11 23:55:469#include "chrome/browser/chrome_notification_types.h"
[email protected]8ecad5e2010-12-02 21:18:3310#include "chrome/browser/profiles/profile.h"
[email protected]64e199252012-04-06 01:54:3611#include "chromeos/dbus/dbus_thread_manager.h"
12#include "chromeos/dbus/session_manager_client.h"
[email protected]c38831a12011-10-28 12:44:4913#include "content/public/browser/browser_thread.h"
[email protected]62cb9942010-12-01 13:09:3214
[email protected]631bb742011-11-02 11:29:3915using content::BrowserThread;
16
[email protected]62cb9942010-12-01 13:09:3217namespace chromeos {
18
19EnterpriseExtensionObserver::EnterpriseExtensionObserver(Profile* profile)
20 : profile_(profile) {
21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
22 registrar_.Add(this,
[email protected]432115822011-07-10 15:52:2723 chrome::NOTIFICATION_EXTENSION_INSTALLED,
[email protected]6c2381d2011-10-19 02:52:5324 content::Source<Profile>(profile_));
[email protected]62cb9942010-12-01 13:09:3225}
26
[email protected]6c2381d2011-10-19 02:52:5327void EnterpriseExtensionObserver::Observe(
28 int type,
29 const content::NotificationSource& source,
30 const content::NotificationDetails& details) {
[email protected]62cb9942010-12-01 13:09:3231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]432115822011-07-10 15:52:2732 DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED);
[email protected]6c2381d2011-10-19 02:52:5333 if (content::Source<Profile>(source).ptr() != profile_) {
[email protected]62cb9942010-12-01 13:09:3234 return;
35 }
[email protected]41bb80bd2013-05-03 10:56:0236 const extensions::Extension* extension =
37 content::Details<const extensions::InstalledExtensionInfo>(details)->
38 extension;
[email protected]1c321ee52012-05-21 03:02:3439 if (extension->location() !=
[email protected]1d5e58b2013-01-31 08:41:4040 extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD) {
[email protected]62cb9942010-12-01 13:09:3241 return;
42 }
43 BrowserThread::PostTask(
44 BrowserThread::FILE,
45 FROM_HERE,
[email protected]e29a92a9d2011-10-20 05:23:5746 base::Bind(
[email protected]62cb9942010-12-01 13:09:3247 &EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd,
48 extension->path()));
49}
50
51// static
52void EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd(
[email protected]650b2d52013-02-10 03:41:4553 const base::FilePath& path) {
[email protected]62cb9942010-12-01 13:09:3254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
[email protected]7567484142013-07-11 17:36:0755 if (base::PathExists(
[email protected]62cb9942010-12-01 13:09:3256 path.Append(FILE_PATH_LITERAL("isa-cros-policy")))) {
57 BrowserThread::PostTask(
58 BrowserThread::UI,
59 FROM_HERE,
[email protected]e29a92a9d2011-10-20 05:23:5760 base::Bind(&EnterpriseExtensionObserver::NotifyEntd));
[email protected]62cb9942010-12-01 13:09:3261 }
62}
63
64// static
65void EnterpriseExtensionObserver::NotifyEntd() {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]089e30352011-10-29 05:25:5167 DBusThreadManager::Get()->GetSessionManagerClient()->RestartEntd();
[email protected]62cb9942010-12-01 13:09:3268}
69
70} // namespace chromeos