1// Copyright (c) 2010 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/file_util.h" 8#include "chrome/browser/chromeos/cros/cros_library.h" 9#include "chrome/browser/chromeos/cros/login_library.h" 10#include "chrome/browser/profiles/profile.h" 11#include "content/browser/browser_thread.h" 12 13namespace chromeos { 14 15EnterpriseExtensionObserver::EnterpriseExtensionObserver(Profile* profile) 16 : profile_(profile) { 17 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 18 registrar_.Add(this, 19 NotificationType::EXTENSION_INSTALLED, 20 Source<Profile>(profile_)); 21} 22 23void EnterpriseExtensionObserver::Observe(NotificationType type, 24 const NotificationSource& source, 25 const NotificationDetails& details) { 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 27 DCHECK(type == NotificationType::EXTENSION_INSTALLED); 28 if (Source<Profile>(source).ptr() != profile_) { 29 return; 30 } 31 Extension* extension = Details<Extension>(details).ptr(); 32 if (extension->location() != Extension::EXTERNAL_POLICY_DOWNLOAD) { 33 return; 34 } 35 BrowserThread::PostTask( 36 BrowserThread::FILE, 37 FROM_HERE, 38 NewRunnableFunction( 39 &EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd, 40 extension->path())); 41} 42 43// static 44void EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd( 45 const FilePath& path) { 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 47 if (file_util::PathExists( 48 path.Append(FILE_PATH_LITERAL("isa-cros-policy")))) { 49 BrowserThread::PostTask( 50 BrowserThread::UI, 51 FROM_HERE, 52 NewRunnableFunction(&EnterpriseExtensionObserver::NotifyEntd)); 53 } 54} 55 56// static 57void EnterpriseExtensionObserver::NotifyEntd() { 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 59 if (CrosLibrary::Get()->EnsureLoaded()) { 60 CrosLibrary::Get()->GetLoginLibrary()->RestartEntd(); 61 return; 62 } 63} 64 65} // namespace chromeos 66