Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| index 9fab7ceeac9d6791832617b7529863b71ed90f4f..5e65d0fe0f3ed6f4d656e25c19660db7afc01b3b 100644 |
| --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| @@ -8,6 +8,7 @@ |
| #include <set> |
| #include "base/bind.h" |
| +#include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/path_service.h" |
| #include "base/prefs/pref_registry_simple.h" |
| @@ -23,7 +24,10 @@ |
| #include "chrome/browser/chromeos/policy/device_local_account.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| +#include "chrome/browser/extensions/external_provider_impl.h" |
| #include "chrome/common/chrome_paths.h" |
| +#include "chrome/common/extensions/extension_constants.h" |
| +#include "chromeos/chromeos_paths.h" |
| #include "chromeos/cryptohome/async_method_caller.h" |
| #include "chromeos/settings/cros_settings_names.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -54,6 +58,13 @@ void CheckOwnerFilePresence(bool *present) { |
| *present = util->IsPublicKeyPresent(); |
| } |
| +scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { |
| + base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| + CHECK(pool); |
| + return pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| + pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| +} |
| + |
| } // namespace |
| // static |
| @@ -86,7 +97,7 @@ KioskAppManager::App::App(const KioskAppData& data) |
| user_id(data.user_id()), |
| name(data.name()), |
| icon(data.icon()), |
| - is_loading(data.IsLoading()) { |
| + is_loading(data.IsLoading() || data.IsCrxCacheLoading()) { |
|
xiyuan
2014/05/02 03:22:12
Pass IsExtensionPending from manager and combine i
jennyz
2014/05/02 17:46:55
Done.
|
| } |
| KioskAppManager::App::App() : is_loading(false) {} |
| @@ -352,6 +363,15 @@ void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| } |
| KioskAppManager::KioskAppManager() : ownership_established_(false) { |
| + PathService::Get(chromeos::DIR_KIOSK_EXTENSIONS_CACHE, &cache_dir_); |
|
xiyuan
2014/05/02 03:22:12
nit: CHECK(...)
jennyz
2014/05/02 17:46:55
Done.
|
| + external_cache_.reset( |
| + new ExternalCache(cache_dir_, |
| + g_browser_process->system_request_context(), |
| + GetBackgroundTaskRunner(), |
| + this, |
| + true /* always_check_updates */, |
| + false /* wait_for_cache_initialization */)); |
| + |
| UpdateAppData(); |
| local_accounts_subscription_ = |
| CrosSettings::Get()->AddSettingsObserver( |
| @@ -420,20 +440,37 @@ void KioskAppManager::UpdateAppData() { |
| } else { |
| KioskAppData* new_app = |
| new KioskAppData(this, it->kiosk_app_id, it->user_id); |
| + // SetCrxCacheStatus to loading only for newly added apps, so the UI will |
| + // only updates the loading status of these apps. |
| + new_app->SetCrxCacheStatus(KioskAppData::STATUS_LOADING); |
|
xiyuan
2014/05/02 03:22:12
ExternalCache::IsExtensionPending is a good signal
jennyz
2014/05/02 17:46:55
Done.
|
| apps_.push_back(new_app); // Takes ownership of |new_app|. |
| new_app->Load(); |
| } |
| } |
| // Clears cache and deletes the remaining old data. |
| + std::vector<std::string> apps_to_remove; |
| for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); |
| it != old_apps.end(); ++it) { |
| it->second->ClearCache(); |
| cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| it->second->user_id(), |
| base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
| + apps_to_remove.push_back(it->second->app_id()); |
| } |
| STLDeleteValues(&old_apps); |
| + external_cache_->RemoveExtensions(apps_to_remove); |
| + |
| + // Request external_cache_ to download new apps and update the existing |
| + // apps. |
| + scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| + for (size_t i = 0; i < apps_.size(); ++i) { |
| + base::DictionaryValue* entry = new base::DictionaryValue; |
| + entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| + extension_urls::GetWebstoreUpdateUrl().spec()); |
|
xiyuan
2014/05/02 03:22:12
Not needed since it is the default download URL.
jennyz
2014/05/02 17:46:55
Done.
|
| + prefs->Set(apps_[i]->app_id(), entry); |
| + } |
| + external_cache_->UpdateExtensionsList(prefs.Pass()); |
| FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
| OnKioskAppsSettingsChanged()); |
| @@ -457,6 +494,26 @@ void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { |
| OnKioskAppDataLoadFailure(app_id)); |
| } |
| +void KioskAppManager::OnExtensionListsUpdated( |
| + const base::DictionaryValue* prefs) { |
| +} |
| + |
| +void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) { |
| + KioskAppData* app_data = GetAppDataMutable(id); |
| + if (!app_data) |
| + return; |
| + app_data->SetCrxCacheStatus(KioskAppData::STATUS_LOADED); |
|
xiyuan
2014/05/02 03:22:12
Probably can just call OnKioskAppDataChanged(id) h
jennyz
2014/05/02 17:46:55
Done.
|
| +} |
| + |
| +void KioskAppManager::OnExtensionDownloadFailed( |
| + const std::string& id, |
| + extensions::ExtensionDownloaderDelegate::Error error) { |
| + KioskAppData* app_data = GetAppDataMutable(id); |
| + if (!app_data) |
| + return; |
| + app_data->SetCrxCacheStatus(KioskAppData::STATUS_ERROR); |
|
xiyuan
2014/05/02 03:22:12
Similarly, call OnKioskAppDataLoadFailure().
jennyz
2014/05/02 17:46:55
Done.
|
| +} |
| + |
| KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { |
| PrefService* prefs = g_browser_process->local_state(); |
| const base::DictionaryValue* dict = |