Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed DeviceLocalAccountTest. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.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/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
19 #include "chrome/browser/chromeos/login/user_manager.h" 19 #include "chrome/browser/chromeos/login/user_manager.h"
20 #include "chrome/browser/chromeos/policy/device_local_account.h"
20 #include "chrome/browser/chromeos/settings/cros_settings.h" 21 #include "chrome/browser/chromeos/settings/cros_settings.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chromeos/cryptohome/async_method_caller.h" 24 #include "chromeos/cryptohome/async_method_caller.h"
24 25
25 namespace chromeos { 26 namespace chromeos {
26 27
27 namespace { 28 namespace {
28 29
29 std::string FormatKioskAppUserId(const std::string& app_id) { 30 std::string FormatKioskAppAccountId(const std::string& app_id) {
30 return app_id + '@' + UserManager::kKioskAppUserDomain; 31 return app_id + '@' + UserManager::kKioskAppUserDomain;
31 } 32 }
32 33
33 void OnRemoveAppCryptohomeComplete(const std::string& app, 34 void OnRemoveAppCryptohomeComplete(const std::string& app,
34 bool success, 35 bool success,
35 cryptohome::MountError return_code) { 36 cryptohome::MountError return_code) {
36 if (!success) { 37 if (!success) {
37 LOG(ERROR) << "Remove cryptohome for " << app 38 LOG(ERROR) << "Remove cryptohome for " << app
38 << " failed, return code: " << return_code; 39 << " failed, return code: " << return_code;
39 } 40 }
(...skipping 12 matching lines...) Expand all
52 53
53 if (!account_dict->GetStringWithoutPathExpansion( 54 if (!account_dict->GetStringWithoutPathExpansion(
54 kAccountsPrefDeviceLocalAccountsKeyId, account_id)) { 55 kAccountsPrefDeviceLocalAccountsKeyId, account_id)) {
55 LOG(ERROR) << "Account ID missing"; 56 LOG(ERROR) << "Account ID missing";
56 return false; 57 return false;
57 } 58 }
58 59
59 int type; 60 int type;
60 if (!account_dict->GetIntegerWithoutPathExpansion( 61 if (!account_dict->GetIntegerWithoutPathExpansion(
61 kAccountsPrefDeviceLocalAccountsKeyType, &type) || 62 kAccountsPrefDeviceLocalAccountsKeyType, &type) ||
62 type != DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP) { 63 type != policy::DeviceLocalAccount::TYPE_KIOSK_APP) {
63 // Not a kiosk app. 64 // Not a kiosk app.
64 return false; 65 return false;
65 } 66 }
66 67
67 if (!account_dict->GetStringWithoutPathExpansion( 68 if (!account_dict->GetStringWithoutPathExpansion(
68 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id)) { 69 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id)) {
69 LOG(ERROR) << "Kiosk app id missing for " << *account_id; 70 LOG(ERROR) << "Kiosk app id missing for " << *account_id;
70 return false; 71 return false;
71 } 72 }
72 73
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 KioskAppManager::App::App() : is_loading(false) {} 110 KioskAppManager::App::App() : is_loading(false) {}
110 KioskAppManager::App::~App() {} 111 KioskAppManager::App::~App() {}
111 112
112 std::string KioskAppManager::GetAutoLaunchApp() const { 113 std::string KioskAppManager::GetAutoLaunchApp() const {
113 return auto_launch_app_id_; 114 return auto_launch_app_id_;
114 } 115 }
115 116
116 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { 117 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) {
117 CrosSettings::Get()->SetString( 118 CrosSettings::Get()->SetString(
118 kAccountsPrefDeviceLocalAccountAutoLoginId, 119 kAccountsPrefDeviceLocalAccountAutoLoginId,
119 app_id.empty() ? std::string() : FormatKioskAppUserId(app_id)); 120 app_id.empty() ? std::string() : FormatKioskAppAccountId(app_id));
120 CrosSettings::Get()->SetInteger( 121 CrosSettings::Get()->SetInteger(
121 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0); 122 kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0);
122 } 123 }
123 124
124 void KioskAppManager::AddApp(const std::string& app_id) { 125 void KioskAppManager::AddApp(const std::string& app_id) {
125 CrosSettings* cros_settings = CrosSettings::Get(); 126 CrosSettings* cros_settings = CrosSettings::Get();
126 const base::ListValue* accounts_list = NULL; 127 const base::ListValue* accounts_list = NULL;
127 cros_settings->GetList(kAccountsPrefDeviceLocalAccounts, &accounts_list); 128 cros_settings->GetList(kAccountsPrefDeviceLocalAccounts, &accounts_list);
128 129
129 // Don't insert if the app if it's already in the list. 130 // Don't insert if the app if it's already in the list.
130 base::ListValue new_accounts_list; 131 base::ListValue new_accounts_list;
131 if (accounts_list) { 132 if (accounts_list) {
132 for (base::ListValue::const_iterator entry(accounts_list->begin()); 133 for (base::ListValue::const_iterator entry(accounts_list->begin());
133 entry != accounts_list->end(); ++entry) { 134 entry != accounts_list->end(); ++entry) {
134 std::string account_id; 135 std::string account_id;
135 std::string kiosk_app_id; 136 std::string kiosk_app_id;
136 if (DecodeDeviceLocalAccount(*entry, &account_id, &kiosk_app_id) && 137 if (DecodeDeviceLocalAccount(*entry, &account_id, &kiosk_app_id) &&
137 kiosk_app_id == app_id) { 138 kiosk_app_id == app_id) {
138 return; 139 return;
139 } 140 }
140 new_accounts_list.Append((*entry)->DeepCopy()); 141 new_accounts_list.Append((*entry)->DeepCopy());
141 } 142 }
142 } 143 }
143 144
144 // Add the new account. 145 // Add the new account.
145 scoped_ptr<base::DictionaryValue> new_entry(new base::DictionaryValue()); 146 scoped_ptr<base::DictionaryValue> new_entry(new base::DictionaryValue());
146 new_entry->SetStringWithoutPathExpansion( 147 new_entry->SetStringWithoutPathExpansion(
147 kAccountsPrefDeviceLocalAccountsKeyId, FormatKioskAppUserId(app_id)); 148 kAccountsPrefDeviceLocalAccountsKeyId, FormatKioskAppAccountId(app_id));
148 new_entry->SetIntegerWithoutPathExpansion( 149 new_entry->SetIntegerWithoutPathExpansion(
149 kAccountsPrefDeviceLocalAccountsKeyType, 150 kAccountsPrefDeviceLocalAccountsKeyType,
150 DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP); 151 policy::DeviceLocalAccount::TYPE_KIOSK_APP);
151 new_entry->SetStringWithoutPathExpansion( 152 new_entry->SetStringWithoutPathExpansion(
152 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id); 153 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, app_id);
153 new_accounts_list.Append(new_entry.release()); 154 new_accounts_list.Append(new_entry.release());
154 cros_settings->Set(kAccountsPrefDeviceLocalAccounts, new_accounts_list); 155 cros_settings->Set(kAccountsPrefDeviceLocalAccounts, new_accounts_list);
155 } 156 }
156 157
157 void KioskAppManager::RemoveApp(const std::string& app_id) { 158 void KioskAppManager::RemoveApp(const std::string& app_id) {
158 CrosSettings* cros_settings = CrosSettings::Get(); 159 CrosSettings* cros_settings = CrosSettings::Get();
159 const base::ListValue* accounts_list = NULL; 160 const base::ListValue* accounts_list = NULL;
160 cros_settings->GetList(kAccountsPrefDeviceLocalAccounts, &accounts_list); 161 cros_settings->GetList(kAccountsPrefDeviceLocalAccounts, &accounts_list);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 323 }
323 324
324 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { 325 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) {
325 FOR_EACH_OBSERVER(KioskAppManagerObserver, 326 FOR_EACH_OBSERVER(KioskAppManagerObserver,
326 observers_, 327 observers_,
327 OnKioskAppDataLoadFailure(app_id)); 328 OnKioskAppDataLoadFailure(app_id));
328 RemoveApp(app_id); 329 RemoveApp(app_id);
329 } 330 }
330 331
331 } // namespace chromeos 332 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698