| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/policy/app_pack_updater.h" | 5 #include "chrome/browser/chromeos/policy/app_pack_updater.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 10 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 9 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 10 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 12 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 11 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 13 #include "chrome/browser/extensions/external_loader.h" | 12 #include "chrome/browser/extensions/external_loader.h" |
| 14 #include "chrome/browser/extensions/external_provider_impl.h" | 13 #include "chrome/browser/extensions/external_provider_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_details.h" | |
| 17 #include "content/public/browser/notification_service.h" | |
| 18 #include "content/public/browser/notification_source.h" | |
| 19 | 15 |
| 20 using content::BrowserThread; | 16 using content::BrowserThread; |
| 21 | 17 |
| 22 namespace policy { | 18 namespace policy { |
| 23 | 19 |
| 24 namespace { | 20 namespace { |
| 25 | 21 |
| 26 // Directory where the AppPack extensions are cached. | 22 // Directory where the AppPack extensions are cached. |
| 27 const char kAppPackCacheDir[] = "/var/cache/app_pack"; | 23 const char kAppPackCacheDir[] = "/var/cache/app_pack"; |
| 28 | 24 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 56 |
| 61 DISALLOW_COPY_AND_ASSIGN(AppPackExternalLoader); | 57 DISALLOW_COPY_AND_ASSIGN(AppPackExternalLoader); |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, | 60 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, |
| 65 EnterpriseInstallAttributes* install_attributes) | 61 EnterpriseInstallAttributes* install_attributes) |
| 66 : weak_ptr_factory_(this), | 62 : weak_ptr_factory_(this), |
| 67 created_extension_loader_(false), | 63 created_extension_loader_(false), |
| 68 install_attributes_(install_attributes), | 64 install_attributes_(install_attributes), |
| 69 external_cache_(kAppPackCacheDir, request_context, this, false) { | 65 external_cache_(kAppPackCacheDir, request_context, this, false) { |
| 70 chromeos::CrosSettings::Get()->AddSettingsObserver(chromeos::kAppPack, this); | 66 app_pack_subscription_ = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 67 chromeos::kAppPack, |
| 68 base::Bind(&AppPackUpdater::AppPackChanged, base::Unretained(this))); |
| 71 | 69 |
| 72 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) { | 70 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) { |
| 73 // Already in Kiosk mode, start loading. | 71 // Already in Kiosk mode, start loading. |
| 74 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 72 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 75 base::Bind(&AppPackUpdater::LoadPolicy, | 73 base::Bind(&AppPackUpdater::LoadPolicy, |
| 76 weak_ptr_factory_.GetWeakPtr())); | 74 weak_ptr_factory_.GetWeakPtr())); |
| 77 } else { | 75 } else { |
| 78 // Linger until the device switches to DEVICE_MODE_RETAIL_KIOSK and the | 76 // Linger until the device switches to DEVICE_MODE_RETAIL_KIOSK and the |
| 79 // app pack device setting appears. | 77 // app pack device setting appears. |
| 80 } | 78 } |
| 81 } | 79 } |
| 82 | 80 |
| 83 AppPackUpdater::~AppPackUpdater() { | 81 AppPackUpdater::~AppPackUpdater() { |
| 84 chromeos::CrosSettings::Get()->RemoveSettingsObserver( | |
| 85 chromeos::kAppPack, this); | |
| 86 } | 82 } |
| 87 | 83 |
| 88 extensions::ExternalLoader* AppPackUpdater::CreateExternalLoader() { | 84 extensions::ExternalLoader* AppPackUpdater::CreateExternalLoader() { |
| 89 if (created_extension_loader_) { | 85 if (created_extension_loader_) { |
| 90 NOTREACHED(); | 86 NOTREACHED(); |
| 91 return NULL; | 87 return NULL; |
| 92 } | 88 } |
| 93 created_extension_loader_ = true; | 89 created_extension_loader_ = true; |
| 94 AppPackExternalLoader* loader = new AppPackExternalLoader(); | 90 AppPackExternalLoader* loader = new AppPackExternalLoader(); |
| 95 extension_loader_ = loader->AsWeakPtr(); | 91 extension_loader_ = loader->AsWeakPtr(); |
| 96 | 92 |
| 97 // The cache may have been already checked. In that case, load the current | 93 // The cache may have been already checked. In that case, load the current |
| 98 // extensions into the loader immediately. | 94 // extensions into the loader immediately. |
| 99 UpdateExtensionLoader(); | 95 UpdateExtensionLoader(); |
| 100 | 96 |
| 101 return loader; | 97 return loader; |
| 102 } | 98 } |
| 103 | 99 |
| 104 void AppPackUpdater::SetScreenSaverUpdateCallback( | 100 void AppPackUpdater::SetScreenSaverUpdateCallback( |
| 105 const AppPackUpdater::ScreenSaverUpdateCallback& callback) { | 101 const AppPackUpdater::ScreenSaverUpdateCallback& callback) { |
| 106 screen_saver_update_callback_ = callback; | 102 screen_saver_update_callback_ = callback; |
| 107 if (!screen_saver_update_callback_.is_null() && !screen_saver_path_.empty()) { | 103 if (!screen_saver_update_callback_.is_null() && !screen_saver_path_.empty()) { |
| 108 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 109 BrowserThread::UI, FROM_HERE, | 105 BrowserThread::UI, FROM_HERE, |
| 110 base::Bind(screen_saver_update_callback_, screen_saver_path_)); | 106 base::Bind(screen_saver_update_callback_, screen_saver_path_)); |
| 111 } | 107 } |
| 112 } | 108 } |
| 113 | 109 |
| 114 void AppPackUpdater::Observe(int type, | 110 void AppPackUpdater::AppPackChanged() { |
| 115 const content::NotificationSource& source, | 111 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) |
| 116 const content::NotificationDetails& details) { | 112 LoadPolicy(); |
| 117 switch (type) { | |
| 118 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: | |
| 119 DCHECK_EQ(chromeos::kAppPack, | |
| 120 *content::Details<const std::string>(details).ptr()); | |
| 121 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) | |
| 122 LoadPolicy(); | |
| 123 break; | |
| 124 | |
| 125 default: | |
| 126 NOTREACHED(); | |
| 127 } | |
| 128 } | 113 } |
| 129 | 114 |
| 130 void AppPackUpdater::LoadPolicy() { | 115 void AppPackUpdater::LoadPolicy() { |
| 131 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 116 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
| 132 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues( | 117 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues( |
| 133 base::Bind(&AppPackUpdater::LoadPolicy, | 118 base::Bind(&AppPackUpdater::LoadPolicy, |
| 134 weak_ptr_factory_.GetWeakPtr()))) { | 119 weak_ptr_factory_.GetWeakPtr()))) { |
| 135 return; | 120 return; |
| 136 } | 121 } |
| 137 | 122 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { | 197 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { |
| 213 // Don't invoke the callback if the path isn't changing. | 198 // Don't invoke the callback if the path isn't changing. |
| 214 if (path != screen_saver_path_) { | 199 if (path != screen_saver_path_) { |
| 215 screen_saver_path_ = path; | 200 screen_saver_path_ = path; |
| 216 if (!screen_saver_update_callback_.is_null()) | 201 if (!screen_saver_update_callback_.is_null()) |
| 217 screen_saver_update_callback_.Run(screen_saver_path_); | 202 screen_saver_update_callback_.Run(screen_saver_path_); |
| 218 } | 203 } |
| 219 } | 204 } |
| 220 | 205 |
| 221 } // namespace policy | 206 } // namespace policy |
| OLD | NEW |