Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| index bd9f0e5ac811fe13cc9cb67b2f431da29d035346..02412b5437bb7d29c075c4b4098bd03ca5da4889 100644 |
| --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| #include <map> |
| +#include <set> |
| #include "base/bind.h" |
| #include "base/path_service.h" |
| @@ -13,11 +14,11 @@ |
| #include "base/values.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chromeos/cryptohome/async_method_caller.h" |
| -#include "content/public/browser/notification_details.h" |
| namespace chromeos { |
| @@ -70,24 +71,51 @@ KioskAppManager::App::~App() {} |
| std::string KioskAppManager::GetAutoLaunchApp() const { |
| std::string app_id; |
| - if (CrosSettings::Get()->GetString(kKioskAutoLaunch, &app_id)) |
| + std::string auto_login_id; |
| + if (CrosSettings::Get()->GetString(kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + &auto_login_id) && |
| + UserManager::ParseKioskAppUserId(auto_login_id, &app_id)) { |
| return app_id; |
| + } |
| return std::string(); |
| } |
| void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { |
| - CrosSettings::Get()->SetString(kKioskAutoLaunch, app_id); |
| + CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + UserManager::FormatKioskAppUserId(app_id)); |
| + CrosSettings::Get()->SetInteger(kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + 0); |
| } |
| void KioskAppManager::AddApp(const std::string& app_id) { |
| - base::StringValue value(app_id); |
| - CrosSettings::Get()->AppendToList(kKioskApps, &value); |
| + CrosSettings* cros_settings = CrosSettings::Get(); |
| + const base::DictionaryValue* accounts_dict = NULL; |
| + cros_settings->GetDictionary(kAccountsPrefDeviceLocalAccounts, |
| + &accounts_dict); |
| + scoped_ptr<base::DictionaryValue> new_accounts_dict( |
|
bartfab (slow)
2013/04/25 11:17:28
Nit: #include "base/memory/scoped_ptr.h"
Mattias Nissler (ping if slow)
2013/04/26 09:10:05
Done.
|
| + accounts_dict ? accounts_dict->DeepCopy() : new base::DictionaryValue()); |
| + |
| + scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); |
|
bartfab (slow)
2013/04/25 11:17:28
What is the advantage of a scoped_ptr here if you
Mattias Nissler (ping if slow)
2013/04/26 09:10:05
I made that a habit, don't have to worry about mem
|
| + entry_dict->SetStringWithoutPathExpansion( |
| + kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id); |
| + new_accounts_dict->SetWithoutPathExpansion( |
| + UserManager::FormatKioskAppUserId(app_id), entry_dict.release()); |
| + cros_settings->Set(kAccountsPrefDeviceLocalAccounts, *new_accounts_dict); |
| } |
| void KioskAppManager::RemoveApp(const std::string& app_id) { |
| - base::StringValue value(app_id); |
| - CrosSettings::Get()->RemoveFromList(kKioskApps, &value); |
| + CrosSettings* cros_settings = CrosSettings::Get(); |
| + const base::DictionaryValue* accounts_dict = NULL; |
| + cros_settings->GetDictionary(kAccountsPrefDeviceLocalAccounts, |
| + &accounts_dict); |
| + |
| + scoped_ptr<base::DictionaryValue> new_accounts_dict( |
| + accounts_dict ? accounts_dict->DeepCopy() : new base::DictionaryValue()); |
| + if (new_accounts_dict->RemoveWithoutPathExpansion( |
| + UserManager::FormatKioskAppUserId(app_id), NULL)) { |
| + cros_settings->Set(kAccountsPrefDeviceLocalAccounts, *new_accounts_dict); |
| + } |
| } |
| void KioskAppManager::GetApps(Apps* apps) const { |
| @@ -115,9 +143,11 @@ const base::RefCountedString* KioskAppManager::GetAppRawIcon( |
| } |
| bool KioskAppManager::GetDisableBailoutShortcut() const { |
| - bool disable; |
| - if (CrosSettings::Get()->GetBoolean(kKioskDisableBailoutShortcut, &disable)) |
| - return disable; |
| + bool enable; |
| + if (CrosSettings::Get()->GetBoolean( |
| + kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, &enable)) { |
| + return !enable; |
| + } |
| return false; |
| } |
| @@ -132,13 +162,15 @@ void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| KioskAppManager::KioskAppManager() { |
| UpdateAppData(); |
| - CrosSettings::Get()->AddSettingsObserver(kKioskApps, this); |
| + CrosSettings::Get()->AddSettingsObserver( |
| + kAccountsPrefDeviceLocalAccounts, this); |
| } |
| KioskAppManager::~KioskAppManager() {} |
| void KioskAppManager::CleanUp() { |
| - CrosSettings::Get()->RemoveSettingsObserver(kKioskApps, this); |
| + CrosSettings::Get()->RemoveSettingsObserver( |
| + kAccountsPrefDeviceLocalAccounts, this); |
| apps_.clear(); |
| } |
| @@ -160,24 +192,38 @@ void KioskAppManager::UpdateAppData() { |
| old_apps[apps_[i]->id()] = apps_[i]; |
| apps_.weak_clear(); // |old_apps| takes ownership |
| - const base::ListValue* new_apps; |
| - CHECK(CrosSettings::Get()->GetList(kKioskApps, &new_apps)); |
| - |
| - // Re-populates |apps_| and reuses existing KioskAppData when possible. |
| - for (base::ListValue::const_iterator new_it = new_apps->begin(); |
| - new_it != new_apps->end(); |
| - ++new_it) { |
| - std::string id; |
| - CHECK((*new_it)->GetAsString(&id)); |
| - |
| - std::map<std::string, KioskAppData*>::iterator old_it = old_apps.find(id); |
| - if (old_it != old_apps.end()) { |
| - apps_.push_back(old_it->second); |
| - old_apps.erase(old_it); |
| - } else { |
| - KioskAppData* new_app = new KioskAppData(this, id); |
| - apps_.push_back(new_app); // Takes ownership of |new_app|. |
| - new_app->Load(); |
| + const base::DictionaryValue* local_accounts; |
| + if (CrosSettings::Get()->GetDictionary(kAccountsPrefDeviceLocalAccounts, |
| + &local_accounts)) { |
| + // Re-populates |apps_| and reuses existing KioskAppData when possible. |
| + for (base::DictionaryValue::Iterator account(*local_accounts); |
| + !account.IsAtEnd(); account.Advance()) { |
| + const base::DictionaryValue* entry_dict = NULL; |
| + if (!account.value().GetAsDictionary(&entry_dict)) { |
| + NOTREACHED(); |
|
bartfab (slow)
2013/04/25 11:17:28
Nit: #include "base/logging.h"
Mattias Nissler (ping if slow)
2013/04/26 09:10:05
Done.
|
| + continue; |
| + } |
| + |
| + std::string kiosk_app_id; |
| + if (!entry_dict->GetStringWithoutPathExpansion( |
|
bartfab (slow)
2013/04/25 11:17:28
The code should look at account->key() instead to
Mattias Nissler (ping if slow)
2013/04/26 09:10:05
Switched to the type enum.
|
| + kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| + &kiosk_app_id)) { |
| + // Not a kiosk app. |
| + continue; |
| + } |
| + |
| + // TODO(mnissler): Support non-CWS update URLs. |
| + |
| + std::map<std::string, KioskAppData*>::iterator old_it = |
| + old_apps.find(kiosk_app_id); |
| + if (old_it != old_apps.end()) { |
| + apps_.push_back(old_it->second); |
| + old_apps.erase(old_it); |
| + } else { |
| + KioskAppData* new_app = new KioskAppData(this, kiosk_app_id); |
| + apps_.push_back(new_app); // Takes ownership of |new_app|. |
| + new_app->Load(); |
| + } |
| } |
| } |
| @@ -189,15 +235,15 @@ void KioskAppManager::UpdateAppData() { |
| it->first, base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
| } |
| STLDeleteValues(&old_apps); |
| + |
| + FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
| + OnKioskAppsListChanged()); |
| } |
| void KioskAppManager::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| DCHECK_EQ(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, type); |
| - DCHECK_EQ(kKioskApps, |
| - *content::Details<const std::string>(details).ptr()); |
| - |
| UpdateAppData(); |
| } |