| Index: chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc
|
| diff --git a/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc
|
| index 6687d28f742a760c27a6597ebf6f8b1b301da10d..786afbd9dcea2204db6c416dfa86630a008d1eb7 100644
|
| --- a/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc
|
| +++ b/chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_manager.cc
|
| @@ -12,6 +12,7 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/callback.h"
|
| #include "base/logging.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/lifetime/application_lifetime.h"
|
| @@ -96,7 +97,12 @@ static ArcKioskAppManager* g_arc_kiosk_app_manager = nullptr;
|
| } // namespace
|
|
|
| // static
|
| +const char ArcKioskAppManager::kArcKioskDictionaryName[] = "arc-kiosk";
|
| +const char ArcKioskAppManager::kKeyApps[] = "apps";
|
| +
|
| +// static
|
| void ArcKioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) {
|
| + registry->RegisterDictionaryPref(kArcKioskDictionaryName);
|
| registry->RegisterListPref(kArcKioskUsersToRemove);
|
| }
|
|
|
| @@ -108,22 +114,6 @@ void ArcKioskAppManager::RemoveObsoleteCryptohomes() {
|
| base::Bind(&PerformDelayedCryptohomeRemovals));
|
| }
|
|
|
| -ArcKioskAppManager::ArcKioskApp::ArcKioskApp(const ArcKioskApp& other) =
|
| - default;
|
| -
|
| -ArcKioskAppManager::ArcKioskApp::ArcKioskApp(
|
| - const policy::ArcKioskAppBasicInfo& app_info,
|
| - const AccountId& account_id,
|
| - const std::string& name)
|
| - : app_info_(app_info), account_id_(account_id), name_(name) {}
|
| -
|
| -ArcKioskAppManager::ArcKioskApp::~ArcKioskApp() = default;
|
| -
|
| -bool ArcKioskAppManager::ArcKioskApp::operator==(
|
| - const policy::ArcKioskAppBasicInfo& app_info) const {
|
| - return this->app_info_ == app_info;
|
| -}
|
| -
|
| // static
|
| ArcKioskAppManager* ArcKioskAppManager::Get() {
|
| return g_arc_kiosk_app_manager;
|
| @@ -154,14 +144,32 @@ const AccountId& ArcKioskAppManager::GetAutoLaunchAccountId() const {
|
| return auto_launch_account_id_;
|
| }
|
|
|
| -const ArcKioskAppManager::ArcKioskApp* ArcKioskAppManager::GetAppByAccountId(
|
| +const ArcKioskAppData* ArcKioskAppManager::GetAppByAccountId(
|
| const AccountId& account_id) {
|
| - for (auto& app : GetAllApps())
|
| - if (app.account_id() == account_id)
|
| - return &app;
|
| + for (auto& app : apps_)
|
| + if (app->account_id() == account_id)
|
| + return app.get();
|
| return nullptr;
|
| }
|
|
|
| +void ArcKioskAppManager::GetAllApps(Apps* apps) const {
|
| + apps->clear();
|
| + apps->reserve(apps_.size());
|
| + for (auto& app : apps_)
|
| + apps->push_back(app.get());
|
| +}
|
| +
|
| +void ArcKioskAppManager::UpdateNameAndIcon(const std::string& app_id,
|
| + const std::string& name,
|
| + const gfx::ImageSkia& icon) {
|
| + for (auto& app : apps_) {
|
| + if (app->app_id() == app_id) {
|
| + app->SetCache(name, icon);
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| void ArcKioskAppManager::AddObserver(ArcKioskAppManagerObserver* observer) {
|
| observers_.AddObserver(observer);
|
| }
|
| @@ -181,8 +189,10 @@ void ArcKioskAppManager::UpdateApps() {
|
|
|
| // Store current apps. We will compare old and new apps to determine which
|
| // apps are new, and which were deleted.
|
| - ArcKioskApps old_apps(std::move(apps_));
|
| -
|
| + std::map<std::string, std::unique_ptr<ArcKioskAppData>> old_apps;
|
| + for (auto& app : apps_)
|
| + old_apps[app->app_id()] = std::move(app);
|
| + apps_.clear();
|
| auto_launch_account_id_.clear();
|
| auto_launched_with_zero_delay_ = false;
|
| std::string auto_login_account_id_from_settings;
|
| @@ -206,18 +216,19 @@ void ArcKioskAppManager::UpdateApps() {
|
| auto_launched_with_zero_delay_ = auto_launch_delay == 0;
|
| }
|
|
|
| - auto old_it =
|
| - std::find(old_apps.begin(), old_apps.end(), account.arc_kiosk_app_info);
|
| + // Apps are keys by package name. http://crbug.com/665904
|
| + auto old_it = old_apps.find(account.arc_kiosk_app_info.package_name());
|
| if (old_it != old_apps.end()) {
|
| - apps_.push_back(std::move(*old_it));
|
| + apps_.push_back(std::move(old_it->second));
|
| old_apps.erase(old_it);
|
| } else {
|
| // Use package name when display name is not specified.
|
| std::string name = account.arc_kiosk_app_info.package_name();
|
| if (!account.arc_kiosk_app_info.display_name().empty())
|
| name = account.arc_kiosk_app_info.display_name();
|
| - apps_.push_back(
|
| - ArcKioskApp(account.arc_kiosk_app_info, account_id, name));
|
| + apps_.push_back(base::MakeUnique<ArcKioskAppData>(
|
| + account.arc_kiosk_app_info.package_name(), account_id, name));
|
| + apps_.back()->LoadFromCache();
|
| }
|
| CancelDelayedCryptohomeRemoval(cryptohome::Identification(account_id));
|
| }
|
| @@ -230,7 +241,7 @@ void ArcKioskAppManager::UpdateApps() {
|
| }
|
|
|
| void ArcKioskAppManager::ClearRemovedApps(
|
| - const std::vector<ArcKioskApp>& old_apps) {
|
| + const std::map<std::string, std::unique_ptr<ArcKioskAppData>>& old_apps) {
|
| // Check if currently active user must be deleted.
|
| bool active_user_to_be_deleted = false;
|
| const user_manager::User* active_user =
|
| @@ -238,7 +249,7 @@ void ArcKioskAppManager::ClearRemovedApps(
|
| if (active_user) {
|
| const AccountId active_account_id = active_user->GetAccountId();
|
| for (const auto& it : old_apps) {
|
| - if (it.account_id() == active_account_id) {
|
| + if (it.second->account_id() == active_account_id) {
|
| active_user_to_be_deleted = true;
|
| break;
|
| }
|
| @@ -247,7 +258,8 @@ void ArcKioskAppManager::ClearRemovedApps(
|
|
|
| // Remove cryptohome
|
| for (auto& entry : old_apps) {
|
| - const cryptohome::Identification cryptohome_id(entry.account_id());
|
| + entry.second->ClearCache();
|
| + const cryptohome::Identification cryptohome_id(entry.second->account_id());
|
| if (active_user_to_be_deleted) {
|
| // Schedule cryptohome removal after active user logout.
|
| ScheduleDelayedCryptohomeRemoval(cryptohome_id);
|
|
|