Chromium Code Reviews| 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" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 10 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 11 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 12 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 13 #include "chrome/browser/extensions/external_loader.h" | 13 #include "chrome/browser/extensions/external_loader.h" |
| 14 #include "chrome/browser/extensions/external_provider_impl.h" | 14 #include "chrome/browser/extensions/external_provider_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
|
Lei Zhang
2013/09/18 05:00:53
Remove
Avi (use Gerrit)
2013/09/18 16:41:44
Done.
| |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
| 19 | 19 |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 namespace policy { | 22 namespace policy { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Directory where the AppPack extensions are cached. | 26 // Directory where the AppPack extensions are cached. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(AppPackExternalLoader); | 61 DISALLOW_COPY_AND_ASSIGN(AppPackExternalLoader); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, | 64 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, |
| 65 EnterpriseInstallAttributes* install_attributes) | 65 EnterpriseInstallAttributes* install_attributes) |
| 66 : weak_ptr_factory_(this), | 66 : weak_ptr_factory_(this), |
| 67 created_extension_loader_(false), | 67 created_extension_loader_(false), |
| 68 install_attributes_(install_attributes), | 68 install_attributes_(install_attributes), |
| 69 external_cache_(kAppPackCacheDir, request_context, this, false) { | 69 external_cache_(kAppPackCacheDir, request_context, this, false) { |
| 70 chromeos::CrosSettings::Get()->AddSettingsObserver(chromeos::kAppPack, this); | 70 app_pack_subscription_ = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 71 chromeos::kAppPack, | |
| 72 base::Bind(&AppPackUpdater::SettingChanged, base::Unretained(this))); | |
| 71 | 73 |
| 72 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) { | 74 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) { |
| 73 // Already in Kiosk mode, start loading. | 75 // Already in Kiosk mode, start loading. |
| 74 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 76 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 75 base::Bind(&AppPackUpdater::LoadPolicy, | 77 base::Bind(&AppPackUpdater::LoadPolicy, |
| 76 weak_ptr_factory_.GetWeakPtr())); | 78 weak_ptr_factory_.GetWeakPtr())); |
| 77 } else { | 79 } else { |
| 78 // Linger until the device switches to DEVICE_MODE_RETAIL_KIOSK and the | 80 // Linger until the device switches to DEVICE_MODE_RETAIL_KIOSK and the |
| 79 // app pack device setting appears. | 81 // app pack device setting appears. |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 | 84 |
| 83 AppPackUpdater::~AppPackUpdater() { | 85 AppPackUpdater::~AppPackUpdater() { |
| 84 chromeos::CrosSettings::Get()->RemoveSettingsObserver( | |
| 85 chromeos::kAppPack, this); | |
| 86 } | 86 } |
| 87 | 87 |
| 88 extensions::ExternalLoader* AppPackUpdater::CreateExternalLoader() { | 88 extensions::ExternalLoader* AppPackUpdater::CreateExternalLoader() { |
| 89 if (created_extension_loader_) { | 89 if (created_extension_loader_) { |
| 90 NOTREACHED(); | 90 NOTREACHED(); |
| 91 return NULL; | 91 return NULL; |
| 92 } | 92 } |
| 93 created_extension_loader_ = true; | 93 created_extension_loader_ = true; |
| 94 AppPackExternalLoader* loader = new AppPackExternalLoader(); | 94 AppPackExternalLoader* loader = new AppPackExternalLoader(); |
| 95 extension_loader_ = loader->AsWeakPtr(); | 95 extension_loader_ = loader->AsWeakPtr(); |
| 96 | 96 |
| 97 // The cache may have been already checked. In that case, load the current | 97 // The cache may have been already checked. In that case, load the current |
| 98 // extensions into the loader immediately. | 98 // extensions into the loader immediately. |
| 99 UpdateExtensionLoader(); | 99 UpdateExtensionLoader(); |
| 100 | 100 |
| 101 return loader; | 101 return loader; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void AppPackUpdater::SetScreenSaverUpdateCallback( | 104 void AppPackUpdater::SetScreenSaverUpdateCallback( |
| 105 const AppPackUpdater::ScreenSaverUpdateCallback& callback) { | 105 const AppPackUpdater::ScreenSaverUpdateCallback& callback) { |
| 106 screen_saver_update_callback_ = callback; | 106 screen_saver_update_callback_ = callback; |
| 107 if (!screen_saver_update_callback_.is_null() && !screen_saver_path_.empty()) { | 107 if (!screen_saver_update_callback_.is_null() && !screen_saver_path_.empty()) { |
| 108 BrowserThread::PostTask( | 108 BrowserThread::PostTask( |
| 109 BrowserThread::UI, FROM_HERE, | 109 BrowserThread::UI, FROM_HERE, |
| 110 base::Bind(screen_saver_update_callback_, screen_saver_path_)); | 110 base::Bind(screen_saver_update_callback_, screen_saver_path_)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void AppPackUpdater::Observe(int type, | 114 void AppPackUpdater::SettingChanged() { |
| 115 const content::NotificationSource& source, | 115 if (install_attributes_->GetMode() == DEVICE_MODE_RETAIL_KIOSK) |
| 116 const content::NotificationDetails& details) { | 116 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 } | 117 } |
| 129 | 118 |
| 130 void AppPackUpdater::LoadPolicy() { | 119 void AppPackUpdater::LoadPolicy() { |
| 131 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 120 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
| 132 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues( | 121 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues( |
| 133 base::Bind(&AppPackUpdater::LoadPolicy, | 122 base::Bind(&AppPackUpdater::LoadPolicy, |
| 134 weak_ptr_factory_.GetWeakPtr()))) { | 123 weak_ptr_factory_.GetWeakPtr()))) { |
| 135 return; | 124 return; |
| 136 } | 125 } |
| 137 | 126 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { | 201 void AppPackUpdater::SetScreenSaverPath(const base::FilePath& path) { |
| 213 // Don't invoke the callback if the path isn't changing. | 202 // Don't invoke the callback if the path isn't changing. |
| 214 if (path != screen_saver_path_) { | 203 if (path != screen_saver_path_) { |
| 215 screen_saver_path_ = path; | 204 screen_saver_path_ = path; |
| 216 if (!screen_saver_update_callback_.is_null()) | 205 if (!screen_saver_update_callback_.is_null()) |
| 217 screen_saver_update_callback_.Run(screen_saver_path_); | 206 screen_saver_update_callback_.Run(screen_saver_path_); |
| 218 } | 207 } |
| 219 } | 208 } |
| 220 | 209 |
| 221 } // namespace policy | 210 } // namespace policy |
| OLD | NEW |