OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/users/supervised_user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio n.h" | 18 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio n.h" |
19 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" | 19 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" |
20 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" | 20 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" |
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
22 #include "chrome/browser/supervised_user/supervised_user_service.h" | 22 #include "chrome/browser/supervised_user/supervised_user_service.h" |
23 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 23 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
24 #include "chromeos/login/user_names.h" | 24 #include "chromeos/login/user_names.h" |
25 #include "chromeos/settings/cros_settings_names.h" | 25 #include "chromeos/settings/cros_settings_names.h" |
26 #include "components/user_manager/user_id.h" | |
26 #include "components/user_manager/user_type.h" | 27 #include "components/user_manager/user_type.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "google_apis/gaia/gaia_auth_util.h" | 29 #include "google_apis/gaia/gaia_auth_util.h" |
29 | 30 |
30 using content::BrowserThread; | 31 using content::BrowserThread; |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Names for pref keys in Local State. | 35 // Names for pref keys in Local State. |
35 // A map from supervised user local user id to sync user id. | 36 // A map from supervised user local user id to sync user id. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 ChromeUserManagerImpl* owner) | 134 ChromeUserManagerImpl* owner) |
134 : owner_(owner), cros_settings_(CrosSettings::Get()) { | 135 : owner_(owner), cros_settings_(CrosSettings::Get()) { |
135 // SupervisedUserManager instance should be used only on UI thread. | 136 // SupervisedUserManager instance should be used only on UI thread. |
136 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
137 authentication_.reset(new SupervisedUserAuthentication(this)); | 138 authentication_.reset(new SupervisedUserAuthentication(this)); |
138 } | 139 } |
139 | 140 |
140 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { | 141 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { |
141 } | 142 } |
142 | 143 |
143 std::string SupervisedUserManagerImpl::GenerateUserId() { | 144 user_manager::UserID SupervisedUserManagerImpl::GenerateUserId() { |
144 int counter = g_browser_process->local_state()-> | 145 int counter = g_browser_process->local_state()-> |
145 GetInteger(kSupervisedUsersNextId); | 146 GetInteger(kSupervisedUsersNextId); |
146 std::string id; | 147 user_manager::UserID user_id = user_manager::UserID(std::string(), std::string ()); |
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:47
EmptyGaiaID() ?
| |
147 bool user_exists; | 148 bool user_exists; |
148 do { | 149 do { |
149 id = base::StringPrintf( | 150 const std::string email = base::StringPrintf( |
150 "%d@%s", counter, chromeos::login::kSupervisedUserDomain); | 151 "%d@%s", counter, chromeos::login::kSupervisedUserDomain); |
151 counter++; | 152 counter++; |
152 user_exists = (NULL != owner_->FindUser(id)); | 153 user_id = user_manager::UserID::FromUserEmail(email); |
154 user_exists = (NULL != owner_->FindUser(user_id)); | |
153 DCHECK(!user_exists); | 155 DCHECK(!user_exists); |
154 if (user_exists) { | 156 if (user_exists) { |
155 LOG(ERROR) << "Supervised user with id " << id << " already exists."; | 157 LOG(ERROR) << "Supervised user with email " << email << " already exists." ; |
156 } | 158 } |
157 } while (user_exists); | 159 } while (user_exists); |
158 | 160 |
159 g_browser_process->local_state()-> | 161 g_browser_process->local_state()-> |
160 SetInteger(kSupervisedUsersNextId, counter); | 162 SetInteger(kSupervisedUsersNextId, counter); |
161 | 163 |
162 g_browser_process->local_state()->CommitPendingWrite(); | 164 g_browser_process->local_state()->CommitPendingWrite(); |
163 return id; | 165 return user_id; |
164 } | 166 } |
165 | 167 |
166 bool SupervisedUserManagerImpl::HasSupervisedUsers( | 168 bool SupervisedUserManagerImpl::HasSupervisedUsers( |
167 const std::string& manager_id) const { | 169 const user_manager::UserID& manager_id) const { |
168 const user_manager::UserList& users = owner_->GetUsers(); | 170 const user_manager::UserList& users = owner_->GetUsers(); |
169 for (user_manager::UserList::const_iterator it = users.begin(); | 171 for (user_manager::UserList::const_iterator it = users.begin(); |
170 it != users.end(); | 172 it != users.end(); |
171 ++it) { | 173 ++it) { |
172 if ((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) { | 174 if ((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) { |
173 if (manager_id == GetManagerUserId((*it)->email())) | 175 if (manager_id == GetManagerUserId((*it)->GetUserID())) |
174 return true; | 176 return true; |
175 } | 177 } |
176 } | 178 } |
177 return false; | 179 return false; |
178 } | 180 } |
179 | 181 |
180 const user_manager::User* SupervisedUserManagerImpl::CreateUserRecord( | 182 const user_manager::User* SupervisedUserManagerImpl::CreateUserRecord( |
181 const std::string& manager_id, | 183 const user_manager::UserID& manager_id, |
182 const std::string& local_user_id, | 184 const user_manager::UserID& local_user_id, |
183 const std::string& sync_user_id, | 185 const std::string& sync_user_id, |
184 const base::string16& display_name) { | 186 const base::string16& display_name) { |
185 const user_manager::User* user = FindByDisplayName(display_name); | 187 const user_manager::User* user = FindByDisplayName(display_name); |
186 DCHECK(!user); | 188 DCHECK(!user); |
187 if (user) | 189 if (user) |
188 return user; | 190 return user; |
189 const user_manager::User* manager = owner_->FindUser(manager_id); | 191 const user_manager::User* manager = owner_->FindUser(manager_id); |
190 CHECK(manager); | 192 CHECK(manager); |
191 | 193 |
192 PrefService* local_state = g_browser_process->local_state(); | 194 PrefService* local_state = g_browser_process->local_state(); |
193 | 195 |
194 user_manager::User* new_user = | 196 user_manager::User* new_user = |
195 user_manager::User::CreateSupervisedUser(local_user_id); | 197 user_manager::User::CreateSupervisedUser(local_user_id); |
196 | 198 |
197 owner_->AddUserRecord(new_user); | 199 owner_->AddUserRecord(new_user); |
198 | 200 |
199 ListPrefUpdate prefs_new_users_update(local_state, | 201 ListPrefUpdate prefs_new_users_update(local_state, |
200 kSupervisedUsersFirstRun); | 202 kSupervisedUsersFirstRun); |
201 DictionaryPrefUpdate sync_id_update(local_state, kSupervisedUserSyncId); | 203 DictionaryPrefUpdate sync_id_update(local_state, kSupervisedUserSyncId); |
202 DictionaryPrefUpdate manager_update(local_state, kSupervisedUserManagers); | 204 DictionaryPrefUpdate manager_update(local_state, kSupervisedUserManagers); |
203 DictionaryPrefUpdate manager_name_update(local_state, | 205 DictionaryPrefUpdate manager_name_update(local_state, |
204 kSupervisedUserManagerNames); | 206 kSupervisedUserManagerNames); |
205 DictionaryPrefUpdate manager_email_update( | 207 DictionaryPrefUpdate manager_email_update( |
206 local_state, | 208 local_state, |
207 kSupervisedUserManagerDisplayEmails); | 209 kSupervisedUserManagerDisplayEmails); |
208 | 210 |
209 prefs_new_users_update->Insert(0, new base::StringValue(local_user_id)); | 211 prefs_new_users_update->Insert(0, new base::StringValue(local_user_id.GetUserE mail())); |
210 | 212 |
211 sync_id_update->SetWithoutPathExpansion(local_user_id, | 213 sync_id_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(), |
212 new base::StringValue(sync_user_id)); | 214 new base::StringValue(sync_user_id)); |
213 manager_update->SetWithoutPathExpansion(local_user_id, | 215 manager_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(), |
214 new base::StringValue(manager->email())); | 216 new base::StringValue(manager->GetUserID().GetUserEmail())); |
215 manager_name_update->SetWithoutPathExpansion(local_user_id, | 217 manager_name_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(), |
216 new base::StringValue(manager->GetDisplayName())); | 218 new base::StringValue(manager->GetDisplayName())); |
217 manager_email_update->SetWithoutPathExpansion(local_user_id, | 219 manager_email_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(), |
218 new base::StringValue(manager->display_email())); | 220 new base::StringValue(manager->display_email())); |
219 | 221 |
220 owner_->SaveUserDisplayName(local_user_id, display_name); | 222 owner_->SaveUserDisplayName(local_user_id, display_name); |
221 | 223 |
222 g_browser_process->local_state()->CommitPendingWrite(); | 224 g_browser_process->local_state()->CommitPendingWrite(); |
223 return new_user; | 225 return new_user; |
224 } | 226 } |
225 | 227 |
226 std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id) | 228 std::string SupervisedUserManagerImpl::GetUserSyncId(const user_manager::UserID& user_id) |
227 const { | 229 const { |
228 std::string result; | 230 std::string result; |
229 GetUserStringValue(user_id, kSupervisedUserSyncId, &result); | 231 GetUserStringValue(user_id, kSupervisedUserSyncId, &result); |
230 return result; | 232 return result; |
231 } | 233 } |
232 | 234 |
233 base::string16 SupervisedUserManagerImpl::GetManagerDisplayName( | 235 base::string16 SupervisedUserManagerImpl::GetManagerDisplayName( |
234 const std::string& user_id) const { | 236 const user_manager::UserID& user_id) const { |
235 PrefService* local_state = g_browser_process->local_state(); | 237 PrefService* local_state = g_browser_process->local_state(); |
236 const base::DictionaryValue* manager_names = | 238 const base::DictionaryValue* manager_names = |
237 local_state->GetDictionary(kSupervisedUserManagerNames); | 239 local_state->GetDictionary(kSupervisedUserManagerNames); |
238 base::string16 result; | 240 base::string16 result; |
239 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && | 241 if (manager_names->GetStringWithoutPathExpansion(user_id.GetUserEmail(), &resu lt) && |
240 !result.empty()) | 242 !result.empty()) |
241 return result; | 243 return result; |
242 return base::UTF8ToUTF16(GetManagerDisplayEmail(user_id)); | 244 return base::UTF8ToUTF16(GetManagerDisplayEmail(user_id)); |
243 } | 245 } |
244 | 246 |
245 std::string SupervisedUserManagerImpl::GetManagerUserId( | 247 user_manager::UserID SupervisedUserManagerImpl::GetManagerUserId( |
246 const std::string& user_id) const { | 248 const user_manager::UserID& user_id) const { |
247 std::string result; | 249 std::string result; |
248 GetUserStringValue(user_id, kSupervisedUserManagers, &result); | 250 GetUserStringValue(user_id, kSupervisedUserManagers, &result); |
249 return result; | 251 return user_manager::UserID::FromUserEmail(result); |
250 } | 252 } |
251 | 253 |
252 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( | 254 std::string SupervisedUserManagerImpl::GetManagerDisplayEmail( |
253 const std::string& user_id) const { | 255 const user_manager::UserID& user_id) const { |
254 std::string result; | 256 std::string result; |
255 if (GetUserStringValue(user_id, | 257 if (GetUserStringValue(user_id, |
256 kSupervisedUserManagerDisplayEmails, | 258 kSupervisedUserManagerDisplayEmails, |
257 &result) && | 259 &result) && |
258 !result.empty()) | 260 !result.empty()) |
259 return result; | 261 return result; |
260 return GetManagerUserId(user_id); | 262 return GetManagerUserId(user_id).GetUserEmail(); |
261 } | 263 } |
262 | 264 |
263 void SupervisedUserManagerImpl::GetPasswordInformation( | 265 void SupervisedUserManagerImpl::GetPasswordInformation( |
264 const std::string& user_id, | 266 const user_manager::UserID& user_id, |
265 base::DictionaryValue* result) { | 267 base::DictionaryValue* result) { |
266 int value; | 268 int value; |
267 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value)) | 269 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value)) |
268 result->SetIntegerWithoutPathExpansion(kSchemaVersion, value); | 270 result->SetIntegerWithoutPathExpansion(kSchemaVersion, value); |
269 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value)) | 271 if (GetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, &value)) |
270 result->SetIntegerWithoutPathExpansion(kPasswordRevision, value); | 272 result->SetIntegerWithoutPathExpansion(kPasswordRevision, value); |
271 | 273 |
272 bool flag; | 274 bool flag; |
273 if (GetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, &flag)) | 275 if (GetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, &flag)) |
274 result->SetBooleanWithoutPathExpansion(kRequirePasswordUpdate, flag); | 276 result->SetBooleanWithoutPathExpansion(kRequirePasswordUpdate, flag); |
275 if (GetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, &flag)) | 277 if (GetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, &flag)) |
276 result->SetBooleanWithoutPathExpansion(kHasIncompleteKey, flag); | 278 result->SetBooleanWithoutPathExpansion(kHasIncompleteKey, flag); |
277 | 279 |
278 std::string salt; | 280 std::string salt; |
279 if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt)) | 281 if (GetUserStringValue(user_id, kSupervisedUserPasswordSalt, &salt)) |
280 result->SetStringWithoutPathExpansion(kSalt, salt); | 282 result->SetStringWithoutPathExpansion(kSalt, salt); |
281 } | 283 } |
282 | 284 |
283 void SupervisedUserManagerImpl::SetPasswordInformation( | 285 void SupervisedUserManagerImpl::SetPasswordInformation( |
284 const std::string& user_id, | 286 const user_manager::UserID& user_id, |
285 const base::DictionaryValue* password_info) { | 287 const base::DictionaryValue* password_info) { |
286 int value; | 288 int value; |
287 if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value)) | 289 if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value)) |
288 SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, value); | 290 SetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, value); |
289 if (password_info->GetIntegerWithoutPathExpansion(kPasswordRevision, &value)) | 291 if (password_info->GetIntegerWithoutPathExpansion(kPasswordRevision, &value)) |
290 SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, value); | 292 SetUserIntegerValue(user_id, kSupervisedUserPasswordRevision, value); |
291 | 293 |
292 bool flag; | 294 bool flag; |
293 if (password_info->GetBooleanWithoutPathExpansion(kRequirePasswordUpdate, | 295 if (password_info->GetBooleanWithoutPathExpansion(kRequirePasswordUpdate, |
294 &flag)) { | 296 &flag)) { |
295 SetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, flag); | 297 SetUserBooleanValue(user_id, kSupervisedUserNeedPasswordUpdate, flag); |
296 } | 298 } |
297 if (password_info->GetBooleanWithoutPathExpansion(kHasIncompleteKey, &flag)) | 299 if (password_info->GetBooleanWithoutPathExpansion(kHasIncompleteKey, &flag)) |
298 SetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, flag); | 300 SetUserBooleanValue(user_id, kSupervisedUserIncompleteKey, flag); |
299 | 301 |
300 std::string salt; | 302 std::string salt; |
301 if (password_info->GetStringWithoutPathExpansion(kSalt, &salt)) | 303 if (password_info->GetStringWithoutPathExpansion(kSalt, &salt)) |
302 SetUserStringValue(user_id, kSupervisedUserPasswordSalt, salt); | 304 SetUserStringValue(user_id, kSupervisedUserPasswordSalt, salt); |
303 g_browser_process->local_state()->CommitPendingWrite(); | 305 g_browser_process->local_state()->CommitPendingWrite(); |
304 } | 306 } |
305 | 307 |
306 bool SupervisedUserManagerImpl::GetUserStringValue( | 308 bool SupervisedUserManagerImpl::GetUserStringValue( |
307 const std::string& user_id, | 309 const user_manager::UserID& user_id, |
308 const char* key, | 310 const char* key, |
309 std::string* out_value) const { | 311 std::string* out_value) const { |
310 PrefService* local_state = g_browser_process->local_state(); | 312 PrefService* local_state = g_browser_process->local_state(); |
311 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); | 313 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
312 return dictionary->GetStringWithoutPathExpansion(user_id, out_value); | 314 return dictionary->GetStringWithoutPathExpansion(user_id.GetUserEmail(), out_v alue); |
313 } | 315 } |
314 | 316 |
315 bool SupervisedUserManagerImpl::GetUserIntegerValue( | 317 bool SupervisedUserManagerImpl::GetUserIntegerValue( |
316 const std::string& user_id, | 318 const user_manager::UserID& user_id, |
317 const char* key, | 319 const char* key, |
318 int* out_value) const { | 320 int* out_value) const { |
319 PrefService* local_state = g_browser_process->local_state(); | 321 PrefService* local_state = g_browser_process->local_state(); |
320 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); | 322 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
321 return dictionary->GetIntegerWithoutPathExpansion(user_id, out_value); | 323 return dictionary->GetIntegerWithoutPathExpansion(user_id.GetUserEmail(), out_ value); |
322 } | 324 } |
323 | 325 |
324 bool SupervisedUserManagerImpl::GetUserBooleanValue(const std::string& user_id, | 326 bool SupervisedUserManagerImpl::GetUserBooleanValue(const user_manager::UserID& user_id, |
325 const char* key, | 327 const char* key, |
326 bool* out_value) const { | 328 bool* out_value) const { |
327 PrefService* local_state = g_browser_process->local_state(); | 329 PrefService* local_state = g_browser_process->local_state(); |
328 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); | 330 const base::DictionaryValue* dictionary = local_state->GetDictionary(key); |
329 return dictionary->GetBooleanWithoutPathExpansion(user_id, out_value); | 331 return dictionary->GetBooleanWithoutPathExpansion(user_id.GetUserEmail(), out_ value); |
330 } | 332 } |
331 | 333 |
332 void SupervisedUserManagerImpl::SetUserStringValue( | 334 void SupervisedUserManagerImpl::SetUserStringValue( |
333 const std::string& user_id, | 335 const user_manager::UserID& user_id, |
334 const char* key, | 336 const char* key, |
335 const std::string& value) { | 337 const std::string& value) { |
336 PrefService* local_state = g_browser_process->local_state(); | 338 PrefService* local_state = g_browser_process->local_state(); |
337 DictionaryPrefUpdate update(local_state, key); | 339 DictionaryPrefUpdate update(local_state, key); |
338 update->SetStringWithoutPathExpansion(user_id, value); | 340 update->SetStringWithoutPathExpansion(user_id.GetUserEmail(), value); |
339 } | 341 } |
340 | 342 |
341 void SupervisedUserManagerImpl::SetUserIntegerValue( | 343 void SupervisedUserManagerImpl::SetUserIntegerValue( |
342 const std::string& user_id, | 344 const user_manager::UserID& user_id, |
343 const char* key, | 345 const char* key, |
344 const int value) { | 346 const int value) { |
345 PrefService* local_state = g_browser_process->local_state(); | 347 PrefService* local_state = g_browser_process->local_state(); |
346 DictionaryPrefUpdate update(local_state, key); | 348 DictionaryPrefUpdate update(local_state, key); |
347 update->SetIntegerWithoutPathExpansion(user_id, value); | 349 update->SetIntegerWithoutPathExpansion(user_id.GetUserEmail(), value); |
348 } | 350 } |
349 | 351 |
350 void SupervisedUserManagerImpl::SetUserBooleanValue(const std::string& user_id, | 352 void SupervisedUserManagerImpl::SetUserBooleanValue(const user_manager::UserID& user_id, |
351 const char* key, | 353 const char* key, |
352 const bool value) { | 354 const bool value) { |
353 PrefService* local_state = g_browser_process->local_state(); | 355 PrefService* local_state = g_browser_process->local_state(); |
354 DictionaryPrefUpdate update(local_state, key); | 356 DictionaryPrefUpdate update(local_state, key); |
355 update->SetBooleanWithoutPathExpansion(user_id, value); | 357 update->SetBooleanWithoutPathExpansion(user_id.GetUserEmail(), value); |
356 } | 358 } |
357 | 359 |
358 const user_manager::User* SupervisedUserManagerImpl::FindByDisplayName( | 360 const user_manager::User* SupervisedUserManagerImpl::FindByDisplayName( |
359 const base::string16& display_name) const { | 361 const base::string16& display_name) const { |
360 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 362 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
361 const user_manager::UserList& users = owner_->GetUsers(); | 363 const user_manager::UserList& users = owner_->GetUsers(); |
362 for (user_manager::UserList::const_iterator it = users.begin(); | 364 for (user_manager::UserList::const_iterator it = users.begin(); |
363 it != users.end(); | 365 it != users.end(); |
364 ++it) { | 366 ++it) { |
365 if (((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) && | 367 if (((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) && |
366 ((*it)->display_name() == display_name)) { | 368 ((*it)->display_name() == display_name)) { |
367 return *it; | 369 return *it; |
368 } | 370 } |
369 } | 371 } |
370 return NULL; | 372 return NULL; |
371 } | 373 } |
372 | 374 |
373 const user_manager::User* SupervisedUserManagerImpl::FindBySyncId( | 375 const user_manager::User* SupervisedUserManagerImpl::FindBySyncId( |
374 const std::string& sync_id) const { | 376 const std::string& sync_id) const { |
375 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 377 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
376 const user_manager::UserList& users = owner_->GetUsers(); | 378 const user_manager::UserList& users = owner_->GetUsers(); |
377 for (user_manager::UserList::const_iterator it = users.begin(); | 379 for (user_manager::UserList::const_iterator it = users.begin(); |
378 it != users.end(); | 380 it != users.end(); |
379 ++it) { | 381 ++it) { |
380 if (((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) && | 382 if (((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) && |
381 (GetUserSyncId((*it)->email()) == sync_id)) { | 383 (GetUserSyncId((*it)->GetUserID()) == sync_id)) { |
382 return *it; | 384 return *it; |
383 } | 385 } |
384 } | 386 } |
385 return NULL; | 387 return NULL; |
386 } | 388 } |
387 | 389 |
388 void SupervisedUserManagerImpl::StartCreationTransaction( | 390 void SupervisedUserManagerImpl::StartCreationTransaction( |
389 const base::string16& display_name) { | 391 const base::string16& display_name) { |
390 g_browser_process->local_state()-> | 392 g_browser_process->local_state()-> |
391 SetString(kSupervisedUserCreationTransactionDisplayName, | 393 SetString(kSupervisedUserCreationTransactionDisplayName, |
392 base::UTF16ToASCII(display_name)); | 394 base::UTF16ToASCII(display_name)); |
393 g_browser_process->local_state()->CommitPendingWrite(); | 395 g_browser_process->local_state()->CommitPendingWrite(); |
394 } | 396 } |
395 | 397 |
396 void SupervisedUserManagerImpl::SetCreationTransactionUserId( | 398 void SupervisedUserManagerImpl::SetCreationTransactionUserId( |
397 const std::string& email) { | 399 const user_manager::UserID& user_id) { |
398 g_browser_process->local_state()-> | 400 g_browser_process->local_state()-> |
399 SetString(kSupervisedUserCreationTransactionUserId, | 401 SetString(kSupervisedUserCreationTransactionUserId, |
400 email); | 402 user_id.GetUserEmail()); |
401 g_browser_process->local_state()->CommitPendingWrite(); | 403 g_browser_process->local_state()->CommitPendingWrite(); |
402 } | 404 } |
403 | 405 |
404 void SupervisedUserManagerImpl::CommitCreationTransaction() { | 406 void SupervisedUserManagerImpl::CommitCreationTransaction() { |
405 g_browser_process->local_state()-> | 407 g_browser_process->local_state()-> |
406 ClearPref(kSupervisedUserCreationTransactionDisplayName); | 408 ClearPref(kSupervisedUserCreationTransactionDisplayName); |
407 g_browser_process->local_state()-> | 409 g_browser_process->local_state()-> |
408 ClearPref(kSupervisedUserCreationTransactionUserId); | 410 ClearPref(kSupervisedUserCreationTransactionUserId); |
409 g_browser_process->local_state()->CommitPendingWrite(); | 411 g_browser_process->local_state()->CommitPendingWrite(); |
410 } | 412 } |
411 | 413 |
412 bool SupervisedUserManagerImpl::HasFailedUserCreationTransaction() { | 414 bool SupervisedUserManagerImpl::HasFailedUserCreationTransaction() { |
413 return !(g_browser_process->local_state()-> | 415 return !(g_browser_process->local_state()-> |
414 GetString(kSupervisedUserCreationTransactionDisplayName). | 416 GetString(kSupervisedUserCreationTransactionDisplayName). |
415 empty()); | 417 empty()); |
416 } | 418 } |
417 | 419 |
418 void SupervisedUserManagerImpl::RollbackUserCreationTransaction() { | 420 void SupervisedUserManagerImpl::RollbackUserCreationTransaction() { |
419 PrefService* prefs = g_browser_process->local_state(); | 421 PrefService* prefs = g_browser_process->local_state(); |
420 | 422 |
421 std::string display_name = prefs-> | 423 std::string display_name = prefs-> |
422 GetString(kSupervisedUserCreationTransactionDisplayName); | 424 GetString(kSupervisedUserCreationTransactionDisplayName); |
423 std::string user_id = prefs-> | 425 user_manager::UserID user_id(user_manager::UserID::FromUserEmail(prefs-> |
424 GetString(kSupervisedUserCreationTransactionUserId); | 426 GetString(kSupervisedUserCreationTransactionUserId))); |
425 | 427 |
426 LOG(WARNING) << "Cleaning up transaction for " | 428 LOG(WARNING) << "Cleaning up transaction for " |
427 << display_name << "/" << user_id; | 429 << display_name << "/" << user_id.GetUserEmail(); |
428 | 430 |
429 if (user_id.empty()) { | 431 if (user_id.empty()) { |
430 // Not much to do - just remove transaction. | 432 // Not much to do - just remove transaction. |
431 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); | 433 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); |
432 prefs->CommitPendingWrite(); | 434 prefs->CommitPendingWrite(); |
433 return; | 435 return; |
434 } | 436 } |
435 | 437 |
436 if (gaia::ExtractDomainName(user_id) != | 438 if (gaia::ExtractDomainName(user_id.GetUserEmail()) != |
437 chromeos::login::kSupervisedUserDomain) { | 439 chromeos::login::kSupervisedUserDomain) { |
438 LOG(WARNING) << "Clean up transaction for non-supervised user found :" | 440 LOG(WARNING) << "Clean up transaction for non-supervised user found :" |
439 << user_id << ", will not remove data"; | 441 << user_id.GetUserEmail() << ", will not remove data"; |
440 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); | 442 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); |
441 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); | 443 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); |
442 prefs->CommitPendingWrite(); | 444 prefs->CommitPendingWrite(); |
443 return; | 445 return; |
444 } | 446 } |
445 owner_->RemoveNonOwnerUserInternal(user_id, NULL); | 447 owner_->RemoveNonOwnerUserInternal(user_id, NULL); |
446 | 448 |
447 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); | 449 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); |
448 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); | 450 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); |
449 prefs->CommitPendingWrite(); | 451 prefs->CommitPendingWrite(); |
450 } | 452 } |
451 | 453 |
452 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( | 454 void SupervisedUserManagerImpl::RemoveNonCryptohomeData( |
453 const std::string& user_id) { | 455 const user_manager::UserID& user_id) { |
454 PrefService* prefs = g_browser_process->local_state(); | 456 PrefService* prefs = g_browser_process->local_state(); |
455 ListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun); | 457 ListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun); |
456 prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 458 prefs_new_users_update->Remove(base::StringValue(user_id.GetUserEmail()), NULL ); |
457 | 459 |
458 CleanPref(user_id, kSupervisedUserSyncId); | 460 CleanPref(user_id, kSupervisedUserSyncId); |
459 CleanPref(user_id, kSupervisedUserManagers); | 461 CleanPref(user_id, kSupervisedUserManagers); |
460 CleanPref(user_id, kSupervisedUserManagerNames); | 462 CleanPref(user_id, kSupervisedUserManagerNames); |
461 CleanPref(user_id, kSupervisedUserManagerDisplayEmails); | 463 CleanPref(user_id, kSupervisedUserManagerDisplayEmails); |
462 CleanPref(user_id, kSupervisedUserPasswordSalt); | 464 CleanPref(user_id, kSupervisedUserPasswordSalt); |
463 CleanPref(user_id, kSupervisedUserPasswordSchema); | 465 CleanPref(user_id, kSupervisedUserPasswordSchema); |
464 CleanPref(user_id, kSupervisedUserPasswordRevision); | 466 CleanPref(user_id, kSupervisedUserPasswordRevision); |
465 CleanPref(user_id, kSupervisedUserNeedPasswordUpdate); | 467 CleanPref(user_id, kSupervisedUserNeedPasswordUpdate); |
466 CleanPref(user_id, kSupervisedUserIncompleteKey); | 468 CleanPref(user_id, kSupervisedUserIncompleteKey); |
467 } | 469 } |
468 | 470 |
469 void SupervisedUserManagerImpl::CleanPref(const std::string& user_id, | 471 void SupervisedUserManagerImpl::CleanPref(const user_manager::UserID& user_id, |
470 const char* key) { | 472 const char* key) { |
471 PrefService* prefs = g_browser_process->local_state(); | 473 PrefService* prefs = g_browser_process->local_state(); |
472 DictionaryPrefUpdate dict_update(prefs, key); | 474 DictionaryPrefUpdate dict_update(prefs, key); |
473 dict_update->RemoveWithoutPathExpansion(user_id, NULL); | 475 dict_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL); |
474 } | 476 } |
475 | 477 |
476 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { | 478 bool SupervisedUserManagerImpl::CheckForFirstRun(const user_manager::UserID& use r_id) { |
477 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), | 479 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), |
478 kSupervisedUsersFirstRun); | 480 kSupervisedUsersFirstRun); |
479 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 481 return prefs_new_users_update->Remove(base::StringValue(user_id.GetUserEmail() ), NULL); |
480 } | 482 } |
481 | 483 |
482 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, | 484 void SupervisedUserManagerImpl::UpdateManagerName(const user_manager::UserID& ma nager_id, |
483 const base::string16& new_display_name) { | 485 const base::string16& new_display_name) { |
484 PrefService* local_state = g_browser_process->local_state(); | 486 PrefService* local_state = g_browser_process->local_state(); |
485 | 487 |
486 const base::DictionaryValue* manager_ids = | 488 const base::DictionaryValue* manager_ids = |
487 local_state->GetDictionary(kSupervisedUserManagers); | 489 local_state->GetDictionary(kSupervisedUserManagers); |
488 | 490 |
489 DictionaryPrefUpdate manager_name_update(local_state, | 491 DictionaryPrefUpdate manager_name_update(local_state, |
490 kSupervisedUserManagerNames); | 492 kSupervisedUserManagerNames); |
491 for (base::DictionaryValue::Iterator it(*manager_ids); !it.IsAtEnd(); | 493 for (base::DictionaryValue::Iterator it(*manager_ids); !it.IsAtEnd(); |
492 it.Advance()) { | 494 it.Advance()) { |
493 std::string user_id; | 495 std::string user_email; |
494 bool has_manager_id = it.value().GetAsString(&user_id); | 496 bool has_manager_id = it.value().GetAsString(&user_email); |
495 DCHECK(has_manager_id); | 497 DCHECK(has_manager_id); |
496 if (user_id == manager_id) { | 498 if (user_manager::UserID::FromUserEmail(user_email) == manager_id) { |
497 manager_name_update->SetWithoutPathExpansion( | 499 manager_name_update->SetWithoutPathExpansion( |
498 it.key(), | 500 it.key(), |
499 new base::StringValue(new_display_name)); | 501 new base::StringValue(new_display_name)); |
500 } | 502 } |
501 } | 503 } |
502 } | 504 } |
503 | 505 |
504 SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() { | 506 SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() { |
505 return authentication_.get(); | 507 return authentication_.get(); |
506 } | 508 } |
(...skipping 13 matching lines...) Expand all Loading... | |
520 } | 522 } |
521 | 523 |
522 void SupervisedUserManagerImpl::ConfigureSyncWithToken( | 524 void SupervisedUserManagerImpl::ConfigureSyncWithToken( |
523 Profile* profile, | 525 Profile* profile, |
524 const std::string& token) { | 526 const std::string& token) { |
525 if (!token.empty()) | 527 if (!token.empty()) |
526 SupervisedUserServiceFactory::GetForProfile(profile)->InitSync(token); | 528 SupervisedUserServiceFactory::GetForProfile(profile)->InitSync(token); |
527 } | 529 } |
528 | 530 |
529 } // namespace chromeos | 531 } // namespace chromeos |
OLD | NEW |