| 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/files/file_util.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 16 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
| 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 24 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" |
| 23 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" | 25 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
| 24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 25 #include "chrome/browser/chromeos/policy/device_local_account.h" | 27 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 26 #include "chrome/browser/chromeos/settings/cros_settings.h" | 28 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 27 #include "chrome/browser/extensions/external_loader.h" | 29 #include "chrome/browser/extensions/external_loader.h" |
| 28 #include "chrome/browser/extensions/external_provider_impl.h" | 30 #include "chrome/browser/extensions/external_provider_impl.h" |
| 29 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 31 #include "chromeos/chromeos_paths.h" | 33 #include "chromeos/chromeos_paths.h" |
| 32 #include "chromeos/cryptohome/async_method_caller.h" | 34 #include "chromeos/cryptohome/async_method_caller.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 71 } |
| 70 | 72 |
| 71 } // namespace | 73 } // namespace |
| 72 | 74 |
| 73 // static | 75 // static |
| 74 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; | 76 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; |
| 75 const char KioskAppManager::kKeyApps[] = "apps"; | 77 const char KioskAppManager::kKeyApps[] = "apps"; |
| 76 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; | 78 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; |
| 77 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; | 79 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; |
| 78 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; | 80 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; |
| 81 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; |
| 79 | 82 |
| 80 // static | 83 // static |
| 81 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER; | 84 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER; |
| 82 KioskAppManager* KioskAppManager::Get() { | 85 KioskAppManager* KioskAppManager::Get() { |
| 83 return instance.Pointer(); | 86 return instance.Pointer(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 // static | 89 // static |
| 87 void KioskAppManager::Shutdown() { | 90 void KioskAppManager::Shutdown() { |
| 88 if (instance == NULL) | 91 if (instance == NULL) |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 apps_[i]->Load(); | 368 apps_[i]->Load(); |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 369 bool KioskAppManager::HasCachedCrx(const std::string& app_id) const { | 372 bool KioskAppManager::HasCachedCrx(const std::string& app_id) const { |
| 370 base::FilePath crx_path; | 373 base::FilePath crx_path; |
| 371 std::string version; | 374 std::string version; |
| 372 return GetCachedCrx(app_id, &crx_path, &version); | 375 return GetCachedCrx(app_id, &crx_path, &version); |
| 373 } | 376 } |
| 374 | 377 |
| 378 bool KioskAppManager::GetCachedCrx(const std::string& app_id, |
| 379 base::FilePath* file_path, |
| 380 std::string* version) const { |
| 381 return external_cache_->GetExtension(app_id, file_path, version); |
| 382 } |
| 383 |
| 375 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 384 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
| 376 observers_.AddObserver(observer); | 385 observers_.AddObserver(observer); |
| 377 } | 386 } |
| 378 | 387 |
| 379 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 388 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| 380 observers_.RemoveObserver(observer); | 389 observers_.RemoveObserver(observer); |
| 381 } | 390 } |
| 382 | 391 |
| 383 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { | 392 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { |
| 384 if (external_loader_created_) { | 393 if (external_loader_created_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 402 } else { | 411 } else { |
| 403 LOG(ERROR) << "Can't find app in the cached externsions" | 412 LOG(ERROR) << "Can't find app in the cached externsions" |
| 404 << " id = " << id; | 413 << " id = " << id; |
| 405 } | 414 } |
| 406 } | 415 } |
| 407 | 416 |
| 408 void KioskAppManager::UpdateExternalCache() { | 417 void KioskAppManager::UpdateExternalCache() { |
| 409 UpdateAppData(); | 418 UpdateAppData(); |
| 410 } | 419 } |
| 411 | 420 |
| 421 void KioskAppManager::OnKioskAppCacheUpdated(const std::string& app_id) { |
| 422 FOR_EACH_OBSERVER( |
| 423 KioskAppManagerObserver, observers_, OnKioskAppCacheUpdated(app_id)); |
| 424 } |
| 425 |
| 426 void KioskAppManager::PutValidatedExternalExtension( |
| 427 const std::string& app_id, |
| 428 const base::FilePath& crx_path, |
| 429 const std::string& version, |
| 430 const ExternalCache::PutExternalExtensionCallback& callback) { |
| 431 external_cache_->PutExternalExtension(app_id, crx_path, version, callback); |
| 432 } |
| 433 |
| 412 KioskAppManager::KioskAppManager() | 434 KioskAppManager::KioskAppManager() |
| 413 : ownership_established_(false), external_loader_created_(false) { | 435 : ownership_established_(false), external_loader_created_(false) { |
| 414 base::FilePath cache_dir; | 436 base::FilePath cache_dir; |
| 415 GetCrxCacheDir(&cache_dir); | 437 GetCrxCacheDir(&cache_dir); |
| 416 external_cache_.reset( | 438 external_cache_.reset( |
| 417 new ExternalCache(cache_dir, | 439 new ExternalCache(cache_dir, |
| 418 g_browser_process->system_request_context(), | 440 g_browser_process->system_request_context(), |
| 419 GetBackgroundTaskRunner(), | 441 GetBackgroundTaskRunner(), |
| 420 this, | 442 this, |
| 421 true /* always_check_updates */, | 443 true /* always_check_updates */, |
| 422 false /* wait_for_cache_initialization */)); | 444 false /* wait_for_cache_initialization */)); |
| 423 UpdateAppData(); | 445 UpdateAppData(); |
| 424 local_accounts_subscription_ = | 446 local_accounts_subscription_ = |
| 425 CrosSettings::Get()->AddSettingsObserver( | 447 CrosSettings::Get()->AddSettingsObserver( |
| 426 kAccountsPrefDeviceLocalAccounts, | 448 kAccountsPrefDeviceLocalAccounts, |
| 427 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 449 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 428 local_account_auto_login_id_subscription_ = | 450 local_account_auto_login_id_subscription_ = |
| 429 CrosSettings::Get()->AddSettingsObserver( | 451 CrosSettings::Get()->AddSettingsObserver( |
| 430 kAccountsPrefDeviceLocalAccountAutoLoginId, | 452 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 431 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); | 453 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 432 } | 454 } |
| 433 | 455 |
| 434 KioskAppManager::~KioskAppManager() {} | 456 KioskAppManager::~KioskAppManager() {} |
| 435 | 457 |
| 458 void KioskAppManager::MonitorKioskExternalUpdate() { |
| 459 base::FilePath cache_dir; |
| 460 GetCrxCacheDir(&cache_dir); |
| 461 base::FilePath unpack_dir; |
| 462 GetCrxUnpackDir(&unpack_dir); |
| 463 usb_stick_updater_.reset(new KioskExternalUpdater( |
| 464 GetBackgroundTaskRunner(), cache_dir, unpack_dir)); |
| 465 } |
| 466 |
| 436 void KioskAppManager::CleanUp() { | 467 void KioskAppManager::CleanUp() { |
| 437 local_accounts_subscription_.reset(); | 468 local_accounts_subscription_.reset(); |
| 438 local_account_auto_login_id_subscription_.reset(); | 469 local_account_auto_login_id_subscription_.reset(); |
| 439 apps_.clear(); | 470 apps_.clear(); |
| 471 usb_stick_updater_.reset(); |
| 440 external_cache_.reset(); | 472 external_cache_.reset(); |
| 441 } | 473 } |
| 442 | 474 |
| 443 const KioskAppData* KioskAppManager::GetAppData( | 475 const KioskAppData* KioskAppManager::GetAppData( |
| 444 const std::string& app_id) const { | 476 const std::string& app_id) const { |
| 445 for (size_t i = 0; i < apps_.size(); ++i) { | 477 for (size_t i = 0; i < apps_.size(); ++i) { |
| 446 const KioskAppData* data = apps_[i]; | 478 const KioskAppData* data = apps_[i]; |
| 447 if (data->app_id() == app_id) | 479 if (data->app_id() == app_id) |
| 448 return data; | 480 return data; |
| 449 } | 481 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 dict_update->SetInteger(kKeyAutoLoginState, state); | 613 dict_update->SetInteger(kKeyAutoLoginState, state); |
| 582 prefs->CommitPendingWrite(); | 614 prefs->CommitPendingWrite(); |
| 583 } | 615 } |
| 584 | 616 |
| 585 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { | 617 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { |
| 586 base::FilePath user_data_dir; | 618 base::FilePath user_data_dir; |
| 587 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 619 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 588 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 620 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
| 589 } | 621 } |
| 590 | 622 |
| 591 bool KioskAppManager::GetCachedCrx(const std::string& app_id, | 623 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { |
| 592 base::FilePath* file_path, | 624 base::FilePath temp_dir; |
| 593 std::string* version) const { | 625 base::GetTempDir(&temp_dir); |
| 594 return external_cache_->GetExtension(app_id, file_path, version); | 626 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); |
| 595 } | 627 } |
| 596 | 628 |
| 597 } // namespace chromeos | 629 } // namespace chromeos |
| OLD | NEW |