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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 14139003: Chrome OS multi-profiles backend and UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move IsMultiProfilesEnabled() out of cros Created 7 years, 8 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/login/user_manager_impl.h" 5 #include "chrome/browser/chromeos/login/user_manager_impl.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); 183 registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
184 registry->RegisterDictionaryPref(kUserDisplayName); 184 registry->RegisterDictionaryPref(kUserDisplayName);
185 registry->RegisterDictionaryPref(kUserDisplayEmail); 185 registry->RegisterDictionaryPref(kUserDisplayEmail);
186 SessionLengthLimiter::RegisterPrefs(registry); 186 SessionLengthLimiter::RegisterPrefs(registry);
187 } 187 }
188 188
189 UserManagerImpl::UserManagerImpl() 189 UserManagerImpl::UserManagerImpl()
190 : cros_settings_(CrosSettings::Get()), 190 : cros_settings_(CrosSettings::Get()),
191 device_local_account_policy_service_(NULL), 191 device_local_account_policy_service_(NULL),
192 users_loaded_(false), 192 users_loaded_(false),
193 logged_in_user_(NULL), 193 active_user_(NULL),
194 session_started_(false), 194 session_started_(false),
195 is_current_user_owner_(false), 195 is_current_user_owner_(false),
196 is_current_user_new_(false), 196 is_current_user_new_(false),
197 is_current_user_ephemeral_regular_user_(false), 197 is_current_user_ephemeral_regular_user_(false),
198 ephemeral_users_enabled_(false), 198 ephemeral_users_enabled_(false),
199 merge_session_state_(MERGE_STATUS_NOT_STARTED), 199 merge_session_state_(MERGE_STATUS_NOT_STARTED),
200 observed_sync_service_(NULL), 200 observed_sync_service_(NULL),
201 user_image_manager_(new UserImageManagerImpl) { 201 user_image_manager_(new UserImageManagerImpl) {
202 // UserManager instance should be used only on UI thread. 202 // UserManager instance should be used only on UI thread.
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, 204 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
205 content::NotificationService::AllSources()); 205 content::NotificationService::AllSources());
206 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 206 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
207 content::NotificationService::AllSources()); 207 content::NotificationService::AllSources());
208 RetrieveTrustedDevicePolicies(); 208 RetrieveTrustedDevicePolicies();
209 } 209 }
210 210
211 UserManagerImpl::~UserManagerImpl() { 211 UserManagerImpl::~UserManagerImpl() {
212 // Can't use STLDeleteElements because of the private destructor of User. 212 // Can't use STLDeleteElements because of the private destructor of User.
213 for (UserList::iterator it = users_.begin(); it != users_.end(); 213 for (UserList::iterator it = users_.begin(); it != users_.end();
214 it = users_.erase(it)) { 214 it = users_.erase(it)) {
215 if (logged_in_user_ == *it) 215 if (active_user_ == *it)
216 logged_in_user_ = NULL; 216 active_user_ = NULL;
217 delete *it; 217 delete *it;
218 } 218 }
219 delete logged_in_user_; 219 // These are pointers to the same User instances that were in users_ list.
220 logged_in_users_.clear();
221 delete active_user_;
220 } 222 }
221 223
222 void UserManagerImpl::Shutdown() { 224 void UserManagerImpl::Shutdown() {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
224 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, 226 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts,
225 this); 227 this);
226 // Stop the session length limiter. 228 // Stop the session length limiter.
227 session_length_limiter_.reset(); 229 session_length_limiter_.reset();
228 230
229 if (device_local_account_policy_service_) 231 if (device_local_account_policy_service_)
230 device_local_account_policy_service_->RemoveObserver(this); 232 device_local_account_policy_service_->RemoveObserver(this);
231 } 233 }
232 234
233 UserImageManager* UserManagerImpl::GetUserImageManager() { 235 UserImageManager* UserManagerImpl::GetUserImageManager() {
234 return user_image_manager_.get(); 236 return user_image_manager_.get();
235 } 237 }
236 238
237 const UserList& UserManagerImpl::GetUsers() const { 239 const UserList& UserManagerImpl::GetUsers() const {
238 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 240 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
239 return users_; 241 return users_;
240 } 242 }
241 243
244 const UserList& UserManagerImpl::GetLoggedInUsers() const {
245 return logged_in_users_;
246 }
247
242 void UserManagerImpl::UserLoggedIn(const std::string& email, 248 void UserManagerImpl::UserLoggedIn(const std::string& email,
243 const std::string& username_hash, 249 const std::string& username_hash,
244 bool browser_restart) { 250 bool browser_restart) {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 252
247 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles)) 253 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
248 DCHECK(!IsUserLoggedIn()); 254 DCHECK(!IsUserLoggedIn());
249 255
256 if (active_user_)
257 active_user_->set_is_active(false);
258
250 if (email == kGuestUserEMail) { 259 if (email == kGuestUserEMail) {
251 GuestUserLoggedIn(); 260 GuestUserLoggedIn();
252 } else if (email == kRetailModeUserEMail) { 261 } else if (email == kRetailModeUserEMail) {
253 RetailModeUserLoggedIn(); 262 RetailModeUserLoggedIn();
254 } else if (gaia::ExtractDomainName(email) == kKioskAppUserDomain) { 263 } else if (gaia::ExtractDomainName(email) == kKioskAppUserDomain) {
255 KioskAppLoggedIn(email); 264 KioskAppLoggedIn(email);
256 } else { 265 } else {
257 EnsureUsersLoaded(); 266 EnsureUsersLoaded();
258 267
259 User* user = const_cast<User*>(FindUserInList(email)); 268 User* user = FindUserInListAndModify(email);
260 if (user && user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) { 269 if (user && user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) {
261 PublicAccountUserLoggedIn(user); 270 PublicAccountUserLoggedIn(user);
262 } else if ((user && 271 } else if ((user &&
263 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) || 272 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) ||
264 (!user && 273 (!user &&
265 gaia::ExtractDomainName(email) == 274 gaia::ExtractDomainName(email) ==
266 UserManager::kLocallyManagedUserDomain)) { 275 UserManager::kLocallyManagedUserDomain)) {
267 LocallyManagedUserLoggedIn(email); 276 LocallyManagedUserLoggedIn(email);
268 } else if (browser_restart && email == g_browser_process->local_state()-> 277 } else if (browser_restart && email == g_browser_process->local_state()->
269 GetString(kPublicAccountPendingDataRemoval)) { 278 GetString(kPublicAccountPendingDataRemoval)) {
270 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email)); 279 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(email));
271 } else if (email != owner_email_ && !user && 280 } else if (email != owner_email_ && !user &&
272 (AreEphemeralUsersEnabled() || browser_restart)) { 281 (AreEphemeralUsersEnabled() || browser_restart)) {
273 RegularUserLoggedInAsEphemeral(email); 282 RegularUserLoggedInAsEphemeral(email);
274 } else { 283 } else {
275 RegularUserLoggedIn(email, browser_restart); 284 RegularUserLoggedIn(email, browser_restart);
276 } 285 }
277 286
278 // Initialize the session length limiter and start it only if 287 // Initialize the session length limiter and start it only if
279 // session limit is defined by the policy. 288 // session limit is defined by the policy.
280 session_length_limiter_.reset(new SessionLengthLimiter(NULL, 289 session_length_limiter_.reset(new SessionLengthLimiter(NULL,
281 browser_restart)); 290 browser_restart));
282 } 291 }
283 DCHECK(logged_in_user_); 292 DCHECK(active_user_);
284 logged_in_user_->set_username_hash(username_hash); 293 active_user_->set_is_logged_in(true);
294 active_user_->set_is_active(true);
295 active_user_->set_username_hash(username_hash);
296
297 // Place user who just signed in to the top of the logged in users.
298 logged_in_users_.insert(logged_in_users_.begin(), active_user_);
285 299
286 NotifyOnLogin(); 300 NotifyOnLogin();
287 } 301 }
288 302
303 void UserManagerImpl::SwitchActiveUser(const std::string& email) {
304 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles))
305 return;
306
307 User* user = FindUserAndModify(email);
308 if (!user) {
309 NOTREACHED() << "Switching to a non-existing user";
310 return;
311 }
312 if (user == active_user_) {
313 NOTREACHED() << "Switching to a user who is already active";
314 return;
315 }
316 if (!user->is_logged_in()) {
317 NOTREACHED() << "Switching to a user that is not logged in";
318 return;
319 }
320 if (user->GetType() != User::USER_TYPE_REGULAR) {
321 NOTREACHED() << "Switching to a non-regular user";
322 return;
323 }
324 if (user->username_hash().empty()) {
325 NOTREACHED() << "Switching to a user that doesn't have username_hash set";
326 return;
327 }
328
329 DCHECK(active_user_);
330 active_user_->set_is_active(false);
331 user->set_is_active(true);
332 active_user_ = user;
333
334 // TODO(nkostylev): Notify session_manager on active user change.
335 // http://crbug.com/230857
336 content::NotificationService::current()->Notify(
337 chrome::NOTIFICATION_ACTIVE_USER_CHANGED,
338 content::Source<UserManager>(this),
339 content::Details<const User>(active_user_));
340 }
341
289 void UserManagerImpl::RetailModeUserLoggedIn() { 342 void UserManagerImpl::RetailModeUserLoggedIn() {
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
291 is_current_user_new_ = true; 344 is_current_user_new_ = true;
292 logged_in_user_ = User::CreateRetailModeUser(); 345 active_user_ = User::CreateRetailModeUser();
293 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, 346 user_image_manager_->UserLoggedIn(kRetailModeUserEMail,
294 is_current_user_new_, 347 is_current_user_new_,
295 true); 348 true);
296 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false); 349 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false);
297 } 350 }
298 351
299 void UserManagerImpl::GuestUserLoggedIn() { 352 void UserManagerImpl::GuestUserLoggedIn() {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
301 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false); 354 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false);
302 logged_in_user_ = User::CreateGuestUser(); 355 active_user_ = User::CreateGuestUser();
303 // TODO(nkostylev): Add support for passing guest session cryptohome 356 // TODO(nkostylev): Add support for passing guest session cryptohome
304 // mount point. Legacy (--login-profile) value will be used for now. 357 // mount point. Legacy (--login-profile) value will be used for now.
305 logged_in_user_->SetStubImage(User::kInvalidImageIndex, false); 358 // http://crosbug.com/230859
359 active_user_->SetStubImage(User::kInvalidImageIndex, false);
306 } 360 }
307 361
308 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) { 362 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
310 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain); 364 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain);
311 365
312 WallpaperManager::Get()->SetInitialUserWallpaper(username, false); 366 WallpaperManager::Get()->SetInitialUserWallpaper(username, false);
313 logged_in_user_ = User::CreateKioskAppUser(username); 367 active_user_ = User::CreateKioskAppUser(username);
314 logged_in_user_->SetStubImage(User::kInvalidImageIndex, false); 368 active_user_->SetStubImage(User::kInvalidImageIndex, false);
315 369
316 CommandLine* command_line = CommandLine::ForCurrentProcess(); 370 CommandLine* command_line = CommandLine::ForCurrentProcess();
317 command_line->AppendSwitch(::switches::kForceAppMode); 371 command_line->AppendSwitch(::switches::kForceAppMode);
318 command_line->AppendSwitchASCII(::switches::kAppId, 372 command_line->AppendSwitchASCII(::switches::kAppId,
319 logged_in_user_->GetAccountName(false)); 373 active_user_->GetAccountName(false));
320 } 374 }
321 375
322 void UserManagerImpl::LocallyManagedUserLoggedIn( 376 void UserManagerImpl::LocallyManagedUserLoggedIn(
323 const std::string& username) { 377 const std::string& username) {
324 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn(). 378 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn().
325 379
326 // Remove the user from the user list. 380 // Remove the user from the user list.
327 logged_in_user_ = RemoveRegularOrLocallyManagedUserFromList(username); 381 active_user_ = RemoveRegularOrLocallyManagedUserFromList(username);
328 // If the user was not found on the user list, create a new user. 382 // If the user was not found on the user list, create a new user.
329 if (!logged_in_user_) { 383 if (!active_user_) {
330 is_current_user_new_ = true; 384 is_current_user_new_ = true;
331 logged_in_user_ = User::CreateLocallyManagedUser(username); 385 active_user_ = User::CreateLocallyManagedUser(username);
332 // Leaving OAuth token status at the default state = unknown. 386 // Leaving OAuth token status at the default state = unknown.
333 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); 387 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
334 } else { 388 } else {
335 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), 389 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
336 kLocallyManagedUsersFirstRun); 390 kLocallyManagedUsersFirstRun);
337 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) { 391 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) {
338 is_current_user_new_ = true; 392 is_current_user_new_ = true;
339 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); 393 WallpaperManager::Get()->SetInitialUserWallpaper(username, true);
340 } 394 }
341 } 395 }
342 396
343 // Add the user to the front of the user list. 397 // Add the user to the front of the user list.
344 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), 398 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
345 kRegularUsers); 399 kRegularUsers);
346 prefs_users_update->Insert(0, new base::StringValue(username)); 400 prefs_users_update->Insert(0, new base::StringValue(username));
347 users_.insert(users_.begin(), logged_in_user_); 401 users_.insert(users_.begin(), active_user_);
348 402
349 // Now that user is in the list, save display name. 403 // Now that user is in the list, save display name.
350 if (is_current_user_new_) { 404 if (is_current_user_new_) {
351 SaveUserDisplayName(logged_in_user_->email(), 405 SaveUserDisplayName(active_user_->email(),
352 logged_in_user_->GetDisplayName()); 406 active_user_->GetDisplayName());
353 } 407 }
354 408
355 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true); 409 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true);
356 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 410 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
357 411
358 // Make sure that new data is persisted to Local State. 412 // Make sure that new data is persisted to Local State.
359 g_browser_process->local_state()->CommitPendingWrite(); 413 g_browser_process->local_state()->CommitPendingWrite();
360 } 414 }
361 415
362 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) { 416 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) {
363 is_current_user_new_ = true; 417 is_current_user_new_ = true;
364 logged_in_user_ = user; 418 active_user_ = user;
365 // The UserImageManager chooses a random avatar picture when a user logs in 419 // The UserImageManager chooses a random avatar picture when a user logs in
366 // for the first time. Tell the UserImageManager that this user is not new to 420 // for the first time. Tell the UserImageManager that this user is not new to
367 // prevent the avatar from getting changed. 421 // prevent the avatar from getting changed.
368 user_image_manager_->UserLoggedIn(user->email(), false, true); 422 user_image_manager_->UserLoggedIn(user->email(), false, true);
369 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 423 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
370 } 424 }
371 425
372 void UserManagerImpl::RegularUserLoggedIn(const std::string& email, 426 void UserManagerImpl::RegularUserLoggedIn(const std::string& email,
373 bool browser_restart) { 427 bool browser_restart) {
374 // Remove the user from the user list. 428 // Remove the user from the user list.
375 logged_in_user_ = RemoveRegularOrLocallyManagedUserFromList(email); 429 active_user_ = RemoveRegularOrLocallyManagedUserFromList(email);
376 430
377 // If the user was not found on the user list, create a new user. 431 // If the user was not found on the user list, create a new user.
378 if (!logged_in_user_) { 432 if (!active_user_) {
379 is_current_user_new_ = true; 433 is_current_user_new_ = true;
380 logged_in_user_ = User::CreateRegularUser(email); 434 active_user_ = User::CreateRegularUser(email);
381 logged_in_user_->set_oauth_token_status(LoadUserOAuthStatus(email)); 435 active_user_->set_oauth_token_status(LoadUserOAuthStatus(email));
382 SaveUserDisplayName(logged_in_user_->email(), 436 SaveUserDisplayName(active_user_->email(),
383 UTF8ToUTF16(logged_in_user_->GetAccountName(true))); 437 UTF8ToUTF16(active_user_->GetAccountName(true)));
384 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); 438 WallpaperManager::Get()->SetInitialUserWallpaper(email, true);
385 } 439 }
386 440
387 // Add the user to the front of the user list. 441 // Add the user to the front of the user list.
388 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), 442 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
389 kRegularUsers); 443 kRegularUsers);
390 prefs_users_update->Insert(0, new base::StringValue(email)); 444 prefs_users_update->Insert(0, new base::StringValue(email));
391 users_.insert(users_.begin(), logged_in_user_); 445 users_.insert(users_.begin(), active_user_);
392 446
393 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); 447 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
394 448
395 if (!browser_restart) { 449 if (!browser_restart) {
396 // For GAIA login flow, logged in user wallpaper may not be loaded. 450 // For GAIA login flow, logged in user wallpaper may not be loaded.
397 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 451 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
398 } 452 }
399 453
400 // Make sure that new data is persisted to Local State. 454 // Make sure that new data is persisted to Local State.
401 g_browser_process->local_state()->CommitPendingWrite(); 455 g_browser_process->local_state()->CommitPendingWrite();
402 } 456 }
403 457
404 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) { 458 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) {
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
406 is_current_user_new_ = true; 460 is_current_user_new_ = true;
407 is_current_user_ephemeral_regular_user_ = true; 461 is_current_user_ephemeral_regular_user_ = true;
408 logged_in_user_ = User::CreateRegularUser(email); 462 active_user_ = User::CreateRegularUser(email);
409 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); 463 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
410 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); 464 WallpaperManager::Get()->SetInitialUserWallpaper(email, false);
411 } 465 }
412 466
413 void UserManagerImpl::SessionStarted() { 467 void UserManagerImpl::SessionStarted() {
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
415 session_started_ = true; 469 session_started_ = true;
416 content::NotificationService::current()->Notify( 470 content::NotificationService::current()->Notify(
417 chrome::NOTIFICATION_SESSION_STARTED, 471 chrome::NOTIFICATION_SESSION_STARTED,
418 content::NotificationService::AllSources(), 472 content::Source<UserManager>(this),
419 content::NotificationService::NoDetails()); 473 content::Details<const User>(active_user_));
420 if (is_current_user_new_) { 474 if (is_current_user_new_) {
421 // Make sure that the new user's data is persisted to Local State. 475 // Make sure that the new user's data is persisted to Local State.
422 g_browser_process->local_state()->CommitPendingWrite(); 476 g_browser_process->local_state()->CommitPendingWrite();
423 } 477 }
424 } 478 }
425 479
426 std::string UserManagerImpl::GenerateUniqueLocallyManagedUserId() { 480 std::string UserManagerImpl::GenerateUniqueLocallyManagedUserId() {
427 int counter = g_browser_process->local_state()-> 481 int counter = g_browser_process->local_state()->
428 GetInteger(kLocallyManagedUsersNextId); 482 GetInteger(kLocallyManagedUsersNextId);
429 std::string id; 483 std::string id;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return; 531 return;
478 532
479 // Sanity check: we must not remove single user. This check may seem 533 // Sanity check: we must not remove single user. This check may seem
480 // redundant at a first sight because this single user must be an owner and 534 // redundant at a first sight because this single user must be an owner and
481 // we perform special check later in order not to remove an owner. However 535 // we perform special check later in order not to remove an owner. However
482 // due to non-instant nature of ownership assignment this later check may 536 // due to non-instant nature of ownership assignment this later check may
483 // sometimes fail. See http://crosbug.com/12723 537 // sometimes fail. See http://crosbug.com/12723
484 if (users_.size() < 2) 538 if (users_.size() < 2)
485 return; 539 return;
486 540
487 // Sanity check: do not allow the logged-in user to remove himself. 541 // Sanity check: do not allow any of the the logged in users to be removed.
488 if (logged_in_user_ && logged_in_user_->email() == email) 542 for (UserList::const_iterator it = logged_in_users_.begin();
489 return; 543 it != logged_in_users_.end(); ++it) {
544 if ((*it)->email() == email)
545 return;
546 }
490 547
491 RemoveUserInternal(email, delegate); 548 RemoveUserInternal(email, delegate);
492 } 549 }
493 550
494 void UserManagerImpl::RemoveUserFromList(const std::string& email) { 551 void UserManagerImpl::RemoveUserFromList(const std::string& email) {
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
496 EnsureUsersLoaded(); 553 EnsureUsersLoaded();
497 RemoveNonCryptohomeData(email); 554 RemoveNonCryptohomeData(email);
498 delete RemoveRegularOrLocallyManagedUserFromList(email); 555 delete RemoveRegularOrLocallyManagedUserFromList(email);
499 // Make sure that new data is persisted to Local State. 556 // Make sure that new data is persisted to Local State.
500 g_browser_process->local_state()->CommitPendingWrite(); 557 g_browser_process->local_state()->CommitPendingWrite();
501 } 558 }
502 559
503 bool UserManagerImpl::IsKnownUser(const std::string& email) const { 560 bool UserManagerImpl::IsKnownUser(const std::string& email) const {
504 return FindUser(email) != NULL; 561 return FindUser(email) != NULL;
505 } 562 }
506 563
507 const User* UserManagerImpl::FindUser(const std::string& email) const { 564 const User* UserManagerImpl::FindUser(const std::string& email) const {
508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
509 if (logged_in_user_ && logged_in_user_->email() == email) 566 if (active_user_ && active_user_->email() == email)
510 return logged_in_user_; 567 return active_user_;
511 return FindUserInList(email); 568 return FindUserInList(email);
512 } 569 }
513 570
514 const User* UserManagerImpl::FindLocallyManagedUser( 571 const User* UserManagerImpl::FindLocallyManagedUser(
515 const string16& display_name) const { 572 const string16& display_name) const {
516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
517 const UserList& users = GetUsers(); 574 const UserList& users = GetUsers();
518 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 575 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
519 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && 576 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) &&
520 ((*it)->display_name() == display_name)) { 577 ((*it)->display_name() == display_name)) {
521 return *it; 578 return *it;
522 } 579 }
523 } 580 }
524 return NULL; 581 return NULL;
525 } 582 }
526 583
527 const User* UserManagerImpl::GetLoggedInUser() const { 584 const User* UserManagerImpl::GetLoggedInUser() const {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
529 return logged_in_user_; 586 return active_user_;
530 } 587 }
531 588
532 User* UserManagerImpl::GetLoggedInUser() { 589 User* UserManagerImpl::GetLoggedInUser() {
533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
534 return logged_in_user_; 591 return active_user_;
592 }
593
594 const User* UserManagerImpl::GetActiveUser() const {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596 return active_user_;
597 }
598
599 User* UserManagerImpl::GetActiveUser() {
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
601 return active_user_;
535 } 602 }
536 603
537 void UserManagerImpl::SaveUserOAuthStatus( 604 void UserManagerImpl::SaveUserOAuthStatus(
538 const std::string& username, 605 const std::string& username,
539 User::OAuthTokenStatus oauth_token_status) { 606 User::OAuthTokenStatus oauth_token_status) {
540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
541 608
542 DVLOG(1) << "Saving user OAuth token status in Local State"; 609 DVLOG(1) << "Saving user OAuth token status in Local State";
543 User* user = const_cast<User*>(FindUser(username)); 610 User* user = FindUserAndModify(username);
544 if (user) 611 if (user)
545 user->set_oauth_token_status(oauth_token_status); 612 user->set_oauth_token_status(oauth_token_status);
546 613
547 GetUserFlow(username)->HandleOAuthTokenStatusChange(oauth_token_status); 614 GetUserFlow(username)->HandleOAuthTokenStatusChange(oauth_token_status);
548 615
549 // Do not update local store if data stored or cached outside the user's 616 // Do not update local store if data stored or cached outside the user's
550 // cryptohome is to be treated as ephemeral. 617 // cryptohome is to be treated as ephemeral.
551 if (IsUserNonCryptohomeDataEphemeral(username)) 618 if (IsUserNonCryptohomeDataEphemeral(username))
552 return; 619 return;
553 620
(...skipping 21 matching lines...) Expand all
575 GetUserFlow(username)->HandleOAuthTokenStatusChange(result); 642 GetUserFlow(username)->HandleOAuthTokenStatusChange(result);
576 return result; 643 return result;
577 } 644 }
578 return User::OAUTH_TOKEN_STATUS_UNKNOWN; 645 return User::OAUTH_TOKEN_STATUS_UNKNOWN;
579 } 646 }
580 647
581 void UserManagerImpl::SaveUserDisplayName(const std::string& username, 648 void UserManagerImpl::SaveUserDisplayName(const std::string& username,
582 const string16& display_name) { 649 const string16& display_name) {
583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
584 651
585 User* user = const_cast<User*>(FindUser(username)); 652 User* user = FindUserAndModify(username);
586 if (!user) 653 if (!user)
587 return; // Ignore if there is no such user. 654 return; // Ignore if there is no such user.
588 655
589 user->set_display_name(display_name); 656 user->set_display_name(display_name);
590 657
591 // Do not update local store if data stored or cached outside the user's 658 // Do not update local store if data stored or cached outside the user's
592 // cryptohome is to be treated as ephemeral. 659 // cryptohome is to be treated as ephemeral.
593 if (IsUserNonCryptohomeDataEphemeral(username)) 660 if (IsUserNonCryptohomeDataEphemeral(username))
594 return; 661 return;
595 662
596 PrefService* local_state = g_browser_process->local_state(); 663 PrefService* local_state = g_browser_process->local_state();
597 664
598 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName); 665 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName);
599 display_name_update->SetWithoutPathExpansion( 666 display_name_update->SetWithoutPathExpansion(
600 username, 667 username,
601 new base::StringValue(display_name)); 668 new base::StringValue(display_name));
602 } 669 }
603 670
604 string16 UserManagerImpl::GetUserDisplayName( 671 string16 UserManagerImpl::GetUserDisplayName(
605 const std::string& username) const { 672 const std::string& username) const {
606 const User* user = FindUser(username); 673 const User* user = FindUser(username);
607 return user ? user->display_name() : string16(); 674 return user ? user->display_name() : string16();
608 } 675 }
609 676
610 void UserManagerImpl::SaveUserDisplayEmail(const std::string& username, 677 void UserManagerImpl::SaveUserDisplayEmail(const std::string& username,
611 const std::string& display_email) { 678 const std::string& display_email) {
612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
613 680
614 User* user = const_cast<User*>(FindUser(username)); 681 User* user = FindUserAndModify(username);
615 if (!user) 682 if (!user)
616 return; // Ignore if there is no such user. 683 return; // Ignore if there is no such user.
617 684
618 user->set_display_email(display_email); 685 user->set_display_email(display_email);
619 686
620 // Do not update local store if data stored or cached outside the user's 687 // Do not update local store if data stored or cached outside the user's
621 // cryptohome is to be treated as ephemeral. 688 // cryptohome is to be treated as ephemeral.
622 if (IsUserNonCryptohomeDataEphemeral(username)) 689 if (IsUserNonCryptohomeDataEphemeral(username))
623 return; 690 return;
624 691
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 observed_sync_service_->GetAuthError().state(); 748 observed_sync_service_->GetAuthError().state();
682 if (state != GoogleServiceAuthError::NONE && 749 if (state != GoogleServiceAuthError::NONE &&
683 state != GoogleServiceAuthError::CONNECTION_FAILED && 750 state != GoogleServiceAuthError::CONNECTION_FAILED &&
684 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && 751 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE &&
685 state != GoogleServiceAuthError::REQUEST_CANCELED) { 752 state != GoogleServiceAuthError::REQUEST_CANCELED) {
686 // Invalidate OAuth token to force Gaia sign-in flow. This is needed 753 // Invalidate OAuth token to force Gaia sign-in flow. This is needed
687 // because sign-out/sign-in solution is suggested to the user. 754 // because sign-out/sign-in solution is suggested to the user.
688 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is 755 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is
689 // implemented. 756 // implemented.
690 DVLOG(1) << "Invalidate OAuth token because of a sync error."; 757 DVLOG(1) << "Invalidate OAuth token because of a sync error.";
758 // http://crbug.com/230860
759 // TODO(nkostylev): Figure out whether we want to have observers
760 // for each logged in user.
761 // TODO(nkostyelv): Change observer after active user has changed.
691 SaveUserOAuthStatus( 762 SaveUserOAuthStatus(
692 logged_in_user_->email(), 763 active_user_->email(),
693 User::OAUTH2_TOKEN_STATUS_INVALID); 764 User::OAUTH2_TOKEN_STATUS_INVALID);
694 } 765 }
695 } 766 }
696 767
697 void UserManagerImpl::OnPolicyUpdated(const std::string& account_id) { 768 void UserManagerImpl::OnPolicyUpdated(const std::string& account_id) {
698 UpdatePublicAccountDisplayName(account_id); 769 UpdatePublicAccountDisplayName(account_id);
699 NotifyUserListChanged(); 770 NotifyUserListChanged();
700 } 771 }
701 772
702 void UserManagerImpl::OnDeviceLocalAccountsChanged() { 773 void UserManagerImpl::OnDeviceLocalAccountsChanged() {
(...skipping 19 matching lines...) Expand all
722 } 793 }
723 794
724 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { 795 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const {
725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
726 return IsUserLoggedIn() && 797 return IsUserLoggedIn() &&
727 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); 798 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email());
728 } 799 }
729 800
730 bool UserManagerImpl::CanCurrentUserLock() const { 801 bool UserManagerImpl::CanCurrentUserLock() const {
731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
732 return IsUserLoggedIn() && logged_in_user_->can_lock(); 803 return IsUserLoggedIn() && active_user_->can_lock();
733 } 804 }
734 805
735 bool UserManagerImpl::IsUserLoggedIn() const { 806 bool UserManagerImpl::IsUserLoggedIn() const {
736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
737 return logged_in_user_; 808 return active_user_;
738 } 809 }
739 810
740 bool UserManagerImpl::IsLoggedInAsRegularUser() const { 811 bool UserManagerImpl::IsLoggedInAsRegularUser() const {
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 812 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
742 return IsUserLoggedIn() && 813 return IsUserLoggedIn() &&
743 logged_in_user_->GetType() == User::USER_TYPE_REGULAR; 814 active_user_->GetType() == User::USER_TYPE_REGULAR;
744 } 815 }
745 816
746 bool UserManagerImpl::IsLoggedInAsDemoUser() const { 817 bool UserManagerImpl::IsLoggedInAsDemoUser() const {
747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
748 return IsUserLoggedIn() && 819 return IsUserLoggedIn() &&
749 logged_in_user_->GetType() == User::USER_TYPE_RETAIL_MODE; 820 active_user_->GetType() == User::USER_TYPE_RETAIL_MODE;
750 } 821 }
751 822
752 bool UserManagerImpl::IsLoggedInAsPublicAccount() const { 823 bool UserManagerImpl::IsLoggedInAsPublicAccount() const {
753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
754 return IsUserLoggedIn() && 825 return IsUserLoggedIn() &&
755 logged_in_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; 826 active_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
756 } 827 }
757 828
758 bool UserManagerImpl::IsLoggedInAsGuest() const { 829 bool UserManagerImpl::IsLoggedInAsGuest() const {
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
760 return IsUserLoggedIn() && 831 return IsUserLoggedIn() &&
761 logged_in_user_->GetType() == User::USER_TYPE_GUEST; 832 active_user_->GetType() == User::USER_TYPE_GUEST;
762 } 833 }
763 834
764 bool UserManagerImpl::IsLoggedInAsLocallyManagedUser() const { 835 bool UserManagerImpl::IsLoggedInAsLocallyManagedUser() const {
765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
766 return IsUserLoggedIn() && 837 return IsUserLoggedIn() &&
767 logged_in_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED; 838 active_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
768 } 839 }
769 840
770 bool UserManagerImpl::IsLoggedInAsKioskApp() const { 841 bool UserManagerImpl::IsLoggedInAsKioskApp() const {
771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
772 return IsUserLoggedIn() && 843 return IsUserLoggedIn() &&
773 logged_in_user_->GetType() == User::USER_TYPE_KIOSK_APP; 844 active_user_->GetType() == User::USER_TYPE_KIOSK_APP;
774 } 845 }
775 846
776 bool UserManagerImpl::IsLoggedInAsStub() const { 847 bool UserManagerImpl::IsLoggedInAsStub() const {
777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
778 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser; 849 return IsUserLoggedIn() && active_user_->email() == kStubUser;
779 } 850 }
780 851
781 bool UserManagerImpl::IsSessionStarted() const { 852 bool UserManagerImpl::IsSessionStarted() const {
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
783 return session_started_; 854 return session_started_;
784 } 855 }
785 856
786 UserManager::MergeSessionState UserManagerImpl::GetMergeSessionState() const { 857 UserManager::MergeSessionState UserManagerImpl::GetMergeSessionState() const {
787 return merge_session_state_; 858 return merge_session_state_;
788 } 859 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts, 1040 cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts,
970 this); 1041 this);
971 } 1042 }
972 1043
973 bool UserManagerImpl::AreEphemeralUsersEnabled() const { 1044 bool UserManagerImpl::AreEphemeralUsersEnabled() const {
974 return ephemeral_users_enabled_ && 1045 return ephemeral_users_enabled_ &&
975 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || 1046 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ||
976 !owner_email_.empty()); 1047 !owner_email_.empty());
977 } 1048 }
978 1049
1050 UserList& UserManagerImpl::GetUsersAndModify() {
1051 EnsureUsersLoaded();
1052 return users_;
1053 }
1054
1055 User* UserManagerImpl::FindUserAndModify(const std::string& email) {
1056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1057 if (active_user_ && active_user_->email() == email)
1058 return active_user_;
1059 return FindUserInListAndModify(email);
1060 }
1061
979 const User* UserManagerImpl::FindUserInList(const std::string& email) const { 1062 const User* UserManagerImpl::FindUserInList(const std::string& email) const {
980 const UserList& users = GetUsers(); 1063 const UserList& users = GetUsers();
981 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 1064 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
982 if ((*it)->email() == email) 1065 if ((*it)->email() == email)
983 return *it; 1066 return *it;
984 } 1067 }
985 return NULL; 1068 return NULL;
986 } 1069 }
987 1070
1071 User* UserManagerImpl::FindUserInListAndModify(const std::string& email) {
1072 UserList& users = GetUsersAndModify();
1073 for (UserList::iterator it = users.begin(); it != users.end(); ++it) {
1074 if ((*it)->email() == email)
1075 return *it;
1076 }
1077 return NULL;
1078 }
1079
988 void UserManagerImpl::NotifyOnLogin() { 1080 void UserManagerImpl::NotifyOnLogin() {
989 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1081 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
990 content::NotificationService::current()->Notify( 1082 content::NotificationService::current()->Notify(
991 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 1083 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
992 content::Source<UserManager>(this), 1084 content::Source<UserManager>(this),
993 content::Details<const User>(logged_in_user_)); 1085 content::Details<const User>(active_user_));
994 1086
995 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 1087 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
996 1088
997 // Indicate to DeviceSettingsService that the owner key may have become 1089 // Indicate to DeviceSettingsService that the owner key may have become
998 // available. 1090 // available.
999 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); 1091 DeviceSettingsService::Get()->SetUsername(active_user_->email());
1000 } 1092 }
1001 1093
1002 void UserManagerImpl::UpdateOwnership( 1094 void UserManagerImpl::UpdateOwnership(
1003 DeviceSettingsService::OwnershipStatus status, 1095 DeviceSettingsService::OwnershipStatus status,
1004 bool is_owner) { 1096 bool is_owner) {
1005 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); 1097 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1006 1098
1007 SetCurrentUserIsOwner(is_owner); 1099 SetCurrentUserIsOwner(is_owner);
1008 } 1100 }
1009 1101
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 } 1145 }
1054 } 1146 }
1055 return user; 1147 return user;
1056 } 1148 }
1057 1149
1058 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( 1150 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts(
1059 const base::ListValue& public_accounts) { 1151 const base::ListValue& public_accounts) {
1060 PrefService* local_state = g_browser_process->local_state(); 1152 PrefService* local_state = g_browser_process->local_state();
1061 1153
1062 // Determine the currently logged-in user's email. 1154 // Determine the currently logged-in user's email.
1063 std::string logged_in_user_email; 1155 std::string active_user_email;
1064 if (IsUserLoggedIn()) 1156 if (IsUserLoggedIn())
1065 logged_in_user_email = GetLoggedInUser()->email(); 1157 active_user_email = GetLoggedInUser()->email();
1066 1158
1067 // If there is a public account whose data is pending removal and the user is 1159 // If there is a public account whose data is pending removal and the user is
1068 // not currently logged in with that account, take this opportunity to remove 1160 // not currently logged in with that account, take this opportunity to remove
1069 // the data. 1161 // the data.
1070 std::string public_account_pending_data_removal = 1162 std::string public_account_pending_data_removal =
1071 local_state->GetString(kPublicAccountPendingDataRemoval); 1163 local_state->GetString(kPublicAccountPendingDataRemoval);
1072 if (!public_account_pending_data_removal.empty() && 1164 if (!public_account_pending_data_removal.empty() &&
1073 public_account_pending_data_removal != logged_in_user_email) { 1165 public_account_pending_data_removal != active_user_email) {
1074 RemoveNonCryptohomeData(public_account_pending_data_removal); 1166 RemoveNonCryptohomeData(public_account_pending_data_removal);
1075 local_state->ClearPref(kPublicAccountPendingDataRemoval); 1167 local_state->ClearPref(kPublicAccountPendingDataRemoval);
1076 } 1168 }
1077 1169
1078 // Split the current user list public accounts and regular users. 1170 // Split the current user list public accounts and regular users.
1079 std::vector<std::string> old_public_accounts; 1171 std::vector<std::string> old_public_accounts;
1080 std::set<std::string> regular_users; 1172 std::set<std::string> regular_users;
1081 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { 1173 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) {
1082 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) 1174 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT)
1083 old_public_accounts.push_back((*it)->email()); 1175 old_public_accounts.push_back((*it)->email());
1084 else 1176 else
1085 regular_users.insert((*it)->email()); 1177 regular_users.insert((*it)->email());
1086 } 1178 }
1087 1179
1088 // Get the new list of public accounts from policy. 1180 // Get the new list of public accounts from policy.
1089 std::vector<std::string> new_public_accounts; 1181 std::vector<std::string> new_public_accounts;
1090 std::set<std::string> new_public_accounts_set; 1182 std::set<std::string> new_public_accounts_set;
1091 if (!ParseUserList(public_accounts, regular_users, logged_in_user_email, 1183 if (!ParseUserList(public_accounts, regular_users, active_user_email,
1092 &new_public_accounts, &new_public_accounts_set) && 1184 &new_public_accounts, &new_public_accounts_set) &&
1093 IsLoggedInAsPublicAccount()) { 1185 IsLoggedInAsPublicAccount()) {
1094 // If the user is currently logged into a public account that has been 1186 // If the user is currently logged into a public account that has been
1095 // removed from the list, mark the account's data as pending removal after 1187 // removed from the list, mark the account's data as pending removal after
1096 // logout. 1188 // logout.
1097 local_state->SetString(kPublicAccountPendingDataRemoval, 1189 local_state->SetString(kPublicAccountPendingDataRemoval,
1098 logged_in_user_email); 1190 active_user_email);
1099 } 1191 }
1100 1192
1101 // Persist the new list of public accounts in a pref. 1193 // Persist the new list of public accounts in a pref.
1102 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); 1194 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts);
1103 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); 1195 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy());
1104 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); 1196 prefs_public_accounts_update->Swap(prefs_public_accounts.get());
1105 1197
1106 // If the list of public accounts has not changed, return. 1198 // If the list of public accounts has not changed, return.
1107 if (new_public_accounts.size() == old_public_accounts.size()) { 1199 if (new_public_accounts.size() == old_public_accounts.size()) {
1108 bool changed = false; 1200 bool changed = false;
(...skipping 15 matching lines...) Expand all
1124 it = users_.erase(it); 1216 it = users_.erase(it);
1125 } else { 1217 } else {
1126 ++it; 1218 ++it;
1127 } 1219 }
1128 } 1220 }
1129 1221
1130 // Add the new public accounts to the front of the user list. 1222 // Add the new public accounts to the front of the user list.
1131 for (std::vector<std::string>::const_reverse_iterator 1223 for (std::vector<std::string>::const_reverse_iterator
1132 it = new_public_accounts.rbegin(); 1224 it = new_public_accounts.rbegin();
1133 it != new_public_accounts.rend(); ++it) { 1225 it != new_public_accounts.rend(); ++it) {
1134 if (IsLoggedInAsPublicAccount() && *it == logged_in_user_email) 1226 if (IsLoggedInAsPublicAccount() && *it == active_user_email)
1135 users_.insert(users_.begin(), GetLoggedInUser()); 1227 users_.insert(users_.begin(), GetLoggedInUser());
1136 else 1228 else
1137 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); 1229 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it));
1138 UpdatePublicAccountDisplayName(*it); 1230 UpdatePublicAccountDisplayName(*it);
1139 } 1231 }
1140 1232
1141 user_image_manager_->LoadUserImages( 1233 user_image_manager_->LoadUserImages(
1142 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); 1234 UserList(users_.begin(), users_.begin() + new_public_accounts.size()));
1143 1235
1144 return true; 1236 return true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 content::NotificationService::NoDetails()); 1386 content::NotificationService::NoDetails());
1295 } 1387 }
1296 1388
1297 void UserManagerImpl::NotifyMergeSessionStateChanged() { 1389 void UserManagerImpl::NotifyMergeSessionStateChanged() {
1298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1299 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, 1391 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_,
1300 MergeSessionStateChanged(merge_session_state_)); 1392 MergeSessionStateChanged(merge_session_state_));
1301 } 1393 }
1302 1394
1303 } // namespace chromeos 1395 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698