| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 17 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 18 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/app_mode/app_session.h" | 21 #include "chrome/browser/chromeos/app_mode/app_session.h" |
| 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" | 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
| 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 23 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" | 25 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" |
| 24 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 26 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 secondary_app_external_loader_created_ = true; | 510 secondary_app_external_loader_created_ = true; |
| 509 KioskAppExternalLoader* secondary_loader = new KioskAppExternalLoader(); | 511 KioskAppExternalLoader* secondary_loader = new KioskAppExternalLoader(); |
| 510 secondary_app_external_loader_ = secondary_loader->AsWeakPtr(); | 512 secondary_app_external_loader_ = secondary_loader->AsWeakPtr(); |
| 511 | 513 |
| 512 return secondary_loader; | 514 return secondary_loader; |
| 513 } | 515 } |
| 514 | 516 |
| 515 void KioskAppManager::InstallFromCache(const std::string& id) { | 517 void KioskAppManager::InstallFromCache(const std::string& id) { |
| 516 const base::DictionaryValue* extension = nullptr; | 518 const base::DictionaryValue* extension = nullptr; |
| 517 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { | 519 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { |
| 518 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 520 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 519 base::DictionaryValue* extension_copy = extension->DeepCopy(); | 521 base::DictionaryValue* extension_copy = extension->DeepCopy(); |
| 520 prefs->Set(id, extension_copy); | 522 prefs->Set(id, extension_copy); |
| 521 external_loader_->SetCurrentAppExtensions(std::move(prefs)); | 523 external_loader_->SetCurrentAppExtensions(std::move(prefs)); |
| 522 } else { | 524 } else { |
| 523 LOG(ERROR) << "Can't find app in the cached externsions" | 525 LOG(ERROR) << "Can't find app in the cached externsions" |
| 524 << " id = " << id; | 526 << " id = " << id; |
| 525 } | 527 } |
| 526 } | 528 } |
| 527 | 529 |
| 528 void KioskAppManager::InstallSecondaryApps( | 530 void KioskAppManager::InstallSecondaryApps( |
| 529 const std::vector<std::string>& ids) { | 531 const std::vector<std::string>& ids) { |
| 530 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 532 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 531 for (const std::string& id : ids) { | 533 for (const std::string& id : ids) { |
| 532 scoped_ptr<base::DictionaryValue> extension_entry( | 534 std::unique_ptr<base::DictionaryValue> extension_entry( |
| 533 new base::DictionaryValue); | 535 new base::DictionaryValue); |
| 534 extension_entry->SetStringWithoutPathExpansion( | 536 extension_entry->SetStringWithoutPathExpansion( |
| 535 extensions::ExternalProviderImpl::kExternalUpdateUrl, | 537 extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 536 extension_urls::GetWebstoreUpdateUrl().spec()); | 538 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 537 extension_entry->SetBoolean( | 539 extension_entry->SetBoolean( |
| 538 extensions::ExternalProviderImpl::kIsFromWebstore, true); | 540 extensions::ExternalProviderImpl::kIsFromWebstore, true); |
| 539 prefs->Set(id, std::move(extension_entry)); | 541 prefs->Set(id, std::move(extension_entry)); |
| 540 } | 542 } |
| 541 secondary_app_external_loader_->SetCurrentAppExtensions(std::move(prefs)); | 543 secondary_app_external_loader_->SetCurrentAppExtensions(std::move(prefs)); |
| 542 } | 544 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 619 |
| 618 return nullptr; | 620 return nullptr; |
| 619 } | 621 } |
| 620 | 622 |
| 621 KioskAppData* KioskAppManager::GetAppDataMutable(const std::string& app_id) { | 623 KioskAppData* KioskAppManager::GetAppDataMutable(const std::string& app_id) { |
| 622 return const_cast<KioskAppData*>(GetAppData(app_id)); | 624 return const_cast<KioskAppData*>(GetAppData(app_id)); |
| 623 } | 625 } |
| 624 | 626 |
| 625 void KioskAppManager::UpdateAppData() { | 627 void KioskAppManager::UpdateAppData() { |
| 626 // Gets app id to data mapping for existing apps. | 628 // Gets app id to data mapping for existing apps. |
| 627 std::map<std::string, scoped_ptr<KioskAppData>> old_apps; | 629 std::map<std::string, std::unique_ptr<KioskAppData>> old_apps; |
| 628 for (auto& app : apps_) | 630 for (auto& app : apps_) |
| 629 old_apps[app->app_id()] = std::move(app); | 631 old_apps[app->app_id()] = std::move(app); |
| 630 apps_.clear(); | 632 apps_.clear(); |
| 631 | 633 |
| 632 auto_launch_app_id_.clear(); | 634 auto_launch_app_id_.clear(); |
| 633 std::string auto_login_account_id; | 635 std::string auto_login_account_id; |
| 634 CrosSettings::Get()->GetString(kAccountsPrefDeviceLocalAccountAutoLoginId, | 636 CrosSettings::Get()->GetString(kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 635 &auto_login_account_id); | 637 &auto_login_account_id); |
| 636 | 638 |
| 637 // Re-populates |apps_| and reuses existing KioskAppData when possible. | 639 // Re-populates |apps_| and reuses existing KioskAppData when possible. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 651 const AccountId account_id(AccountId::FromUserEmail(it->user_id)); | 653 const AccountId account_id(AccountId::FromUserEmail(it->user_id)); |
| 652 auto old_it = old_apps.find(it->kiosk_app_id); | 654 auto old_it = old_apps.find(it->kiosk_app_id); |
| 653 if (old_it != old_apps.end()) { | 655 if (old_it != old_apps.end()) { |
| 654 apps_.push_back(std::move(old_it->second)); | 656 apps_.push_back(std::move(old_it->second)); |
| 655 old_apps.erase(old_it); | 657 old_apps.erase(old_it); |
| 656 } else { | 658 } else { |
| 657 base::FilePath cached_crx; | 659 base::FilePath cached_crx; |
| 658 std::string version; | 660 std::string version; |
| 659 GetCachedCrx(it->kiosk_app_id, &cached_crx, &version); | 661 GetCachedCrx(it->kiosk_app_id, &cached_crx, &version); |
| 660 | 662 |
| 661 apps_.push_back(make_scoped_ptr( | 663 apps_.push_back(base::WrapUnique( |
| 662 new KioskAppData(this, it->kiosk_app_id, account_id, | 664 new KioskAppData(this, it->kiosk_app_id, account_id, |
| 663 GURL(it->kiosk_app_update_url), cached_crx))); | 665 GURL(it->kiosk_app_update_url), cached_crx))); |
| 664 apps_.back()->Load(); | 666 apps_.back()->Load(); |
| 665 } | 667 } |
| 666 CancelDelayedCryptohomeRemoval(cryptohome::Identification(account_id)); | 668 CancelDelayedCryptohomeRemoval(cryptohome::Identification(account_id)); |
| 667 } | 669 } |
| 668 | 670 |
| 669 ClearRemovedApps(old_apps); | 671 ClearRemovedApps(old_apps); |
| 670 UpdateExternalCachePrefs(); | 672 UpdateExternalCachePrefs(); |
| 671 RetryFailedAppDataFetch(); | 673 RetryFailedAppDataFetch(); |
| 672 | 674 |
| 673 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, | 675 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
| 674 OnKioskAppsSettingsChanged()); | 676 OnKioskAppsSettingsChanged()); |
| 675 } | 677 } |
| 676 | 678 |
| 677 void KioskAppManager::ClearRemovedApps( | 679 void KioskAppManager::ClearRemovedApps( |
| 678 const std::map<std::string, scoped_ptr<KioskAppData>>& old_apps) { | 680 const std::map<std::string, std::unique_ptr<KioskAppData>>& old_apps) { |
| 679 base::Closure cryptohomes_barrier_closure; | 681 base::Closure cryptohomes_barrier_closure; |
| 680 | 682 |
| 681 const user_manager::User* active_user = | 683 const user_manager::User* active_user = |
| 682 user_manager::UserManager::Get()->GetActiveUser(); | 684 user_manager::UserManager::Get()->GetActiveUser(); |
| 683 if (active_user) { | 685 if (active_user) { |
| 684 const AccountId active_account_id = active_user->GetAccountId(); | 686 const AccountId active_account_id = active_user->GetAccountId(); |
| 685 for (const auto& it : old_apps) { | 687 for (const auto& it : old_apps) { |
| 686 if (it.second->account_id() == active_account_id) { | 688 if (it.second->account_id() == active_account_id) { |
| 687 VLOG(1) << "Currently running kiosk app removed from policy, exiting"; | 689 VLOG(1) << "Currently running kiosk app removed from policy, exiting"; |
| 688 cryptohomes_barrier_closure = BarrierClosure( | 690 cryptohomes_barrier_closure = BarrierClosure( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 700 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 702 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 701 cryptohome_id, base::Bind(&OnRemoveAppCryptohomeComplete, cryptohome_id, | 703 cryptohome_id, base::Bind(&OnRemoveAppCryptohomeComplete, cryptohome_id, |
| 702 entry.first, cryptohomes_barrier_closure)); | 704 entry.first, cryptohomes_barrier_closure)); |
| 703 apps_to_remove.push_back(entry.second->app_id()); | 705 apps_to_remove.push_back(entry.second->app_id()); |
| 704 } | 706 } |
| 705 external_cache_->RemoveExtensions(apps_to_remove); | 707 external_cache_->RemoveExtensions(apps_to_remove); |
| 706 } | 708 } |
| 707 | 709 |
| 708 void KioskAppManager::UpdateExternalCachePrefs() { | 710 void KioskAppManager::UpdateExternalCachePrefs() { |
| 709 // Request external_cache_ to download new apps and update the existing apps. | 711 // Request external_cache_ to download new apps and update the existing apps. |
| 710 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 712 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 711 for (size_t i = 0; i < apps_.size(); ++i) { | 713 for (size_t i = 0; i < apps_.size(); ++i) { |
| 712 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 714 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 713 | 715 |
| 714 if (apps_[i]->update_url().is_valid()) { | 716 if (apps_[i]->update_url().is_valid()) { |
| 715 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, | 717 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 716 apps_[i]->update_url().spec()); | 718 apps_[i]->update_url().spec()); |
| 717 } else { | 719 } else { |
| 718 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, | 720 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 719 extension_urls::GetWebstoreUpdateUrl().spec()); | 721 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 720 } | 722 } |
| 721 | 723 |
| 722 prefs->Set(apps_[i]->app_id(), entry.release()); | 724 prefs->Set(apps_[i]->app_id(), entry.release()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { | 809 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { |
| 808 int delay; | 810 int delay; |
| 809 if (!CrosSettings::Get()->GetInteger( | 811 if (!CrosSettings::Get()->GetInteger( |
| 810 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { | 812 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { |
| 811 return base::TimeDelta(); // Default delay is 0ms. | 813 return base::TimeDelta(); // Default delay is 0ms. |
| 812 } | 814 } |
| 813 return base::TimeDelta::FromMilliseconds(delay); | 815 return base::TimeDelta::FromMilliseconds(delay); |
| 814 } | 816 } |
| 815 | 817 |
| 816 } // namespace chromeos | 818 } // namespace chromeos |
| OLD | NEW |