Home | History | Annotate | Download | only in chromeos
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      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 
      7 #include "base/bind.h"
      8 #include "base/file_util.h"
      9 #include "chrome/browser/chrome_notification_types.h"
     10 #include "chrome/browser/profiles/profile.h"
     11 #include "chromeos/dbus/dbus_thread_manager.h"
     12 #include "chromeos/dbus/session_manager_client.h"
     13 #include "content/public/browser/browser_thread.h"
     14 
     15 using content::BrowserThread;
     16 
     17 namespace chromeos {
     18 
     19 EnterpriseExtensionObserver::EnterpriseExtensionObserver(Profile* profile)
     20     : profile_(profile) {
     21   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     22   registrar_.Add(this,
     23                  chrome::NOTIFICATION_EXTENSION_INSTALLED,
     24                  content::Source<Profile>(profile_));
     25 }
     26 
     27 void EnterpriseExtensionObserver::Observe(
     28     int type,
     29     const content::NotificationSource& source,
     30     const content::NotificationDetails& details) {
     31   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     32   DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED);
     33   if (content::Source<Profile>(source).ptr() != profile_) {
     34     return;
     35   }
     36   const extensions::Extension* extension =
     37       content::Details<const extensions::InstalledExtensionInfo>(details)->
     38           extension;
     39   if (extension->location() !=
     40       extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD) {
     41     return;
     42   }
     43   BrowserThread::PostTask(
     44       BrowserThread::FILE,
     45       FROM_HERE,
     46       base::Bind(
     47           &EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd,
     48           extension->path()));
     49 }
     50 
     51 // static
     52 void EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd(
     53     const base::FilePath& path) {
     54   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
     55   if (base::PathExists(
     56       path.Append(FILE_PATH_LITERAL("isa-cros-policy")))) {
     57     BrowserThread::PostTask(
     58         BrowserThread::UI,
     59         FROM_HERE,
     60         base::Bind(&EnterpriseExtensionObserver::NotifyEntd));
     61   }
     62 }
     63 
     64 // static
     65 void EnterpriseExtensionObserver::NotifyEntd() {
     66   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
     67   DBusThreadManager::Get()->GetSessionManagerClient()->RestartEntd();
     68 }
     69 
     70 }  // namespace chromeos
     71