OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
17 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
20 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
21 #include "chrome/browser/chromeos/login/user_manager.h" | 22 #include "chrome/browser/chromeos/login/user_manager.h" |
22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
23 #include "chrome/browser/chromeos/policy/device_local_account.h" | 24 #include "chrome/browser/chromeos/policy/device_local_account.h" |
24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/cros_settings.h" |
25 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 26 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
27 #include "chrome/browser/extensions/external_provider_impl.h" | |
26 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/extensions/extension_constants.h" | |
30 #include "chromeos/chromeos_paths.h" | |
27 #include "chromeos/cryptohome/async_method_caller.h" | 31 #include "chromeos/cryptohome/async_method_caller.h" |
28 #include "chromeos/settings/cros_settings_names.h" | 32 #include "chromeos/settings/cros_settings_names.h" |
29 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
30 | 34 |
31 namespace chromeos { | 35 namespace chromeos { |
32 | 36 |
33 namespace { | 37 namespace { |
34 | 38 |
35 // Domain that is used for kiosk-app account IDs. | 39 // Domain that is used for kiosk-app account IDs. |
36 const char kKioskAppAccountDomain[] = "kiosk-apps"; | 40 const char kKioskAppAccountDomain[] = "kiosk-apps"; |
(...skipping 10 matching lines...) Expand all Loading... | |
47 << " failed, return code: " << return_code; | 51 << " failed, return code: " << return_code; |
48 } | 52 } |
49 } | 53 } |
50 | 54 |
51 // Check for presence of machine owner public key file. | 55 // Check for presence of machine owner public key file. |
52 void CheckOwnerFilePresence(bool *present) { | 56 void CheckOwnerFilePresence(bool *present) { |
53 scoped_refptr<OwnerKeyUtil> util = OwnerKeyUtil::Create(); | 57 scoped_refptr<OwnerKeyUtil> util = OwnerKeyUtil::Create(); |
54 *present = util->IsPublicKeyPresent(); | 58 *present = util->IsPublicKeyPresent(); |
55 } | 59 } |
56 | 60 |
61 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { | |
62 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | |
63 CHECK(pool); | |
64 return pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
65 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
66 } | |
67 | |
57 } // namespace | 68 } // namespace |
58 | 69 |
59 // static | 70 // static |
60 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; | 71 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; |
61 const char KioskAppManager::kKeyApps[] = "apps"; | 72 const char KioskAppManager::kKeyApps[] = "apps"; |
62 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; | 73 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; |
63 const char KioskAppManager::kIconCacheDir[] = "kiosk"; | 74 const char KioskAppManager::kIconCacheDir[] = "kiosk"; |
64 | 75 |
65 // static | 76 // static |
66 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER; | 77 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER; |
(...skipping 12 matching lines...) Expand all Loading... | |
79 // static | 90 // static |
80 void KioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) { | 91 void KioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) { |
81 registry->RegisterDictionaryPref(kKioskDictionaryName); | 92 registry->RegisterDictionaryPref(kKioskDictionaryName); |
82 } | 93 } |
83 | 94 |
84 KioskAppManager::App::App(const KioskAppData& data) | 95 KioskAppManager::App::App(const KioskAppData& data) |
85 : app_id(data.app_id()), | 96 : app_id(data.app_id()), |
86 user_id(data.user_id()), | 97 user_id(data.user_id()), |
87 name(data.name()), | 98 name(data.name()), |
88 icon(data.icon()), | 99 icon(data.icon()), |
89 is_loading(data.IsLoading()) { | 100 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.
| |
90 } | 101 } |
91 | 102 |
92 KioskAppManager::App::App() : is_loading(false) {} | 103 KioskAppManager::App::App() : is_loading(false) {} |
93 KioskAppManager::App::~App() {} | 104 KioskAppManager::App::~App() {} |
94 | 105 |
95 std::string KioskAppManager::GetAutoLaunchApp() const { | 106 std::string KioskAppManager::GetAutoLaunchApp() const { |
96 return auto_launch_app_id_; | 107 return auto_launch_app_id_; |
97 } | 108 } |
98 | 109 |
99 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { | 110 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 | 356 |
346 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 357 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
347 observers_.AddObserver(observer); | 358 observers_.AddObserver(observer); |
348 } | 359 } |
349 | 360 |
350 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 361 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
351 observers_.RemoveObserver(observer); | 362 observers_.RemoveObserver(observer); |
352 } | 363 } |
353 | 364 |
354 KioskAppManager::KioskAppManager() : ownership_established_(false) { | 365 KioskAppManager::KioskAppManager() : ownership_established_(false) { |
366 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.
| |
367 external_cache_.reset( | |
368 new ExternalCache(cache_dir_, | |
369 g_browser_process->system_request_context(), | |
370 GetBackgroundTaskRunner(), | |
371 this, | |
372 true /* always_check_updates */, | |
373 false /* wait_for_cache_initialization */)); | |
374 | |
355 UpdateAppData(); | 375 UpdateAppData(); |
356 local_accounts_subscription_ = | 376 local_accounts_subscription_ = |
357 CrosSettings::Get()->AddSettingsObserver( | 377 CrosSettings::Get()->AddSettingsObserver( |
358 kAccountsPrefDeviceLocalAccounts, | 378 kAccountsPrefDeviceLocalAccounts, |
359 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 379 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
360 local_account_auto_login_id_subscription_ = | 380 local_account_auto_login_id_subscription_ = |
361 CrosSettings::Get()->AddSettingsObserver( | 381 CrosSettings::Get()->AddSettingsObserver( |
362 kAccountsPrefDeviceLocalAccountAutoLoginId, | 382 kAccountsPrefDeviceLocalAccountAutoLoginId, |
363 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 383 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
364 } | 384 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 // TODO(mnissler): Support non-CWS update URLs. | 433 // TODO(mnissler): Support non-CWS update URLs. |
414 | 434 |
415 std::map<std::string, KioskAppData*>::iterator old_it = | 435 std::map<std::string, KioskAppData*>::iterator old_it = |
416 old_apps.find(it->kiosk_app_id); | 436 old_apps.find(it->kiosk_app_id); |
417 if (old_it != old_apps.end()) { | 437 if (old_it != old_apps.end()) { |
418 apps_.push_back(old_it->second); | 438 apps_.push_back(old_it->second); |
419 old_apps.erase(old_it); | 439 old_apps.erase(old_it); |
420 } else { | 440 } else { |
421 KioskAppData* new_app = | 441 KioskAppData* new_app = |
422 new KioskAppData(this, it->kiosk_app_id, it->user_id); | 442 new KioskAppData(this, it->kiosk_app_id, it->user_id); |
443 // SetCrxCacheStatus to loading only for newly added apps, so the UI will | |
444 // only updates the loading status of these apps. | |
445 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.
| |
423 apps_.push_back(new_app); // Takes ownership of |new_app|. | 446 apps_.push_back(new_app); // Takes ownership of |new_app|. |
424 new_app->Load(); | 447 new_app->Load(); |
425 } | 448 } |
426 } | 449 } |
427 | 450 |
428 // Clears cache and deletes the remaining old data. | 451 // Clears cache and deletes the remaining old data. |
452 std::vector<std::string> apps_to_remove; | |
429 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); | 453 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); |
430 it != old_apps.end(); ++it) { | 454 it != old_apps.end(); ++it) { |
431 it->second->ClearCache(); | 455 it->second->ClearCache(); |
432 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 456 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
433 it->second->user_id(), | 457 it->second->user_id(), |
434 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); | 458 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
459 apps_to_remove.push_back(it->second->app_id()); | |
435 } | 460 } |
436 STLDeleteValues(&old_apps); | 461 STLDeleteValues(&old_apps); |
462 external_cache_->RemoveExtensions(apps_to_remove); | |
463 | |
464 // Request external_cache_ to download new apps and update the existing | |
465 // apps. | |
466 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | |
467 for (size_t i = 0; i < apps_.size(); ++i) { | |
468 base::DictionaryValue* entry = new base::DictionaryValue; | |
469 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, | |
470 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.
| |
471 prefs->Set(apps_[i]->app_id(), entry); | |
472 } | |
473 external_cache_->UpdateExtensionsList(prefs.Pass()); | |
437 | 474 |
438 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, | 475 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
439 OnKioskAppsSettingsChanged()); | 476 OnKioskAppsSettingsChanged()); |
440 } | 477 } |
441 | 478 |
442 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { | 479 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { |
443 base::FilePath user_data_dir; | 480 base::FilePath user_data_dir; |
444 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 481 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
445 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); | 482 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); |
446 } | 483 } |
447 | 484 |
448 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { | 485 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { |
449 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 486 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
450 observers_, | 487 observers_, |
451 OnKioskAppDataChanged(app_id)); | 488 OnKioskAppDataChanged(app_id)); |
452 } | 489 } |
453 | 490 |
454 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { | 491 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { |
455 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 492 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
456 observers_, | 493 observers_, |
457 OnKioskAppDataLoadFailure(app_id)); | 494 OnKioskAppDataLoadFailure(app_id)); |
458 } | 495 } |
459 | 496 |
497 void KioskAppManager::OnExtensionListsUpdated( | |
498 const base::DictionaryValue* prefs) { | |
499 } | |
500 | |
501 void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) { | |
502 KioskAppData* app_data = GetAppDataMutable(id); | |
503 if (!app_data) | |
504 return; | |
505 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.
| |
506 } | |
507 | |
508 void KioskAppManager::OnExtensionDownloadFailed( | |
509 const std::string& id, | |
510 extensions::ExtensionDownloaderDelegate::Error error) { | |
511 KioskAppData* app_data = GetAppDataMutable(id); | |
512 if (!app_data) | |
513 return; | |
514 app_data->SetCrxCacheStatus(KioskAppData::STATUS_ERROR); | |
xiyuan
2014/05/02 03:22:12
Similarly, call OnKioskAppDataLoadFailure().
jennyz
2014/05/02 17:46:55
Done.
| |
515 } | |
516 | |
460 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { | 517 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { |
461 PrefService* prefs = g_browser_process->local_state(); | 518 PrefService* prefs = g_browser_process->local_state(); |
462 const base::DictionaryValue* dict = | 519 const base::DictionaryValue* dict = |
463 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); | 520 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); |
464 int value; | 521 int value; |
465 if (!dict->GetInteger(kKeyAutoLoginState, &value)) | 522 if (!dict->GetInteger(kKeyAutoLoginState, &value)) |
466 return AUTOLOGIN_NONE; | 523 return AUTOLOGIN_NONE; |
467 | 524 |
468 return static_cast<AutoLoginState>(value); | 525 return static_cast<AutoLoginState>(value); |
469 } | 526 } |
470 | 527 |
471 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { | 528 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { |
472 PrefService* prefs = g_browser_process->local_state(); | 529 PrefService* prefs = g_browser_process->local_state(); |
473 DictionaryPrefUpdate dict_update(prefs, | 530 DictionaryPrefUpdate dict_update(prefs, |
474 KioskAppManager::kKioskDictionaryName); | 531 KioskAppManager::kKioskDictionaryName); |
475 dict_update->SetInteger(kKeyAutoLoginState, state); | 532 dict_update->SetInteger(kKeyAutoLoginState, state); |
476 prefs->CommitPendingWrite(); | 533 prefs->CommitPendingWrite(); |
477 } | 534 } |
478 | 535 |
479 } // namespace chromeos | 536 } // namespace chromeos |
OLD | NEW |