| 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/files/file_path.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 22 #include "chrome/browser/chromeos/login/users/user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/device_local_account.h" | 25 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 26 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 26 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 27 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| 28 #include "chrome/browser/extensions/external_loader.h" |
| 27 #include "chrome/browser/extensions/external_provider_impl.h" | 29 #include "chrome/browser/extensions/external_provider_impl.h" |
| 28 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 29 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
| 30 #include "chromeos/chromeos_paths.h" | 32 #include "chromeos/chromeos_paths.h" |
| 31 #include "chromeos/cryptohome/async_method_caller.h" | 33 #include "chromeos/cryptohome/async_method_caller.h" |
| 32 #include "chromeos/settings/cros_settings_names.h" | 34 #include "chromeos/settings/cros_settings_names.h" |
| 33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 34 | 36 |
| 35 namespace chromeos { | 37 namespace chromeos { |
| 36 | 38 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 app_data->LoadFromInstalledApp(profile, app); | 358 app_data->LoadFromInstalledApp(profile, app); |
| 357 } | 359 } |
| 358 | 360 |
| 359 void KioskAppManager::RetryFailedAppDataFetch() { | 361 void KioskAppManager::RetryFailedAppDataFetch() { |
| 360 for (size_t i = 0; i < apps_.size(); ++i) { | 362 for (size_t i = 0; i < apps_.size(); ++i) { |
| 361 if (apps_[i]->status() == KioskAppData::STATUS_ERROR) | 363 if (apps_[i]->status() == KioskAppData::STATUS_ERROR) |
| 362 apps_[i]->Load(); | 364 apps_[i]->Load(); |
| 363 } | 365 } |
| 364 } | 366 } |
| 365 | 367 |
| 368 bool KioskAppManager::HasCachedCrx(const std::string& app_id) const { |
| 369 base::FilePath crx_path; |
| 370 std::string version; |
| 371 return GetCachedCrx(app_id, &crx_path, &version); |
| 372 } |
| 373 |
| 366 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 374 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
| 367 observers_.AddObserver(observer); | 375 observers_.AddObserver(observer); |
| 368 } | 376 } |
| 369 | 377 |
| 370 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 378 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| 371 observers_.RemoveObserver(observer); | 379 observers_.RemoveObserver(observer); |
| 372 } | 380 } |
| 373 | 381 |
| 374 KioskAppManager::KioskAppManager() : ownership_established_(false) { | 382 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { |
| 383 if (external_loader_created_) { |
| 384 NOTREACHED(); |
| 385 return NULL; |
| 386 } |
| 387 external_loader_created_ = true; |
| 388 KioskAppExternalLoader* loader = new KioskAppExternalLoader(); |
| 389 external_loader_ = loader->AsWeakPtr(); |
| 390 |
| 391 return loader; |
| 392 } |
| 393 |
| 394 void KioskAppManager::InstallFromCache(const std::string& id) { |
| 395 const base::DictionaryValue* extension = NULL; |
| 396 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { |
| 397 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 398 base::DictionaryValue* extension_copy = extension->DeepCopy(); |
| 399 prefs->Set(id, extension_copy); |
| 400 external_loader_->SetCurrentAppExtensions(prefs.Pass()); |
| 401 } else { |
| 402 LOG(ERROR) << "Can't find app in the cached externsions" |
| 403 << " id = " << id; |
| 404 } |
| 405 } |
| 406 |
| 407 void KioskAppManager::UpdateExternalCache() { |
| 408 UpdateAppData(); |
| 409 } |
| 410 |
| 411 KioskAppManager::KioskAppManager() |
| 412 : ownership_established_(false), external_loader_created_(false) { |
| 375 base::FilePath cache_dir; | 413 base::FilePath cache_dir; |
| 376 GetCrxCacheDir(&cache_dir); | 414 GetCrxCacheDir(&cache_dir); |
| 377 external_cache_.reset( | 415 external_cache_.reset( |
| 378 new ExternalCache(cache_dir, | 416 new ExternalCache(cache_dir, |
| 379 g_browser_process->system_request_context(), | 417 g_browser_process->system_request_context(), |
| 380 GetBackgroundTaskRunner(), | 418 GetBackgroundTaskRunner(), |
| 381 this, | 419 this, |
| 382 true /* always_check_updates */, | 420 true /* always_check_updates */, |
| 383 false /* wait_for_cache_initialization */)); | 421 false /* wait_for_cache_initialization */)); |
| 384 | |
| 385 UpdateAppData(); | 422 UpdateAppData(); |
| 386 local_accounts_subscription_ = | 423 local_accounts_subscription_ = |
| 387 CrosSettings::Get()->AddSettingsObserver( | 424 CrosSettings::Get()->AddSettingsObserver( |
| 388 kAccountsPrefDeviceLocalAccounts, | 425 kAccountsPrefDeviceLocalAccounts, |
| 389 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 426 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 390 local_account_auto_login_id_subscription_ = | 427 local_account_auto_login_id_subscription_ = |
| 391 CrosSettings::Get()->AddSettingsObserver( | 428 CrosSettings::Get()->AddSettingsObserver( |
| 392 kAccountsPrefDeviceLocalAccountAutoLoginId, | 429 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 393 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 430 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 394 } | 431 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 538 } |
| 502 | 539 |
| 503 void KioskAppManager::OnExtensionListsUpdated( | 540 void KioskAppManager::OnExtensionListsUpdated( |
| 504 const base::DictionaryValue* prefs) { | 541 const base::DictionaryValue* prefs) { |
| 505 } | 542 } |
| 506 | 543 |
| 507 void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) { | 544 void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) { |
| 508 KioskAppData* app_data = GetAppDataMutable(id); | 545 KioskAppData* app_data = GetAppDataMutable(id); |
| 509 if (!app_data) | 546 if (!app_data) |
| 510 return; | 547 return; |
| 511 OnKioskAppDataChanged(id); | 548 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
| 549 observers_, |
| 550 OnKioskExtensionLoadedInCache(id)); |
| 551 |
| 512 } | 552 } |
| 513 | 553 |
| 514 void KioskAppManager::OnExtensionDownloadFailed( | 554 void KioskAppManager::OnExtensionDownloadFailed( |
| 515 const std::string& id, | 555 const std::string& id, |
| 516 extensions::ExtensionDownloaderDelegate::Error error) { | 556 extensions::ExtensionDownloaderDelegate::Error error) { |
| 517 KioskAppData* app_data = GetAppDataMutable(id); | 557 KioskAppData* app_data = GetAppDataMutable(id); |
| 518 if (!app_data) | 558 if (!app_data) |
| 519 return; | 559 return; |
| 520 OnKioskAppDataLoadFailure(id); | 560 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
| 561 observers_, |
| 562 OnKioskExtensionDownloadFailed(id)); |
| 521 } | 563 } |
| 522 | 564 |
| 523 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { | 565 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { |
| 524 PrefService* prefs = g_browser_process->local_state(); | 566 PrefService* prefs = g_browser_process->local_state(); |
| 525 const base::DictionaryValue* dict = | 567 const base::DictionaryValue* dict = |
| 526 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); | 568 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 527 int value; | 569 int value; |
| 528 if (!dict->GetInteger(kKeyAutoLoginState, &value)) | 570 if (!dict->GetInteger(kKeyAutoLoginState, &value)) |
| 529 return AUTOLOGIN_NONE; | 571 return AUTOLOGIN_NONE; |
| 530 | 572 |
| 531 return static_cast<AutoLoginState>(value); | 573 return static_cast<AutoLoginState>(value); |
| 532 } | 574 } |
| 533 | 575 |
| 534 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { | 576 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { |
| 535 PrefService* prefs = g_browser_process->local_state(); | 577 PrefService* prefs = g_browser_process->local_state(); |
| 536 DictionaryPrefUpdate dict_update(prefs, | 578 DictionaryPrefUpdate dict_update(prefs, |
| 537 KioskAppManager::kKioskDictionaryName); | 579 KioskAppManager::kKioskDictionaryName); |
| 538 dict_update->SetInteger(kKeyAutoLoginState, state); | 580 dict_update->SetInteger(kKeyAutoLoginState, state); |
| 539 prefs->CommitPendingWrite(); | 581 prefs->CommitPendingWrite(); |
| 540 } | 582 } |
| 541 | 583 |
| 542 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { | 584 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { |
| 543 base::FilePath user_data_dir; | 585 base::FilePath user_data_dir; |
| 544 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 586 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 545 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 587 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
| 546 } | 588 } |
| 547 | 589 |
| 548 bool KioskAppManager::GetCachedCrx(const std::string& app_id, | 590 bool KioskAppManager::GetCachedCrx(const std::string& app_id, |
| 549 base::FilePath* file_path, | 591 base::FilePath* file_path, |
| 550 std::string* version) { | 592 std::string* version) const { |
| 551 return external_cache_->GetExtension(app_id, file_path, version); | 593 return external_cache_->GetExtension(app_id, file_path, version); |
| 552 } | 594 } |
| 553 | 595 |
| 554 } // namespace chromeos | 596 } // namespace chromeos |
| OLD | NEW |