| 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; |
| 67 KioskAppManager* KioskAppManager::Get() { | 78 KioskAppManager* KioskAppManager::Get() { |
| 68 return instance.Pointer(); | 79 return instance.Pointer(); |
| 69 } | 80 } |
| 70 | 81 |
| 71 // static | 82 // static |
| 72 void KioskAppManager::Shutdown() { | 83 void KioskAppManager::Shutdown() { |
| 73 if (instance == NULL) | 84 if (instance == NULL) |
| 74 return; | 85 return; |
| 75 | 86 |
| 76 instance.Pointer()->CleanUp(); | 87 instance.Pointer()->CleanUp(); |
| 77 } | 88 } |
| 78 | 89 |
| 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, bool is_extension_pending) |
| 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() || is_extension_pending) { |
| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 296 |
| 286 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); | 297 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); |
| 287 } | 298 } |
| 288 | 299 |
| 289 void KioskAppManager::GetApps(Apps* apps) const { | 300 void KioskAppManager::GetApps(Apps* apps) const { |
| 290 apps->clear(); | 301 apps->clear(); |
| 291 apps->reserve(apps_.size()); | 302 apps->reserve(apps_.size()); |
| 292 for (size_t i = 0; i < apps_.size(); ++i) { | 303 for (size_t i = 0; i < apps_.size(); ++i) { |
| 293 const KioskAppData& app_data = *apps_[i]; | 304 const KioskAppData& app_data = *apps_[i]; |
| 294 if (app_data.status() != KioskAppData::STATUS_ERROR) | 305 if (app_data.status() != KioskAppData::STATUS_ERROR) |
| 295 apps->push_back(App(app_data)); | 306 apps->push_back(App( |
| 307 app_data, external_cache_->IsExtensionPending(app_data.app_id()))); |
| 296 } | 308 } |
| 297 } | 309 } |
| 298 | 310 |
| 299 bool KioskAppManager::GetApp(const std::string& app_id, App* app) const { | 311 bool KioskAppManager::GetApp(const std::string& app_id, App* app) const { |
| 300 const KioskAppData* data = GetAppData(app_id); | 312 const KioskAppData* data = GetAppData(app_id); |
| 301 if (!data) | 313 if (!data) |
| 302 return false; | 314 return false; |
| 303 | 315 |
| 304 *app = App(*data); | 316 *app = App(*data, external_cache_->IsExtensionPending(app_id)); |
| 305 return true; | 317 return true; |
| 306 } | 318 } |
| 307 | 319 |
| 308 const base::RefCountedString* KioskAppManager::GetAppRawIcon( | 320 const base::RefCountedString* KioskAppManager::GetAppRawIcon( |
| 309 const std::string& app_id) const { | 321 const std::string& app_id) const { |
| 310 const KioskAppData* data = GetAppData(app_id); | 322 const KioskAppData* data = GetAppData(app_id); |
| 311 if (!data) | 323 if (!data) |
| 312 return NULL; | 324 return NULL; |
| 313 | 325 |
| 314 return data->raw_icon(); | 326 return data->raw_icon(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 345 | 357 |
| 346 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 358 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
| 347 observers_.AddObserver(observer); | 359 observers_.AddObserver(observer); |
| 348 } | 360 } |
| 349 | 361 |
| 350 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 362 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| 351 observers_.RemoveObserver(observer); | 363 observers_.RemoveObserver(observer); |
| 352 } | 364 } |
| 353 | 365 |
| 354 KioskAppManager::KioskAppManager() : ownership_established_(false) { | 366 KioskAppManager::KioskAppManager() : ownership_established_(false) { |
| 367 CHECK(PathService::Get(chromeos::DIR_KIOSK_EXTENSIONS_CACHE, &cache_dir_)); |
| 368 external_cache_.reset( |
| 369 new ExternalCache(cache_dir_, |
| 370 g_browser_process->system_request_context(), |
| 371 GetBackgroundTaskRunner(), |
| 372 this, |
| 373 true /* always_check_updates */, |
| 374 false /* wait_for_cache_initialization */)); |
| 375 |
| 355 UpdateAppData(); | 376 UpdateAppData(); |
| 356 local_accounts_subscription_ = | 377 local_accounts_subscription_ = |
| 357 CrosSettings::Get()->AddSettingsObserver( | 378 CrosSettings::Get()->AddSettingsObserver( |
| 358 kAccountsPrefDeviceLocalAccounts, | 379 kAccountsPrefDeviceLocalAccounts, |
| 359 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 380 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 360 local_account_auto_login_id_subscription_ = | 381 local_account_auto_login_id_subscription_ = |
| 361 CrosSettings::Get()->AddSettingsObserver( | 382 CrosSettings::Get()->AddSettingsObserver( |
| 362 kAccountsPrefDeviceLocalAccountAutoLoginId, | 383 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 363 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 384 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 364 } | 385 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 old_apps.erase(old_it); | 440 old_apps.erase(old_it); |
| 420 } else { | 441 } else { |
| 421 KioskAppData* new_app = | 442 KioskAppData* new_app = |
| 422 new KioskAppData(this, it->kiosk_app_id, it->user_id); | 443 new KioskAppData(this, it->kiosk_app_id, it->user_id); |
| 423 apps_.push_back(new_app); // Takes ownership of |new_app|. | 444 apps_.push_back(new_app); // Takes ownership of |new_app|. |
| 424 new_app->Load(); | 445 new_app->Load(); |
| 425 } | 446 } |
| 426 } | 447 } |
| 427 | 448 |
| 428 // Clears cache and deletes the remaining old data. | 449 // Clears cache and deletes the remaining old data. |
| 450 std::vector<std::string> apps_to_remove; |
| 429 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); | 451 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); |
| 430 it != old_apps.end(); ++it) { | 452 it != old_apps.end(); ++it) { |
| 431 it->second->ClearCache(); | 453 it->second->ClearCache(); |
| 432 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 454 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 433 it->second->user_id(), | 455 it->second->user_id(), |
| 434 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); | 456 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
| 457 apps_to_remove.push_back(it->second->app_id()); |
| 435 } | 458 } |
| 436 STLDeleteValues(&old_apps); | 459 STLDeleteValues(&old_apps); |
| 460 external_cache_->RemoveExtensions(apps_to_remove); |
| 461 |
| 462 // Request external_cache_ to download new apps and update the existing |
| 463 // apps. |
| 464 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 465 for (size_t i = 0; i < apps_.size(); ++i) |
| 466 prefs->Set(apps_[i]->app_id(), new base::DictionaryValue); |
| 467 external_cache_->UpdateExtensionsList(prefs.Pass()); |
| 437 | 468 |
| 438 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, | 469 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
| 439 OnKioskAppsSettingsChanged()); | 470 OnKioskAppsSettingsChanged()); |
| 440 } | 471 } |
| 441 | 472 |
| 442 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { | 473 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { |
| 443 base::FilePath user_data_dir; | 474 base::FilePath user_data_dir; |
| 444 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 475 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 445 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); | 476 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); |
| 446 } | 477 } |
| 447 | 478 |
| 448 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { | 479 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { |
| 449 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 480 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
| 450 observers_, | 481 observers_, |
| 451 OnKioskAppDataChanged(app_id)); | 482 OnKioskAppDataChanged(app_id)); |
| 452 } | 483 } |
| 453 | 484 |
| 454 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { | 485 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { |
| 455 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 486 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
| 456 observers_, | 487 observers_, |
| 457 OnKioskAppDataLoadFailure(app_id)); | 488 OnKioskAppDataLoadFailure(app_id)); |
| 458 } | 489 } |
| 459 | 490 |
| 491 void KioskAppManager::OnExtensionListsUpdated( |
| 492 const base::DictionaryValue* prefs) { |
| 493 } |
| 494 |
| 495 void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) { |
| 496 KioskAppData* app_data = GetAppDataMutable(id); |
| 497 if (!app_data) |
| 498 return; |
| 499 OnKioskAppDataChanged(id); |
| 500 } |
| 501 |
| 502 void KioskAppManager::OnExtensionDownloadFailed( |
| 503 const std::string& id, |
| 504 extensions::ExtensionDownloaderDelegate::Error error) { |
| 505 KioskAppData* app_data = GetAppDataMutable(id); |
| 506 if (!app_data) |
| 507 return; |
| 508 OnKioskAppDataLoadFailure(id); |
| 509 } |
| 510 |
| 460 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { | 511 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { |
| 461 PrefService* prefs = g_browser_process->local_state(); | 512 PrefService* prefs = g_browser_process->local_state(); |
| 462 const base::DictionaryValue* dict = | 513 const base::DictionaryValue* dict = |
| 463 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); | 514 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 464 int value; | 515 int value; |
| 465 if (!dict->GetInteger(kKeyAutoLoginState, &value)) | 516 if (!dict->GetInteger(kKeyAutoLoginState, &value)) |
| 466 return AUTOLOGIN_NONE; | 517 return AUTOLOGIN_NONE; |
| 467 | 518 |
| 468 return static_cast<AutoLoginState>(value); | 519 return static_cast<AutoLoginState>(value); |
| 469 } | 520 } |
| 470 | 521 |
| 471 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { | 522 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { |
| 472 PrefService* prefs = g_browser_process->local_state(); | 523 PrefService* prefs = g_browser_process->local_state(); |
| 473 DictionaryPrefUpdate dict_update(prefs, | 524 DictionaryPrefUpdate dict_update(prefs, |
| 474 KioskAppManager::kKioskDictionaryName); | 525 KioskAppManager::kKioskDictionaryName); |
| 475 dict_update->SetInteger(kKeyAutoLoginState, state); | 526 dict_update->SetInteger(kKeyAutoLoginState, state); |
| 476 prefs->CommitPendingWrite(); | 527 prefs->CommitPendingWrite(); |
| 477 } | 528 } |
| 478 | 529 |
| 479 } // namespace chromeos | 530 } // namespace chromeos |
| OLD | NEW |