Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" | 28 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" |
| 29 #include "chrome/browser/chromeos/dbus/cryptohome_client.h" | 29 #include "chrome/browser/chromeos/dbus/cryptohome_client.h" |
| 30 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 30 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 31 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 31 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 32 #include "chrome/browser/chromeos/login/default_user_images.h" | 32 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 33 #include "chrome/browser/chromeos/login/helper.h" | 33 #include "chrome/browser/chromeos/login/helper.h" |
| 34 #include "chrome/browser/chromeos/login/login_display.h" | 34 #include "chrome/browser/chromeos/login/login_display.h" |
| 35 #include "chrome/browser/chromeos/login/ownership_service.h" | 35 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 36 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 36 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 37 #include "chrome/browser/chromeos/system/runtime_environment.h" | 37 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 38 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 38 #include "chrome/browser/prefs/pref_service.h" | 39 #include "chrome/browser/prefs/pref_service.h" |
| 39 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 40 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 40 #include "chrome/browser/profiles/profile_downloader.h" | 41 #include "chrome/browser/profiles/profile_downloader.h" |
| 41 #include "chrome/browser/profiles/profile_manager.h" | 42 #include "chrome/browser/profiles/profile_manager.h" |
| 42 #include "chrome/browser/sync/profile_sync_service.h" | 43 #include "chrome/browser/sync/profile_sync_service.h" |
| 43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 44 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 44 #include "chrome/browser/ui/webui/web_ui_util.h" | 45 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 45 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
| 46 #include "chrome/common/chrome_paths.h" | 47 #include "chrome/common/chrome_paths.h" |
| 47 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } // namespace | 284 } // namespace |
| 284 | 285 |
| 285 UserManagerImpl::UserManagerImpl() | 286 UserManagerImpl::UserManagerImpl() |
| 286 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), | 287 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), |
| 287 demo_user_(kDemoUser, false), | 288 demo_user_(kDemoUser, false), |
| 288 guest_user_(kGuestUser, true), | 289 guest_user_(kGuestUser, true), |
| 289 stub_user_(kStubUser, false), | 290 stub_user_(kStubUser, false), |
| 290 logged_in_user_(NULL), | 291 logged_in_user_(NULL), |
| 291 is_current_user_owner_(false), | 292 is_current_user_owner_(false), |
| 292 is_current_user_new_(false), | 293 is_current_user_new_(false), |
| 294 is_current_user_ephemeral_(false), | |
| 293 is_user_logged_in_(false), | 295 is_user_logged_in_(false), |
| 296 ephemeral_users_enabled_(false), | |
| 294 observed_sync_service_(NULL), | 297 observed_sync_service_(NULL), |
| 295 last_image_set_async_(false), | 298 last_image_set_async_(false), |
| 296 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { | 299 downloaded_profile_image_data_url_(chrome::kAboutBlankURL) { |
| 297 // Use stub as the logged-in user for test paths without login. | 300 // Use stub as the logged-in user for test paths without login. |
| 298 if (!system::runtime_environment::IsRunningOnChromeOS()) | 301 if (!system::runtime_environment::IsRunningOnChromeOS()) |
| 299 StubUserLoggedIn(); | 302 StubUserLoggedIn(); |
| 300 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 303 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
| 301 content::NotificationService::AllSources()); | 304 content::NotificationService::AllSources()); |
| 302 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 305 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 303 content::NotificationService::AllSources()); | 306 content::NotificationService::AllSources()); |
| 307 RetrieveTrustedDevicePolicies(); | |
| 304 } | 308 } |
| 305 | 309 |
| 306 UserManagerImpl::~UserManagerImpl() { | 310 UserManagerImpl::~UserManagerImpl() { |
| 307 } | 311 } |
| 308 | 312 |
| 309 const UserList& UserManagerImpl::GetUsers() const { | 313 const UserList& UserManagerImpl::GetUsers() const { |
| 310 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 314 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
| 311 return users_; | 315 return users_; |
| 312 } | 316 } |
| 313 | 317 |
| 314 void UserManagerImpl::UserLoggedIn(const std::string& email) { | 318 void UserManagerImpl::UserLoggedIn(const std::string& email) { |
| 315 DCHECK(!is_user_logged_in_); | 319 DCHECK(!is_user_logged_in_); |
| 316 | 320 |
| 317 is_user_logged_in_ = true; | 321 is_user_logged_in_ = true; |
| 318 | 322 |
| 319 if (email == kGuestUser) { | 323 if (email == kGuestUser) { |
| 324 is_current_user_ephemeral_ = true; | |
| 320 GuestUserLoggedIn(); | 325 GuestUserLoggedIn(); |
| 321 return; | 326 return; |
| 322 } | 327 } |
| 323 | 328 |
| 324 if (email == kDemoUser) { | 329 if (email == kDemoUser) { |
| 330 is_current_user_ephemeral_ = true; | |
| 325 DemoUserLoggedIn(); | 331 DemoUserLoggedIn(); |
| 326 return; | 332 return; |
| 327 } | 333 } |
| 328 | 334 |
| 329 EnsureUsersLoaded(); | 335 if (IsEphemeralUser(email)) { |
| 336 is_current_user_new_ = true; | |
| 337 is_current_user_ephemeral_ = true; | |
| 338 logged_in_user_ = CreateUser(email); | |
| 339 SetInitialUserImage(email); | |
| 340 } else { | |
| 341 EnsureUsersLoaded(); | |
| 330 | 342 |
| 331 // Clear the prefs view of the users. | 343 // Clear the prefs view of the users. |
| 332 PrefService* prefs = g_browser_process->local_state(); | 344 PrefService* prefs = g_browser_process->local_state(); |
| 333 ListPrefUpdate prefs_users_update(prefs, UserManager::kLoggedInUsers); | 345 ListPrefUpdate prefs_users_update(prefs, UserManager::kLoggedInUsers); |
| 334 prefs_users_update->Clear(); | 346 prefs_users_update->Clear(); |
| 335 | 347 |
| 336 // Make sure this user is first. | 348 // Make sure this user is first. |
| 337 prefs_users_update->Append(Value::CreateStringValue(email)); | 349 prefs_users_update->Append(Value::CreateStringValue(email)); |
| 338 UserList::iterator logged_in_user = users_.end(); | 350 UserList::iterator logged_in_user = users_.end(); |
| 339 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | 351 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { |
| 340 std::string user_email = (*it)->email(); | 352 std::string user_email = (*it)->email(); |
| 341 // Skip the most recent user. | 353 // Skip the most recent user. |
| 342 if (email != user_email) | 354 if (email != user_email) |
| 343 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 355 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
| 344 else | 356 else |
| 345 logged_in_user = it; | 357 logged_in_user = it; |
| 358 } | |
| 359 | |
| 360 if (logged_in_user == users_.end()) { | |
| 361 is_current_user_new_ = true; | |
| 362 logged_in_user_ = CreateUser(email); | |
| 363 } else { | |
| 364 logged_in_user_ = *logged_in_user; | |
| 365 users_.erase(logged_in_user); | |
| 366 } | |
| 367 // This user must be in the front of the user list. | |
| 368 users_.insert(users_.begin(), logged_in_user_); | |
| 346 } | 369 } |
| 347 | 370 |
| 348 if (logged_in_user == users_.end()) { | |
| 349 is_current_user_new_ = true; | |
| 350 logged_in_user_ = CreateUser(email); | |
| 351 } else { | |
| 352 logged_in_user_ = *logged_in_user; | |
| 353 users_.erase(logged_in_user); | |
| 354 } | |
| 355 // This user must be in the front of the user list. | |
| 356 users_.insert(users_.begin(), logged_in_user_); | |
| 357 | |
| 358 NotifyOnLogin(); | 371 NotifyOnLogin(); |
| 359 | 372 |
| 360 if (is_current_user_new_) { | 373 if (is_current_user_new_) { |
| 361 SetInitialUserImage(email); | 374 SetInitialUserImage(email); |
| 362 } else { | 375 } else { |
| 363 // Download profile image if it's user image and see if it has changed. | 376 // Download profile image if it's user image and see if it has changed. |
| 364 int image_index = logged_in_user_->image_index(); | 377 int image_index = logged_in_user_->image_index(); |
| 365 if (image_index == User::kProfileImageIndex) { | 378 if (image_index == User::kProfileImageIndex) { |
| 366 InitDownloadedProfileImage(); | 379 InitDownloadedProfileImage(); |
| 367 BrowserThread::PostDelayedTask( | 380 BrowserThread::PostDelayedTask( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 428 |
| 416 // Sanity check: do not allow the logged-in user to remove himself. | 429 // Sanity check: do not allow the logged-in user to remove himself. |
| 417 if (logged_in_user_ && logged_in_user_->email() == email) | 430 if (logged_in_user_ && logged_in_user_->email() == email) |
| 418 return; | 431 return; |
| 419 | 432 |
| 420 RemoveUserInternal(email, delegate); | 433 RemoveUserInternal(email, delegate); |
| 421 } | 434 } |
| 422 | 435 |
| 423 void UserManagerImpl::RemoveUserFromList(const std::string& email) { | 436 void UserManagerImpl::RemoveUserFromList(const std::string& email) { |
| 424 EnsureUsersLoaded(); | 437 EnsureUsersLoaded(); |
| 425 | 438 RemoveUserFromListInternal(email); |
| 426 // Clear the prefs view of the users. | |
| 427 PrefService* prefs = g_browser_process->local_state(); | |
| 428 ListPrefUpdate prefs_users_update(prefs, UserManager::kLoggedInUsers); | |
| 429 prefs_users_update->Clear(); | |
| 430 | |
| 431 UserList::iterator user_to_remove = users_.end(); | |
| 432 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 433 std::string user_email = (*it)->email(); | |
| 434 // Skip user that we would like to delete. | |
| 435 if (email != user_email) | |
| 436 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
| 437 else | |
| 438 user_to_remove = it; | |
| 439 } | |
| 440 | |
| 441 DictionaryPrefUpdate prefs_images_update(prefs, UserManager::kUserImages); | |
| 442 std::string image_path_string; | |
| 443 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | |
| 444 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | |
| 445 | |
| 446 DictionaryPrefUpdate prefs_oauth_update(prefs, | |
| 447 UserManager::kUserOAuthTokenStatus); | |
| 448 int oauth_status; | |
| 449 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | |
| 450 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | |
| 451 | |
| 452 DictionaryPrefUpdate prefs_display_email_update( | |
| 453 prefs, UserManager::kUserDisplayEmail); | |
| 454 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); | |
| 455 | |
| 456 if (user_to_remove != users_.end()) { | |
| 457 --display_name_count_[(*user_to_remove)->GetDisplayName()]; | |
| 458 delete *user_to_remove; | |
| 459 users_.erase(user_to_remove); | |
| 460 } | |
| 461 | |
| 462 int default_image_id = User::kInvalidImageIndex; | |
| 463 if (!image_path_string.empty() && | |
| 464 !IsDefaultImagePath(image_path_string, &default_image_id)) { | |
| 465 FilePath image_path(image_path_string); | |
| 466 BrowserThread::PostTask( | |
| 467 BrowserThread::FILE, | |
| 468 FROM_HERE, | |
| 469 base::Bind(&UserManagerImpl::DeleteUserImage, | |
| 470 base::Unretained(this), | |
| 471 image_path)); | |
| 472 } | |
| 473 } | 439 } |
| 474 | 440 |
| 475 bool UserManagerImpl::IsKnownUser(const std::string& email) const { | 441 bool UserManagerImpl::IsKnownUser(const std::string& email) const { |
| 476 return FindUser(email) != NULL; | 442 return FindUser(email) != NULL; |
| 477 } | 443 } |
| 478 | 444 |
| 479 const User* UserManagerImpl::FindUser(const std::string& email) const { | 445 const User* UserManagerImpl::FindUser(const std::string& email) const { |
| 480 // Speed up search by checking the logged-in user first. | |
| 481 if (logged_in_user_ && logged_in_user_->email() == email) | 446 if (logged_in_user_ && logged_in_user_->email() == email) |
| 482 return logged_in_user_; | 447 return logged_in_user_; |
| 483 const UserList& users = GetUsers(); | 448 return FindUserInList(email); |
| 484 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
| 485 if ((*it)->email() == email) | |
| 486 return *it; | |
| 487 } | |
| 488 return NULL; | |
| 489 } | 449 } |
| 490 | 450 |
| 491 const User& UserManagerImpl::GetLoggedInUser() const { | 451 const User& UserManagerImpl::GetLoggedInUser() const { |
| 492 return *logged_in_user_; | 452 return *logged_in_user_; |
| 493 } | 453 } |
| 494 | 454 |
| 495 User& UserManagerImpl::GetLoggedInUser() { | 455 User& UserManagerImpl::GetLoggedInUser() { |
| 496 return *logged_in_user_; | 456 return *logged_in_user_; |
| 497 } | 457 } |
| 498 | 458 |
| 499 bool UserManagerImpl::IsDisplayNameUnique( | 459 bool UserManagerImpl::IsDisplayNameUnique( |
| 500 const std::string& display_name) const { | 460 const std::string& display_name) const { |
| 501 return display_name_count_[display_name] < 2; | 461 return display_name_count_[display_name] < 2; |
| 502 } | 462 } |
| 503 | 463 |
| 504 void UserManagerImpl::SaveUserOAuthStatus( | 464 void UserManagerImpl::SaveUserOAuthStatus( |
| 505 const std::string& username, | 465 const std::string& username, |
| 506 User::OAuthTokenStatus oauth_token_status) { | 466 User::OAuthTokenStatus oauth_token_status) { |
| 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 468 | |
| 469 DVLOG(1) << "Saving user OAuth token status in Local State"; | |
| 470 User* user = const_cast<User*>(FindUser(username)); | |
| 471 if (user) | |
| 472 user->set_oauth_token_status(oauth_token_status); | |
| 473 | |
| 474 // Do not update local store if the user is ephemeral. | |
| 475 if (IsEphemeralUser(username)) | |
| 476 return; | |
| 477 | |
| 508 PrefService* local_state = g_browser_process->local_state(); | 478 PrefService* local_state = g_browser_process->local_state(); |
| 479 | |
| 509 DictionaryPrefUpdate oauth_status_update(local_state, | 480 DictionaryPrefUpdate oauth_status_update(local_state, |
| 510 UserManager::kUserOAuthTokenStatus); | 481 UserManager::kUserOAuthTokenStatus); |
| 511 oauth_status_update->SetWithoutPathExpansion(username, | 482 oauth_status_update->SetWithoutPathExpansion(username, |
| 512 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 483 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
| 513 DVLOG(1) << "Saving user OAuth token status in Local State"; | |
| 514 User* user = const_cast<User*>(FindUser(username)); | |
| 515 if (user) | |
| 516 user->set_oauth_token_status(oauth_token_status); | |
| 517 } | 484 } |
| 518 | 485 |
| 519 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( | 486 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( |
| 520 const std::string& username) const { | 487 const std::string& username) const { |
| 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 522 | 489 |
| 523 if (CommandLine::ForCurrentProcess()->HasSwitch( | 490 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 524 switches::kSkipOAuthLogin)) { | 491 switches::kSkipOAuthLogin)) { |
| 525 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. | 492 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. |
| 526 return User::OAUTH_TOKEN_STATUS_VALID; | 493 return User::OAUTH_TOKEN_STATUS_VALID; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 543 void UserManagerImpl::SaveUserDisplayEmail(const std::string& username, | 510 void UserManagerImpl::SaveUserDisplayEmail(const std::string& username, |
| 544 const std::string& display_email) { | 511 const std::string& display_email) { |
| 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 546 | 513 |
| 547 User* user = const_cast<User*>(FindUser(username)); | 514 User* user = const_cast<User*>(FindUser(username)); |
| 548 if (!user) | 515 if (!user) |
| 549 return; // Ignore if there is no such user. | 516 return; // Ignore if there is no such user. |
| 550 | 517 |
| 551 user->set_display_email(display_email); | 518 user->set_display_email(display_email); |
| 552 | 519 |
| 520 // Do not update local store if the user is ephemeral. | |
| 521 if (IsEphemeralUser(username)) | |
| 522 return; | |
| 523 | |
| 553 PrefService* local_state = g_browser_process->local_state(); | 524 PrefService* local_state = g_browser_process->local_state(); |
| 554 | 525 |
| 555 DictionaryPrefUpdate display_email_update(local_state, | 526 DictionaryPrefUpdate display_email_update(local_state, |
| 556 UserManager::kUserDisplayEmail); | 527 UserManager::kUserDisplayEmail); |
| 557 display_email_update->SetWithoutPathExpansion( | 528 display_email_update->SetWithoutPathExpansion( |
| 558 username, | 529 username, |
| 559 base::Value::CreateStringValue(display_email)); | 530 base::Value::CreateStringValue(display_email)); |
| 560 } | 531 } |
| 561 | 532 |
| 562 std::string UserManagerImpl::GetUserDisplayEmail( | 533 std::string UserManagerImpl::GetUserDisplayEmail( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); | 568 SaveImageToLocalState(username, "", User::kProfileImageIndex, false); |
| 598 } | 569 } |
| 599 } | 570 } |
| 600 | 571 |
| 601 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 572 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
| 602 if (profile_image_downloader_.get()) { | 573 if (profile_image_downloader_.get()) { |
| 603 // Another download is already in progress | 574 // Another download is already in progress |
| 604 return; | 575 return; |
| 605 } | 576 } |
| 606 | 577 |
| 607 if (GetLoggedInUser().email().empty()) { | 578 if (IsLoggedInAsGuest()) { |
| 608 // This is a guest login so there's no profile image to download. | 579 // This is a guest login so there's no profile image to download. |
| 609 return; | 580 return; |
| 610 } | 581 } |
| 611 | 582 |
| 612 profile_image_download_reason_ = reason; | 583 profile_image_download_reason_ = reason; |
| 613 profile_image_load_start_time_ = base::Time::Now(); | 584 profile_image_load_start_time_ = base::Time::Now(); |
| 614 profile_image_downloader_.reset(new ProfileDownloader(this)); | 585 profile_image_downloader_.reset(new ProfileDownloader(this)); |
| 615 profile_image_downloader_->Start(); | 586 profile_image_downloader_->Start(); |
| 616 } | 587 } |
| 617 | 588 |
| 618 void UserManagerImpl::Observe(int type, | 589 void UserManagerImpl::Observe(int type, |
| 619 const content::NotificationSource& source, | 590 const content::NotificationSource& source, |
| 620 const content::NotificationDetails& details) { | 591 const content::NotificationDetails& details) { |
| 621 switch (type) { | 592 switch (type) { |
| 622 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: | 593 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: |
| 623 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 594 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 624 base::Bind(&UserManagerImpl::CheckOwnership, | 595 base::Bind(&UserManagerImpl::CheckOwnership, |
| 625 base::Unretained(this))); | 596 base::Unretained(this))); |
| 597 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 598 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, | |
| 599 base::Unretained(this))); | |
| 626 break; | 600 break; |
| 627 case chrome::NOTIFICATION_PROFILE_ADDED: | 601 case chrome::NOTIFICATION_PROFILE_ADDED: |
| 628 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) { | 602 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) { |
| 629 Profile* profile = content::Source<Profile>(source).ptr(); | 603 Profile* profile = content::Source<Profile>(source).ptr(); |
| 630 if (!profile->IsOffTheRecord() && | 604 if (!profile->IsOffTheRecord() && |
| 631 profile == ProfileManager::GetDefaultProfile()) { | 605 profile == ProfileManager::GetDefaultProfile()) { |
| 632 DCHECK(NULL == observed_sync_service_); | 606 DCHECK(NULL == observed_sync_service_); |
| 633 observed_sync_service_ = | 607 observed_sync_service_ = |
| 634 ProfileSyncServiceFactory::GetForProfile(profile); | 608 ProfileSyncServiceFactory::GetForProfile(profile); |
| 635 if (observed_sync_service_) | 609 if (observed_sync_service_) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 662 | 636 |
| 663 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { | 637 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { |
| 664 base::AutoLock lk(is_current_user_owner_lock_); | 638 base::AutoLock lk(is_current_user_owner_lock_); |
| 665 is_current_user_owner_ = is_current_user_owner; | 639 is_current_user_owner_ = is_current_user_owner; |
| 666 } | 640 } |
| 667 | 641 |
| 668 bool UserManagerImpl::IsCurrentUserNew() const { | 642 bool UserManagerImpl::IsCurrentUserNew() const { |
| 669 return is_current_user_new_; | 643 return is_current_user_new_; |
| 670 } | 644 } |
| 671 | 645 |
| 646 bool UserManagerImpl::IsCurrentUserEphemeral() const { | |
| 647 return is_current_user_ephemeral_; | |
| 648 } | |
| 649 | |
| 672 bool UserManagerImpl::IsUserLoggedIn() const { | 650 bool UserManagerImpl::IsUserLoggedIn() const { |
| 673 return is_user_logged_in_; | 651 return is_user_logged_in_; |
| 674 } | 652 } |
| 675 | 653 |
| 676 bool UserManagerImpl::IsLoggedInAsDemoUser() const { | 654 bool UserManagerImpl::IsLoggedInAsDemoUser() const { |
| 677 return logged_in_user_ == &demo_user_; | 655 return logged_in_user_ == &demo_user_; |
| 678 } | 656 } |
| 679 | 657 |
| 680 bool UserManagerImpl::IsLoggedInAsGuest() const { | 658 bool UserManagerImpl::IsLoggedInAsGuest() const { |
| 681 return logged_in_user_ == &guest_user_; | 659 return logged_in_user_ == &guest_user_; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 if (prefs_display_emails && | 763 if (prefs_display_emails && |
| 786 prefs_display_emails->GetStringWithoutPathExpansion( | 764 prefs_display_emails->GetStringWithoutPathExpansion( |
| 787 email, &display_email)) { | 765 email, &display_email)) { |
| 788 user->set_display_email(display_email); | 766 user->set_display_email(display_email); |
| 789 } | 767 } |
| 790 } | 768 } |
| 791 } | 769 } |
| 792 } | 770 } |
| 793 } | 771 } |
| 794 | 772 |
| 773 void UserManagerImpl::RetrieveTrustedDevicePolicies() { | |
| 774 ephemeral_users_enabled_ = false; | |
| 775 owner_email_ = ""; | |
|
merkulova
2014/04/08 10:34:59
I wonder why we need this string?
We can initializ
bartfab (slow)
2014/04/14 11:36:42
Sorry for the late reply. I will summarize here wh
| |
| 776 | |
| 777 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 778 // Schedule a callback if device policy has not yet been verified. | |
| 779 if (!cros_settings->GetTrusted( | |
| 780 kAccountsPrefEphemeralUsersEnabled, | |
| 781 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, | |
| 782 base::Unretained(this)))) { | |
| 783 return; | |
| 784 } | |
| 785 | |
| 786 cros_settings->GetBoolean(kAccountsPrefEphemeralUsersEnabled, | |
| 787 &ephemeral_users_enabled_); | |
| 788 cros_settings->GetString(kDeviceOwner, &owner_email_); | |
| 789 | |
| 790 // If ephemeral users are enabled, remove all users except the owner. | |
| 791 if (ephemeral_users_enabled_) { | |
| 792 scoped_ptr<base::ListValue> users( | |
| 793 g_browser_process->local_state()->GetList(kLoggedInUsers)->DeepCopy()); | |
| 794 | |
| 795 bool changed = false; | |
| 796 for (base::ListValue::const_iterator user = users->begin(); | |
| 797 user != users->end(); ++user) { | |
| 798 std::string user_email; | |
| 799 (*user)->GetAsString(&user_email); | |
| 800 if (user_email != owner_email_) { | |
| 801 RemoveUserFromListInternal(user_email); | |
| 802 changed = true; | |
| 803 } | |
| 804 } | |
| 805 | |
| 806 if (changed) { | |
| 807 // Trigger a redraw of the login window. | |
| 808 content::NotificationService::current()->Notify( | |
| 809 chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, | |
| 810 content::Source<UserManagerImpl>(this), | |
| 811 content::NotificationService::NoDetails()); | |
| 812 } | |
| 813 } | |
| 814 } | |
| 815 | |
| 816 bool UserManagerImpl::AreEphemeralUsersEnabled() const { | |
| 817 return ephemeral_users_enabled_ && | |
| 818 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || | |
| 819 !owner_email_.empty()); | |
| 820 } | |
| 821 | |
| 822 bool UserManagerImpl::IsEphemeralUser(const std::string& email) const { | |
| 823 // The guest user always is ephemeral. | |
| 824 if (email == guest_user_.email()) | |
| 825 return true; | |
| 826 | |
| 827 // The currently logged-in user is ephemeral iff logged in as ephemeral. | |
| 828 if (logged_in_user_ && (email == logged_in_user_->email())) | |
| 829 return is_current_user_ephemeral_; | |
| 830 | |
| 831 // Any other user is ephemeral iff ephemeral users are enabled, the user is | |
| 832 // not the owner and is not in the persistent list. | |
| 833 return AreEphemeralUsersEnabled() && | |
| 834 (email != owner_email_) && | |
| 835 !FindUserInList(email); | |
| 836 } | |
| 837 | |
| 838 const User* UserManagerImpl::FindUserInList(const std::string& email) const { | |
| 839 const UserList& users = GetUsers(); | |
| 840 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | |
| 841 if ((*it)->email() == email) | |
| 842 return *it; | |
| 843 } | |
| 844 return NULL; | |
| 845 } | |
| 846 | |
| 795 void UserManagerImpl::StubUserLoggedIn() { | 847 void UserManagerImpl::StubUserLoggedIn() { |
| 796 logged_in_user_ = &stub_user_; | 848 logged_in_user_ = &stub_user_; |
| 797 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), | 849 stub_user_.SetImage(GetDefaultImage(kStubDefaultImageIndex), |
| 798 kStubDefaultImageIndex); | 850 kStubDefaultImageIndex); |
| 799 } | 851 } |
| 800 | 852 |
| 801 void UserManagerImpl::NotifyOnLogin() { | 853 void UserManagerImpl::NotifyOnLogin() { |
| 802 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 854 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 803 content::NotificationService::current()->Notify( | 855 content::NotificationService::current()->Notify( |
| 804 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 856 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 } | 919 } |
| 868 } | 920 } |
| 869 | 921 |
| 870 void UserManagerImpl::SaveUserImageInternal(const std::string& username, | 922 void UserManagerImpl::SaveUserImageInternal(const std::string& username, |
| 871 int image_index, | 923 int image_index, |
| 872 const SkBitmap& image) { | 924 const SkBitmap& image) { |
| 873 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 925 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 874 | 926 |
| 875 SetUserImage(username, image_index, image); | 927 SetUserImage(username, image_index, image); |
| 876 | 928 |
| 929 // Ignore for ephemeral users. | |
| 930 if (IsEphemeralUser(username)) | |
| 931 return; | |
| 932 | |
| 877 FilePath image_path = GetImagePathForUser(username); | 933 FilePath image_path = GetImagePathForUser(username); |
| 878 DVLOG(1) << "Saving user image to " << image_path.value(); | 934 DVLOG(1) << "Saving user image to " << image_path.value(); |
| 879 | 935 |
| 880 last_image_set_async_ = true; | 936 last_image_set_async_ = true; |
| 881 | 937 |
| 882 BrowserThread::PostTask( | 938 BrowserThread::PostTask( |
| 883 BrowserThread::FILE, | 939 BrowserThread::FILE, |
| 884 FROM_HERE, | 940 FROM_HERE, |
| 885 base::Bind(&UserManagerImpl::SaveImageToFile, | 941 base::Bind(&UserManagerImpl::SaveImageToFile, |
| 886 base::Unretained(this), | 942 base::Unretained(this), |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 913 base::Unretained(this), | 969 base::Unretained(this), |
| 914 username, image_path.value(), image_index, true)); | 970 username, image_path.value(), image_index, true)); |
| 915 } | 971 } |
| 916 | 972 |
| 917 void UserManagerImpl::SaveImageToLocalState(const std::string& username, | 973 void UserManagerImpl::SaveImageToLocalState(const std::string& username, |
| 918 const std::string& image_path, | 974 const std::string& image_path, |
| 919 int image_index, | 975 int image_index, |
| 920 bool is_async) { | 976 bool is_async) { |
| 921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 922 | 978 |
| 979 // Ignore for ephemeral users. | |
| 980 if (IsEphemeralUser(username)) | |
| 981 return; | |
| 982 | |
| 923 // TODO(ivankr): use unique filenames for user images each time | 983 // TODO(ivankr): use unique filenames for user images each time |
| 924 // a new image is set so that only the last image update is saved | 984 // a new image is set so that only the last image update is saved |
| 925 // to Local State and notified. | 985 // to Local State and notified. |
| 926 if (is_async && !last_image_set_async_) { | 986 if (is_async && !last_image_set_async_) { |
| 927 DVLOG(1) << "Ignoring saved image because it has changed"; | 987 DVLOG(1) << "Ignoring saved image because it has changed"; |
| 928 return; | 988 return; |
| 929 } else if (!is_async) { | 989 } else if (!is_async) { |
| 930 // Reset the async image save flag if called directly from the UI thread. | 990 // Reset the async image save flag if called directly from the UI thread. |
| 931 last_image_set_async_ = false; | 991 last_image_set_async_ = false; |
| 932 } | 992 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1062 } | 1122 } |
| 1063 | 1123 |
| 1064 User* UserManagerImpl::CreateUser(const std::string& email) const { | 1124 User* UserManagerImpl::CreateUser(const std::string& email) const { |
| 1065 User* user = new User(email, email == kGuestUser); | 1125 User* user = new User(email, email == kGuestUser); |
| 1066 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | 1126 user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 1067 // Used to determine whether user's display name is unique. | 1127 // Used to determine whether user's display name is unique. |
| 1068 ++display_name_count_[user->GetDisplayName()]; | 1128 ++display_name_count_[user->GetDisplayName()]; |
| 1069 return user; | 1129 return user; |
| 1070 } | 1130 } |
| 1071 | 1131 |
| 1132 void UserManagerImpl::RemoveUserFromListInternal(const std::string& email) { | |
| 1133 // Clear the prefs view of the users. | |
| 1134 PrefService* prefs = g_browser_process->local_state(); | |
| 1135 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
| 1136 prefs_users_update->Clear(); | |
| 1137 | |
| 1138 UserList::iterator user_to_remove = users_.end(); | |
| 1139 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 1140 std::string user_email = (*it)->email(); | |
| 1141 // Skip user that we would like to delete. | |
| 1142 if (email != user_email) | |
| 1143 prefs_users_update->Append(Value::CreateStringValue(user_email)); | |
| 1144 else | |
| 1145 user_to_remove = it; | |
| 1146 } | |
| 1147 | |
| 1148 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | |
| 1149 std::string image_path_string; | |
| 1150 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | |
| 1151 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1152 | |
| 1153 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | |
| 1154 int oauth_status; | |
| 1155 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | |
| 1156 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1157 | |
| 1158 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | |
| 1159 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); | |
| 1160 | |
| 1161 if (user_to_remove != users_.end()) { | |
| 1162 --display_name_count_[(*user_to_remove)->GetDisplayName()]; | |
| 1163 delete *user_to_remove; | |
| 1164 users_.erase(user_to_remove); | |
| 1165 } | |
| 1166 | |
| 1167 int default_image_id = User::kInvalidImageIndex; | |
| 1168 if (!image_path_string.empty() && | |
| 1169 !IsDefaultImagePath(image_path_string, &default_image_id)) { | |
| 1170 FilePath image_path(image_path_string); | |
| 1171 BrowserThread::PostTask( | |
| 1172 BrowserThread::FILE, | |
| 1173 FROM_HERE, | |
| 1174 base::Bind(&UserManagerImpl::DeleteUserImage, | |
| 1175 base::Unretained(this), | |
| 1176 image_path)); | |
| 1177 } | |
| 1178 } | |
| 1179 | |
| 1072 } // namespace chromeos | 1180 } // namespace chromeos |
| OLD | NEW |