Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 = const_cast<User*>(FindUserInList(email)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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_); | |
|
Dmitry Polukhin
2013/04/11 13:34:15
Does order of user matter?
Nikita (slow)
2013/04/12 15:41:25
Discussed, for now using same ordering logic as fo
| |
| 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 = const_cast<User*>(FindUser(email)); | |
|
Dmitry Polukhin
2013/04/11 13:34:15
I would add another function that returns non-cons
Nikita (slow)
2013/04/12 15:41:25
Done.
| |
| 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 content::NotificationService::current()->Notify( | |
| 336 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, | |
| 337 content::Source<UserManager>(this), | |
| 338 content::Details<const User>(active_user_)); | |
| 339 } | |
| 340 | |
| 289 void UserManagerImpl::RetailModeUserLoggedIn() { | 341 void UserManagerImpl::RetailModeUserLoggedIn() { |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 291 is_current_user_new_ = true; | 343 is_current_user_new_ = true; |
| 292 logged_in_user_ = User::CreateRetailModeUser(); | 344 active_user_ = User::CreateRetailModeUser(); |
| 293 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, | 345 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, |
| 294 is_current_user_new_, | 346 is_current_user_new_, |
| 295 true); | 347 true); |
| 296 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false); | 348 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false); |
| 297 } | 349 } |
| 298 | 350 |
| 299 void UserManagerImpl::GuestUserLoggedIn() { | 351 void UserManagerImpl::GuestUserLoggedIn() { |
| 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 301 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false); | 353 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUserEMail, false); |
| 302 logged_in_user_ = User::CreateGuestUser(); | 354 active_user_ = User::CreateGuestUser(); |
| 303 // TODO(nkostylev): Add support for passing guest session cryptohome | 355 // TODO(nkostylev): Add support for passing guest session cryptohome |
| 304 // mount point. Legacy (--login-profile) value will be used for now. | 356 // mount point. Legacy (--login-profile) value will be used for now. |
| 305 logged_in_user_->SetStubImage(User::kInvalidImageIndex, false); | 357 active_user_->SetStubImage(User::kInvalidImageIndex, false); |
| 306 } | 358 } |
| 307 | 359 |
| 308 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) { | 360 void UserManagerImpl::KioskAppLoggedIn(const std::string& username) { |
| 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 310 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain); | 362 DCHECK_EQ(gaia::ExtractDomainName(username), kKioskAppUserDomain); |
| 311 | 363 |
| 312 WallpaperManager::Get()->SetInitialUserWallpaper(username, false); | 364 WallpaperManager::Get()->SetInitialUserWallpaper(username, false); |
| 313 logged_in_user_ = User::CreateKioskAppUser(username); | 365 active_user_ = User::CreateKioskAppUser(username); |
| 314 logged_in_user_->SetStubImage(User::kInvalidImageIndex, false); | 366 active_user_->SetStubImage(User::kInvalidImageIndex, false); |
| 315 | 367 |
| 316 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 368 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 317 command_line->AppendSwitch(::switches::kForceAppMode); | 369 command_line->AppendSwitch(::switches::kForceAppMode); |
| 318 command_line->AppendSwitchASCII(::switches::kAppId, | 370 command_line->AppendSwitchASCII(::switches::kAppId, |
| 319 logged_in_user_->GetAccountName(false)); | 371 active_user_->GetAccountName(false)); |
| 320 } | 372 } |
| 321 | 373 |
| 322 void UserManagerImpl::LocallyManagedUserLoggedIn( | 374 void UserManagerImpl::LocallyManagedUserLoggedIn( |
| 323 const std::string& username) { | 375 const std::string& username) { |
| 324 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn(). | 376 // TODO(nkostylev): Refactor, share code with RegularUserLoggedIn(). |
| 325 | 377 |
| 326 // Remove the user from the user list. | 378 // Remove the user from the user list. |
| 327 logged_in_user_ = RemoveRegularOrLocallyManagedUserFromList(username); | 379 active_user_ = RemoveRegularOrLocallyManagedUserFromList(username); |
| 328 // If the user was not found on the user list, create a new user. | 380 // If the user was not found on the user list, create a new user. |
| 329 if (!logged_in_user_) { | 381 if (!active_user_) { |
| 330 is_current_user_new_ = true; | 382 is_current_user_new_ = true; |
| 331 logged_in_user_ = User::CreateLocallyManagedUser(username); | 383 active_user_ = User::CreateLocallyManagedUser(username); |
| 332 // Leaving OAuth token status at the default state = unknown. | 384 // Leaving OAuth token status at the default state = unknown. |
| 333 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); | 385 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); |
| 334 } else { | 386 } else { |
| 335 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), | 387 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), |
| 336 kLocallyManagedUsersFirstRun); | 388 kLocallyManagedUsersFirstRun); |
| 337 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) { | 389 if (prefs_new_users_update->Remove(base::StringValue(username), NULL)) { |
| 338 is_current_user_new_ = true; | 390 is_current_user_new_ = true; |
| 339 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); | 391 WallpaperManager::Get()->SetInitialUserWallpaper(username, true); |
| 340 } | 392 } |
| 341 } | 393 } |
| 342 | 394 |
| 343 // Add the user to the front of the user list. | 395 // Add the user to the front of the user list. |
| 344 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), | 396 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 345 kRegularUsers); | 397 kRegularUsers); |
| 346 prefs_users_update->Insert(0, new base::StringValue(username)); | 398 prefs_users_update->Insert(0, new base::StringValue(username)); |
| 347 users_.insert(users_.begin(), logged_in_user_); | 399 users_.insert(users_.begin(), active_user_); |
| 348 | 400 |
| 349 // Now that user is in the list, save display name. | 401 // Now that user is in the list, save display name. |
| 350 if (is_current_user_new_) { | 402 if (is_current_user_new_) { |
| 351 SaveUserDisplayName(logged_in_user_->email(), | 403 SaveUserDisplayName(active_user_->email(), |
| 352 logged_in_user_->GetDisplayName()); | 404 active_user_->GetDisplayName()); |
| 353 } | 405 } |
| 354 | 406 |
| 355 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true); | 407 user_image_manager_->UserLoggedIn(username, is_current_user_new_, true); |
| 356 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); | 408 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); |
| 357 | 409 |
| 358 // Make sure that new data is persisted to Local State. | 410 // Make sure that new data is persisted to Local State. |
| 359 g_browser_process->local_state()->CommitPendingWrite(); | 411 g_browser_process->local_state()->CommitPendingWrite(); |
| 360 } | 412 } |
| 361 | 413 |
| 362 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) { | 414 void UserManagerImpl::PublicAccountUserLoggedIn(User* user) { |
| 363 is_current_user_new_ = true; | 415 is_current_user_new_ = true; |
| 364 logged_in_user_ = user; | 416 active_user_ = user; |
| 365 // The UserImageManager chooses a random avatar picture when a user logs in | 417 // 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 | 418 // for the first time. Tell the UserImageManager that this user is not new to |
| 367 // prevent the avatar from getting changed. | 419 // prevent the avatar from getting changed. |
| 368 user_image_manager_->UserLoggedIn(user->email(), false, true); | 420 user_image_manager_->UserLoggedIn(user->email(), false, true); |
| 369 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); | 421 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); |
| 370 } | 422 } |
| 371 | 423 |
| 372 void UserManagerImpl::RegularUserLoggedIn(const std::string& email, | 424 void UserManagerImpl::RegularUserLoggedIn(const std::string& email, |
| 373 bool browser_restart) { | 425 bool browser_restart) { |
| 374 // Remove the user from the user list. | 426 // Remove the user from the user list. |
| 375 logged_in_user_ = RemoveRegularOrLocallyManagedUserFromList(email); | 427 active_user_ = RemoveRegularOrLocallyManagedUserFromList(email); |
| 376 | 428 |
| 377 // If the user was not found on the user list, create a new user. | 429 // If the user was not found on the user list, create a new user. |
| 378 if (!logged_in_user_) { | 430 if (!active_user_) { |
| 379 is_current_user_new_ = true; | 431 is_current_user_new_ = true; |
| 380 logged_in_user_ = User::CreateRegularUser(email); | 432 active_user_ = User::CreateRegularUser(email); |
| 381 logged_in_user_->set_oauth_token_status(LoadUserOAuthStatus(email)); | 433 active_user_->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 382 SaveUserDisplayName(logged_in_user_->email(), | 434 SaveUserDisplayName(active_user_->email(), |
| 383 UTF8ToUTF16(logged_in_user_->GetAccountName(true))); | 435 UTF8ToUTF16(active_user_->GetAccountName(true))); |
| 384 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); | 436 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); |
| 385 } | 437 } |
| 386 | 438 |
| 387 // Add the user to the front of the user list. | 439 // Add the user to the front of the user list. |
| 388 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), | 440 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 389 kRegularUsers); | 441 kRegularUsers); |
| 390 prefs_users_update->Insert(0, new base::StringValue(email)); | 442 prefs_users_update->Insert(0, new base::StringValue(email)); |
| 391 users_.insert(users_.begin(), logged_in_user_); | 443 users_.insert(users_.begin(), active_user_); |
| 392 | 444 |
| 393 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); | 445 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); |
| 394 | 446 |
| 395 if (!browser_restart) { | 447 if (!browser_restart) { |
| 396 // For GAIA login flow, logged in user wallpaper may not be loaded. | 448 // For GAIA login flow, logged in user wallpaper may not be loaded. |
| 397 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); | 449 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); |
| 398 } | 450 } |
| 399 | 451 |
| 400 // Make sure that new data is persisted to Local State. | 452 // Make sure that new data is persisted to Local State. |
| 401 g_browser_process->local_state()->CommitPendingWrite(); | 453 g_browser_process->local_state()->CommitPendingWrite(); |
| 402 } | 454 } |
| 403 | 455 |
| 404 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) { | 456 void UserManagerImpl::RegularUserLoggedInAsEphemeral(const std::string& email) { |
| 405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 406 is_current_user_new_ = true; | 458 is_current_user_new_ = true; |
| 407 is_current_user_ephemeral_regular_user_ = true; | 459 is_current_user_ephemeral_regular_user_ = true; |
| 408 logged_in_user_ = User::CreateRegularUser(email); | 460 active_user_ = User::CreateRegularUser(email); |
| 409 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); | 461 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); |
| 410 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); | 462 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); |
| 411 } | 463 } |
| 412 | 464 |
| 413 void UserManagerImpl::SessionStarted() { | 465 void UserManagerImpl::SessionStarted() { |
| 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 415 session_started_ = true; | 467 session_started_ = true; |
| 416 content::NotificationService::current()->Notify( | 468 content::NotificationService::current()->Notify( |
| 417 chrome::NOTIFICATION_SESSION_STARTED, | 469 chrome::NOTIFICATION_SESSION_STARTED, |
| 418 content::NotificationService::AllSources(), | 470 content::Source<UserManager>(this), |
| 419 content::NotificationService::NoDetails()); | 471 content::Details<const User>(active_user_)); |
| 420 if (is_current_user_new_) { | 472 if (is_current_user_new_) { |
| 421 // Make sure that the new user's data is persisted to Local State. | 473 // Make sure that the new user's data is persisted to Local State. |
| 422 g_browser_process->local_state()->CommitPendingWrite(); | 474 g_browser_process->local_state()->CommitPendingWrite(); |
| 423 } | 475 } |
| 424 } | 476 } |
| 425 | 477 |
| 426 std::string UserManagerImpl::GenerateUniqueLocallyManagedUserId() { | 478 std::string UserManagerImpl::GenerateUniqueLocallyManagedUserId() { |
| 427 int counter = g_browser_process->local_state()-> | 479 int counter = g_browser_process->local_state()-> |
| 428 GetInteger(kLocallyManagedUsersNextId); | 480 GetInteger(kLocallyManagedUsersNextId); |
| 429 std::string id; | 481 std::string id; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 return; | 529 return; |
| 478 | 530 |
| 479 // Sanity check: we must not remove single user. This check may seem | 531 // 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 | 532 // 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 | 533 // 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 | 534 // due to non-instant nature of ownership assignment this later check may |
| 483 // sometimes fail. See http://crosbug.com/12723 | 535 // sometimes fail. See http://crosbug.com/12723 |
| 484 if (users_.size() < 2) | 536 if (users_.size() < 2) |
| 485 return; | 537 return; |
| 486 | 538 |
| 487 // Sanity check: do not allow the logged-in user to remove himself. | 539 // 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) | 540 for (UserList::const_iterator it = logged_in_users_.begin(); |
| 489 return; | 541 it != logged_in_users_.end(); ++it) { |
| 542 if ((*it)->email() == email) | |
| 543 return; | |
|
Dmitry Polukhin
2013/04/11 13:34:15
Do you know how it will look from UI point of view
Nikita (slow)
2013/04/12 15:41:25
Yes, nothing will happen.
User will click on [Remo
| |
| 544 } | |
| 490 | 545 |
| 491 RemoveUserInternal(email, delegate); | 546 RemoveUserInternal(email, delegate); |
| 492 } | 547 } |
| 493 | 548 |
| 494 void UserManagerImpl::RemoveUserFromList(const std::string& email) { | 549 void UserManagerImpl::RemoveUserFromList(const std::string& email) { |
| 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 496 EnsureUsersLoaded(); | 551 EnsureUsersLoaded(); |
| 497 RemoveNonCryptohomeData(email); | 552 RemoveNonCryptohomeData(email); |
| 498 delete RemoveRegularOrLocallyManagedUserFromList(email); | 553 delete RemoveRegularOrLocallyManagedUserFromList(email); |
| 499 // Make sure that new data is persisted to Local State. | 554 // Make sure that new data is persisted to Local State. |
| 500 g_browser_process->local_state()->CommitPendingWrite(); | 555 g_browser_process->local_state()->CommitPendingWrite(); |
| 501 } | 556 } |
| 502 | 557 |
| 503 bool UserManagerImpl::IsKnownUser(const std::string& email) const { | 558 bool UserManagerImpl::IsKnownUser(const std::string& email) const { |
| 504 return FindUser(email) != NULL; | 559 return FindUser(email) != NULL; |
| 505 } | 560 } |
| 506 | 561 |
| 507 const User* UserManagerImpl::FindUser(const std::string& email) const { | 562 const User* UserManagerImpl::FindUser(const std::string& email) const { |
| 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 509 if (logged_in_user_ && logged_in_user_->email() == email) | 564 if (active_user_ && active_user_->email() == email) |
| 510 return logged_in_user_; | 565 return active_user_; |
| 511 return FindUserInList(email); | 566 return FindUserInList(email); |
| 512 } | 567 } |
| 513 | 568 |
| 514 const User* UserManagerImpl::FindLocallyManagedUser( | 569 const User* UserManagerImpl::FindLocallyManagedUser( |
| 515 const string16& display_name) const { | 570 const string16& display_name) const { |
| 516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 517 const UserList& users = GetUsers(); | 572 const UserList& users = GetUsers(); |
| 518 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 573 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 519 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 574 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
| 520 ((*it)->display_name() == display_name)) { | 575 ((*it)->display_name() == display_name)) { |
| 521 return *it; | 576 return *it; |
| 522 } | 577 } |
| 523 } | 578 } |
| 524 return NULL; | 579 return NULL; |
| 525 } | 580 } |
| 526 | 581 |
| 527 const User* UserManagerImpl::GetLoggedInUser() const { | 582 const User* UserManagerImpl::GetLoggedInUser() const { |
| 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 529 return logged_in_user_; | 584 return active_user_; |
| 530 } | 585 } |
| 531 | 586 |
| 532 User* UserManagerImpl::GetLoggedInUser() { | 587 User* UserManagerImpl::GetLoggedInUser() { |
| 533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 534 return logged_in_user_; | 589 return active_user_; |
| 590 } | |
| 591 | |
| 592 const User* UserManagerImpl::GetActiveUser() const { | |
| 593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 594 return active_user_; | |
| 595 } | |
| 596 | |
| 597 User* UserManagerImpl::GetActiveUser() { | |
| 598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 599 return active_user_; | |
| 535 } | 600 } |
| 536 | 601 |
| 537 void UserManagerImpl::SaveUserOAuthStatus( | 602 void UserManagerImpl::SaveUserOAuthStatus( |
| 538 const std::string& username, | 603 const std::string& username, |
| 539 User::OAuthTokenStatus oauth_token_status) { | 604 User::OAuthTokenStatus oauth_token_status) { |
| 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 541 | 606 |
| 542 DVLOG(1) << "Saving user OAuth token status in Local State"; | 607 DVLOG(1) << "Saving user OAuth token status in Local State"; |
| 543 User* user = const_cast<User*>(FindUser(username)); | 608 User* user = const_cast<User*>(FindUser(username)); |
| 544 if (user) | 609 if (user) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 observed_sync_service_->GetAuthError().state(); | 746 observed_sync_service_->GetAuthError().state(); |
| 682 if (state != GoogleServiceAuthError::NONE && | 747 if (state != GoogleServiceAuthError::NONE && |
| 683 state != GoogleServiceAuthError::CONNECTION_FAILED && | 748 state != GoogleServiceAuthError::CONNECTION_FAILED && |
| 684 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && | 749 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
| 685 state != GoogleServiceAuthError::REQUEST_CANCELED) { | 750 state != GoogleServiceAuthError::REQUEST_CANCELED) { |
| 686 // Invalidate OAuth token to force Gaia sign-in flow. This is needed | 751 // Invalidate OAuth token to force Gaia sign-in flow. This is needed |
| 687 // because sign-out/sign-in solution is suggested to the user. | 752 // because sign-out/sign-in solution is suggested to the user. |
| 688 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is | 753 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is |
| 689 // implemented. | 754 // implemented. |
| 690 DVLOG(1) << "Invalidate OAuth token because of a sync error."; | 755 DVLOG(1) << "Invalidate OAuth token because of a sync error."; |
| 756 // TODO(nkostylev): Figure out whether we want to have observers | |
| 757 // for each logged in user. | |
| 758 // TODO(nkostyelv): Change observer after active user has changed. | |
| 691 SaveUserOAuthStatus( | 759 SaveUserOAuthStatus( |
| 692 logged_in_user_->email(), | 760 active_user_->email(), |
| 693 User::OAUTH2_TOKEN_STATUS_INVALID); | 761 User::OAUTH2_TOKEN_STATUS_INVALID); |
| 694 } | 762 } |
| 695 } | 763 } |
| 696 | 764 |
| 697 void UserManagerImpl::OnPolicyUpdated(const std::string& account_id) { | 765 void UserManagerImpl::OnPolicyUpdated(const std::string& account_id) { |
| 698 UpdatePublicAccountDisplayName(account_id); | 766 UpdatePublicAccountDisplayName(account_id); |
| 699 NotifyUserListChanged(); | 767 NotifyUserListChanged(); |
| 700 } | 768 } |
| 701 | 769 |
| 702 void UserManagerImpl::OnDeviceLocalAccountsChanged() { | 770 void UserManagerImpl::OnDeviceLocalAccountsChanged() { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 722 } | 790 } |
| 723 | 791 |
| 724 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { | 792 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| 725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 726 return IsUserLoggedIn() && | 794 return IsUserLoggedIn() && |
| 727 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); | 795 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); |
| 728 } | 796 } |
| 729 | 797 |
| 730 bool UserManagerImpl::CanCurrentUserLock() const { | 798 bool UserManagerImpl::CanCurrentUserLock() const { |
| 731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 732 return IsUserLoggedIn() && logged_in_user_->can_lock(); | 800 return IsUserLoggedIn() && active_user_->can_lock(); |
| 733 } | 801 } |
| 734 | 802 |
| 735 bool UserManagerImpl::IsUserLoggedIn() const { | 803 bool UserManagerImpl::IsUserLoggedIn() const { |
| 736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 804 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 737 return logged_in_user_; | 805 return active_user_; |
| 738 } | 806 } |
| 739 | 807 |
| 740 bool UserManagerImpl::IsLoggedInAsRegularUser() const { | 808 bool UserManagerImpl::IsLoggedInAsRegularUser() const { |
| 741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 742 return IsUserLoggedIn() && | 810 return IsUserLoggedIn() && |
| 743 logged_in_user_->GetType() == User::USER_TYPE_REGULAR; | 811 active_user_->GetType() == User::USER_TYPE_REGULAR; |
| 744 } | 812 } |
| 745 | 813 |
| 746 bool UserManagerImpl::IsLoggedInAsDemoUser() const { | 814 bool UserManagerImpl::IsLoggedInAsDemoUser() const { |
| 747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 748 return IsUserLoggedIn() && | 816 return IsUserLoggedIn() && |
| 749 logged_in_user_->GetType() == User::USER_TYPE_RETAIL_MODE; | 817 active_user_->GetType() == User::USER_TYPE_RETAIL_MODE; |
| 750 } | 818 } |
| 751 | 819 |
| 752 bool UserManagerImpl::IsLoggedInAsPublicAccount() const { | 820 bool UserManagerImpl::IsLoggedInAsPublicAccount() const { |
| 753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 821 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 754 return IsUserLoggedIn() && | 822 return IsUserLoggedIn() && |
| 755 logged_in_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; | 823 active_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; |
| 756 } | 824 } |
| 757 | 825 |
| 758 bool UserManagerImpl::IsLoggedInAsGuest() const { | 826 bool UserManagerImpl::IsLoggedInAsGuest() const { |
| 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 760 return IsUserLoggedIn() && | 828 return IsUserLoggedIn() && |
| 761 logged_in_user_->GetType() == User::USER_TYPE_GUEST; | 829 active_user_->GetType() == User::USER_TYPE_GUEST; |
| 762 } | 830 } |
| 763 | 831 |
| 764 bool UserManagerImpl::IsLoggedInAsLocallyManagedUser() const { | 832 bool UserManagerImpl::IsLoggedInAsLocallyManagedUser() const { |
| 765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 766 return IsUserLoggedIn() && | 834 return IsUserLoggedIn() && |
| 767 logged_in_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED; | 835 active_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED; |
| 768 } | 836 } |
| 769 | 837 |
| 770 bool UserManagerImpl::IsLoggedInAsKioskApp() const { | 838 bool UserManagerImpl::IsLoggedInAsKioskApp() const { |
| 771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 772 return IsUserLoggedIn() && | 840 return IsUserLoggedIn() && |
| 773 logged_in_user_->GetType() == User::USER_TYPE_KIOSK_APP; | 841 active_user_->GetType() == User::USER_TYPE_KIOSK_APP; |
| 774 } | 842 } |
| 775 | 843 |
| 776 bool UserManagerImpl::IsLoggedInAsStub() const { | 844 bool UserManagerImpl::IsLoggedInAsStub() const { |
| 777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 778 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser; | 846 return IsUserLoggedIn() && active_user_->email() == kStubUser; |
| 779 } | 847 } |
| 780 | 848 |
| 781 bool UserManagerImpl::IsSessionStarted() const { | 849 bool UserManagerImpl::IsSessionStarted() const { |
| 782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 783 return session_started_; | 851 return session_started_; |
| 784 } | 852 } |
| 785 | 853 |
| 786 UserManager::MergeSessionState UserManagerImpl::GetMergeSessionState() const { | 854 UserManager::MergeSessionState UserManagerImpl::GetMergeSessionState() const { |
| 787 return merge_session_state_; | 855 return merge_session_state_; |
| 788 } | 856 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 return *it; | 1051 return *it; |
| 984 } | 1052 } |
| 985 return NULL; | 1053 return NULL; |
| 986 } | 1054 } |
| 987 | 1055 |
| 988 void UserManagerImpl::NotifyOnLogin() { | 1056 void UserManagerImpl::NotifyOnLogin() { |
| 989 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1057 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 990 content::NotificationService::current()->Notify( | 1058 content::NotificationService::current()->Notify( |
| 991 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 1059 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 992 content::Source<UserManager>(this), | 1060 content::Source<UserManager>(this), |
| 993 content::Details<const User>(logged_in_user_)); | 1061 content::Details<const User>(active_user_)); |
| 994 | 1062 |
| 995 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); | 1063 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); |
| 996 | 1064 |
| 997 // Indicate to DeviceSettingsService that the owner key may have become | 1065 // Indicate to DeviceSettingsService that the owner key may have become |
| 998 // available. | 1066 // available. |
| 999 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); | 1067 DeviceSettingsService::Get()->SetUsername(active_user_->email()); |
| 1000 } | 1068 } |
| 1001 | 1069 |
| 1002 void UserManagerImpl::UpdateOwnership( | 1070 void UserManagerImpl::UpdateOwnership( |
| 1003 DeviceSettingsService::OwnershipStatus status, | 1071 DeviceSettingsService::OwnershipStatus status, |
| 1004 bool is_owner) { | 1072 bool is_owner) { |
| 1005 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); | 1073 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); |
| 1006 | 1074 |
| 1007 SetCurrentUserIsOwner(is_owner); | 1075 SetCurrentUserIsOwner(is_owner); |
| 1008 } | 1076 } |
| 1009 | 1077 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1053 } | 1121 } |
| 1054 } | 1122 } |
| 1055 return user; | 1123 return user; |
| 1056 } | 1124 } |
| 1057 | 1125 |
| 1058 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( | 1126 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( |
| 1059 const base::ListValue& public_accounts) { | 1127 const base::ListValue& public_accounts) { |
| 1060 PrefService* local_state = g_browser_process->local_state(); | 1128 PrefService* local_state = g_browser_process->local_state(); |
| 1061 | 1129 |
| 1062 // Determine the currently logged-in user's email. | 1130 // Determine the currently logged-in user's email. |
| 1063 std::string logged_in_user_email; | 1131 std::string active_user_email; |
| 1064 if (IsUserLoggedIn()) | 1132 if (IsUserLoggedIn()) |
| 1065 logged_in_user_email = GetLoggedInUser()->email(); | 1133 active_user_email = GetLoggedInUser()->email(); |
| 1066 | 1134 |
| 1067 // If there is a public account whose data is pending removal and the user is | 1135 // 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 | 1136 // not currently logged in with that account, take this opportunity to remove |
| 1069 // the data. | 1137 // the data. |
| 1070 std::string public_account_pending_data_removal = | 1138 std::string public_account_pending_data_removal = |
| 1071 local_state->GetString(kPublicAccountPendingDataRemoval); | 1139 local_state->GetString(kPublicAccountPendingDataRemoval); |
| 1072 if (!public_account_pending_data_removal.empty() && | 1140 if (!public_account_pending_data_removal.empty() && |
| 1073 public_account_pending_data_removal != logged_in_user_email) { | 1141 public_account_pending_data_removal != active_user_email) { |
| 1074 RemoveNonCryptohomeData(public_account_pending_data_removal); | 1142 RemoveNonCryptohomeData(public_account_pending_data_removal); |
| 1075 local_state->ClearPref(kPublicAccountPendingDataRemoval); | 1143 local_state->ClearPref(kPublicAccountPendingDataRemoval); |
| 1076 } | 1144 } |
| 1077 | 1145 |
| 1078 // Split the current user list public accounts and regular users. | 1146 // Split the current user list public accounts and regular users. |
| 1079 std::vector<std::string> old_public_accounts; | 1147 std::vector<std::string> old_public_accounts; |
| 1080 std::set<std::string> regular_users; | 1148 std::set<std::string> regular_users; |
| 1081 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 1149 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 1082 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) | 1150 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) |
| 1083 old_public_accounts.push_back((*it)->email()); | 1151 old_public_accounts.push_back((*it)->email()); |
| 1084 else | 1152 else |
| 1085 regular_users.insert((*it)->email()); | 1153 regular_users.insert((*it)->email()); |
| 1086 } | 1154 } |
| 1087 | 1155 |
| 1088 // Get the new list of public accounts from policy. | 1156 // Get the new list of public accounts from policy. |
| 1089 std::vector<std::string> new_public_accounts; | 1157 std::vector<std::string> new_public_accounts; |
| 1090 std::set<std::string> new_public_accounts_set; | 1158 std::set<std::string> new_public_accounts_set; |
| 1091 if (!ParseUserList(public_accounts, regular_users, logged_in_user_email, | 1159 if (!ParseUserList(public_accounts, regular_users, active_user_email, |
| 1092 &new_public_accounts, &new_public_accounts_set) && | 1160 &new_public_accounts, &new_public_accounts_set) && |
| 1093 IsLoggedInAsPublicAccount()) { | 1161 IsLoggedInAsPublicAccount()) { |
| 1094 // If the user is currently logged into a public account that has been | 1162 // 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 | 1163 // removed from the list, mark the account's data as pending removal after |
| 1096 // logout. | 1164 // logout. |
| 1097 local_state->SetString(kPublicAccountPendingDataRemoval, | 1165 local_state->SetString(kPublicAccountPendingDataRemoval, |
| 1098 logged_in_user_email); | 1166 active_user_email); |
| 1099 } | 1167 } |
| 1100 | 1168 |
| 1101 // Persist the new list of public accounts in a pref. | 1169 // Persist the new list of public accounts in a pref. |
| 1102 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); | 1170 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); |
| 1103 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); | 1171 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); |
| 1104 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); | 1172 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); |
| 1105 | 1173 |
| 1106 // If the list of public accounts has not changed, return. | 1174 // If the list of public accounts has not changed, return. |
| 1107 if (new_public_accounts.size() == old_public_accounts.size()) { | 1175 if (new_public_accounts.size() == old_public_accounts.size()) { |
| 1108 bool changed = false; | 1176 bool changed = false; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1124 it = users_.erase(it); | 1192 it = users_.erase(it); |
| 1125 } else { | 1193 } else { |
| 1126 ++it; | 1194 ++it; |
| 1127 } | 1195 } |
| 1128 } | 1196 } |
| 1129 | 1197 |
| 1130 // Add the new public accounts to the front of the user list. | 1198 // Add the new public accounts to the front of the user list. |
| 1131 for (std::vector<std::string>::const_reverse_iterator | 1199 for (std::vector<std::string>::const_reverse_iterator |
| 1132 it = new_public_accounts.rbegin(); | 1200 it = new_public_accounts.rbegin(); |
| 1133 it != new_public_accounts.rend(); ++it) { | 1201 it != new_public_accounts.rend(); ++it) { |
| 1134 if (IsLoggedInAsPublicAccount() && *it == logged_in_user_email) | 1202 if (IsLoggedInAsPublicAccount() && *it == active_user_email) |
| 1135 users_.insert(users_.begin(), GetLoggedInUser()); | 1203 users_.insert(users_.begin(), GetLoggedInUser()); |
| 1136 else | 1204 else |
| 1137 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); | 1205 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); |
| 1138 UpdatePublicAccountDisplayName(*it); | 1206 UpdatePublicAccountDisplayName(*it); |
| 1139 } | 1207 } |
| 1140 | 1208 |
| 1141 user_image_manager_->LoadUserImages( | 1209 user_image_manager_->LoadUserImages( |
| 1142 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); | 1210 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); |
| 1143 | 1211 |
| 1144 return true; | 1212 return true; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1294 content::NotificationService::NoDetails()); | 1362 content::NotificationService::NoDetails()); |
| 1295 } | 1363 } |
| 1296 | 1364 |
| 1297 void UserManagerImpl::NotifyMergeSessionStateChanged() { | 1365 void UserManagerImpl::NotifyMergeSessionStateChanged() { |
| 1298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1299 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 1367 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, |
| 1300 MergeSessionStateChanged(merge_session_state_)); | 1368 MergeSessionStateChanged(merge_session_state_)); |
| 1301 } | 1369 } |
| 1302 | 1370 |
| 1303 } // namespace chromeos | 1371 } // namespace chromeos |
| OLD | NEW |