| 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 "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/chromeos/cros/cert_library.h" | 27 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 28 #include "chrome/browser/chromeos/cros/cros_library.h" | 28 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 29 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 29 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 30 #include "chrome/browser/chromeos/login/default_user_images.h" | 30 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 31 #include "chrome/browser/chromeos/login/helper.h" | 31 #include "chrome/browser/chromeos/login/helper.h" |
| 32 #include "chrome/browser/chromeos/login/login_display.h" | 32 #include "chrome/browser/chromeos/login/login_display.h" |
| 33 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 33 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 34 #include "chrome/browser/chromeos/login/user_image.h" | 34 #include "chrome/browser/chromeos/login/user_image.h" |
| 35 #include "chrome/browser/chromeos/login/wizard_controller.h" | 35 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 36 #include "chrome/browser/chromeos/settings/cros_settings.h" | 36 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 37 #include "chrome/browser/chromeos/settings/ownership_service.h" |
| 37 #include "chrome/browser/policy/browser_policy_connector.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" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 is_current_user_ephemeral_(false), | 196 is_current_user_ephemeral_(false), |
| 196 ephemeral_users_enabled_(false), | 197 ephemeral_users_enabled_(false), |
| 197 observed_sync_service_(NULL), | 198 observed_sync_service_(NULL), |
| 198 last_image_set_async_(false), | 199 last_image_set_async_(false), |
| 199 downloaded_profile_image_data_url_(chrome::kAboutBlankURL), | 200 downloaded_profile_image_data_url_(chrome::kAboutBlankURL), |
| 200 downloading_profile_image_(false) { | 201 downloading_profile_image_(false) { |
| 201 // UserManager instance should be used only on UI thread. | 202 // UserManager instance should be used only on UI thread. |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 203 | 204 |
| 204 MigrateWallpaperData(); | 205 MigrateWallpaperData(); |
| 205 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 206 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
| 206 content::NotificationService::AllSources()); | 207 content::NotificationService::AllSources()); |
| 207 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 208 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 208 content::NotificationService::AllSources()); | 209 content::NotificationService::AllSources()); |
| 209 RetrieveTrustedDevicePolicies(); | 210 RetrieveTrustedDevicePolicies(); |
| 210 } | 211 } |
| 211 | 212 |
| 212 UserManagerImpl::~UserManagerImpl() { | 213 UserManagerImpl::~UserManagerImpl() { |
| 213 // Can't use STLDeleteElements because of the private destructor of User. | 214 // Can't use STLDeleteElements because of the private destructor of User. |
| 214 for (size_t i = 0; i < users_.size(); ++i) | 215 for (size_t i = 0; i < users_.size();++i) |
| 215 delete users_[i]; | 216 delete users_[i]; |
| 216 users_.clear(); | 217 users_.clear(); |
| 217 if (is_current_user_ephemeral_) | 218 if (is_current_user_ephemeral_) |
| 218 delete logged_in_user_; | 219 delete logged_in_user_; |
| 219 } | 220 } |
| 220 | 221 |
| 221 const UserList& UserManagerImpl::GetUsers() const { | 222 const UserList& UserManagerImpl::GetUsers() const { |
| 222 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 223 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
| 223 return users_; | 224 return users_; |
| 224 } | 225 } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 578 } |
| 578 | 579 |
| 579 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { | 580 void UserManagerImpl::DownloadProfileImage(const std::string& reason) { |
| 580 DownloadProfileData(reason, true); | 581 DownloadProfileData(reason, true); |
| 581 } | 582 } |
| 582 | 583 |
| 583 void UserManagerImpl::Observe(int type, | 584 void UserManagerImpl::Observe(int type, |
| 584 const content::NotificationSource& source, | 585 const content::NotificationSource& source, |
| 585 const content::NotificationDetails& details) { | 586 const content::NotificationDetails& details) { |
| 586 switch (type) { | 587 switch (type) { |
| 587 case chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED: | 588 case chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED: |
| 588 CheckOwnership(); | 589 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 589 RetrieveTrustedDevicePolicies(); | 590 base::Bind(&UserManagerImpl::CheckOwnership, |
| 591 base::Unretained(this))); |
| 592 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 593 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, |
| 594 base::Unretained(this))); |
| 590 break; | 595 break; |
| 591 case chrome::NOTIFICATION_PROFILE_ADDED: | 596 case chrome::NOTIFICATION_PROFILE_ADDED: |
| 592 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) { | 597 if (IsUserLoggedIn() && !IsLoggedInAsGuest()) { |
| 593 Profile* profile = content::Source<Profile>(source).ptr(); | 598 Profile* profile = content::Source<Profile>(source).ptr(); |
| 594 if (!profile->IsOffTheRecord() && | 599 if (!profile->IsOffTheRecord() && |
| 595 profile == ProfileManager::GetDefaultProfile()) { | 600 profile == ProfileManager::GetDefaultProfile()) { |
| 596 DCHECK(NULL == observed_sync_service_); | 601 DCHECK(NULL == observed_sync_service_); |
| 597 observed_sync_service_ = | 602 observed_sync_service_ = |
| 598 ProfileSyncServiceFactory::GetForProfile(profile); | 603 ProfileSyncServiceFactory::GetForProfile(profile); |
| 599 if (observed_sync_service_) | 604 if (observed_sync_service_) |
| 600 observed_sync_service_->AddObserver(this); | 605 observed_sync_service_->AddObserver(this); |
| 601 } | 606 } |
| 602 } | 607 } |
| 603 break; | 608 break; |
| 604 default: | 609 default: |
| 605 NOTREACHED(); | 610 NOTREACHED(); |
| 606 } | 611 } |
| 607 } | 612 } |
| 608 | 613 |
| 609 void UserManagerImpl::OnStateChanged() { | 614 void UserManagerImpl::OnStateChanged() { |
| 610 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest()); | 615 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest()); |
| 611 AuthError::State state = observed_sync_service_->GetAuthError().state(); | 616 AuthError::State state = observed_sync_service_->GetAuthError().state(); |
| 612 if (state != AuthError::NONE && | 617 if (state != AuthError::NONE && |
| 613 state != AuthError::CONNECTION_FAILED && | 618 state != AuthError::CONNECTION_FAILED && |
| 614 state != AuthError::SERVICE_UNAVAILABLE && | 619 state != AuthError::SERVICE_UNAVAILABLE && |
| 615 state != AuthError::REQUEST_CANCELED) { | 620 state != AuthError::REQUEST_CANCELED) { |
| 616 // Invalidate OAuth token to force Gaia sign-in flow. This is needed | 621 // Invalidate OAuth token to force Gaia sign-in flow. This is needed |
| 617 // because sign-out/sign-in solution is suggested to the user. | 622 // because sign-out/sign-in solution is suggested to the user. |
| 618 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is | 623 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is |
| 619 // implemented. | 624 // implemented. |
| 620 DVLOG(1) << "Invalidate OAuth token because of a sync error."; | 625 DVLOG(1) << "Invalidate OAuth token because of a sync error."; |
| 621 SaveUserOAuthStatus(GetLoggedInUser().email(), | 626 SaveUserOAuthStatus(GetLoggedInUser().email(), |
| 622 User::OAUTH_TOKEN_STATUS_INVALID); | 627 User::OAUTH_TOKEN_STATUS_INVALID); |
| 623 } | 628 } |
| 624 } | 629 } |
| 625 | 630 |
| 626 bool UserManagerImpl::IsCurrentUserOwner() const { | 631 bool UserManagerImpl::IsCurrentUserOwner() const { |
| 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 628 base::AutoLock lk(is_current_user_owner_lock_); | 633 base::AutoLock lk(is_current_user_owner_lock_); |
| 629 return is_current_user_owner_; | 634 return is_current_user_owner_; |
| 630 } | 635 } |
| 631 | 636 |
| 632 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { | 637 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 // Any other user is ephemeral when: | 691 // Any other user is ephemeral when: |
| 687 // a) Going through the regular login flow and ephemeral users are enabled. | 692 // a) Going through the regular login flow and ephemeral users are enabled. |
| 688 // - or - | 693 // - or - |
| 689 // b) The browser is restarting after a crash. | 694 // b) The browser is restarting after a crash. |
| 690 return AreEphemeralUsersEnabled() || | 695 return AreEphemeralUsersEnabled() || |
| 691 (base::chromeos::IsRunningOnChromeOS() && | 696 (base::chromeos::IsRunningOnChromeOS() && |
| 692 !CommandLine::ForCurrentProcess()-> | 697 !CommandLine::ForCurrentProcess()-> |
| 693 HasSwitch(switches::kLoginManager)); | 698 HasSwitch(switches::kLoginManager)); |
| 694 } | 699 } |
| 695 | 700 |
| 696 void UserManagerImpl::AddObserver(UserManager::Observer* obs) { | 701 void UserManagerImpl::AddObserver(Observer* obs) { |
| 697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 698 observer_list_.AddObserver(obs); | 703 observer_list_.AddObserver(obs); |
| 699 } | 704 } |
| 700 | 705 |
| 701 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) { | 706 void UserManagerImpl::RemoveObserver(Observer* obs) { |
| 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 703 observer_list_.RemoveObserver(obs); | 708 observer_list_.RemoveObserver(obs); |
| 704 } | 709 } |
| 705 | 710 |
| 706 const gfx::ImageSkia& UserManagerImpl::DownloadedProfileImage() const { | 711 const gfx::ImageSkia& UserManagerImpl::DownloadedProfileImage() const { |
| 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 708 return downloaded_profile_image_; | 713 return downloaded_profile_image_; |
| 709 } | 714 } |
| 710 | 715 |
| 711 void UserManagerImpl::NotifyLocalStateChanged() { | 716 void UserManagerImpl::NotifyLocalStateChanged() { |
| 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 713 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 718 FOR_EACH_OBSERVER( |
| 714 LocalStateChanged(this)); | 719 Observer, |
| 720 observer_list_, |
| 721 LocalStateChanged(this)); |
| 715 } | 722 } |
| 716 | 723 |
| 717 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { | 724 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { |
| 718 std::string filename = username + ".png"; | 725 std::string filename = username + ".png"; |
| 719 FilePath user_data_dir; | 726 FilePath user_data_dir; |
| 720 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 727 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 721 return user_data_dir.AppendASCII(filename); | 728 return user_data_dir.AppendASCII(filename); |
| 722 } | 729 } |
| 723 | 730 |
| 724 void UserManagerImpl::EnsureUsersLoaded() { | 731 void UserManagerImpl::EnsureUsersLoaded() { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 888 |
| 882 void UserManagerImpl::NotifyOnLogin() { | 889 void UserManagerImpl::NotifyOnLogin() { |
| 883 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 890 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 884 content::NotificationService::current()->Notify( | 891 content::NotificationService::current()->Notify( |
| 885 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 892 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 886 content::Source<UserManagerImpl>(this), | 893 content::Source<UserManagerImpl>(this), |
| 887 content::Details<const User>(logged_in_user_)); | 894 content::Details<const User>(logged_in_user_)); |
| 888 | 895 |
| 889 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); | 896 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); |
| 890 | 897 |
| 891 // Indicate to DeviceSettingsService that the owner key may have become | 898 // Schedules current user ownership check on file thread. |
| 892 // available. | 899 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 893 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); | 900 base::Bind(&UserManagerImpl::CheckOwnership, |
| 901 base::Unretained(this))); |
| 894 } | 902 } |
| 895 | 903 |
| 896 void UserManagerImpl::SetInitialUserImage(const std::string& username) { | 904 void UserManagerImpl::SetInitialUserImage(const std::string& username) { |
| 897 // Choose a random default image. | 905 // Choose a random default image. |
| 898 int image_id = | 906 int image_id = |
| 899 base::RandInt(kFirstDefaultImageIndex, kDefaultImagesCount - 1); | 907 base::RandInt(kFirstDefaultImageIndex, kDefaultImagesCount - 1); |
| 900 SaveUserDefaultImageIndex(username, image_id); | 908 SaveUserDefaultImageIndex(username, image_id); |
| 901 } | 909 } |
| 902 | 910 |
| 903 void UserManagerImpl::MigrateWallpaperData() { | 911 void UserManagerImpl::MigrateWallpaperData() { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 } | 1148 } |
| 1141 | 1149 |
| 1142 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { | 1150 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { |
| 1143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1144 if (!file_util::Delete(image_path, false)) { | 1152 if (!file_util::Delete(image_path, false)) { |
| 1145 LOG(ERROR) << "Failed to remove user image."; | 1153 LOG(ERROR) << "Failed to remove user image."; |
| 1146 return; | 1154 return; |
| 1147 } | 1155 } |
| 1148 } | 1156 } |
| 1149 | 1157 |
| 1150 void UserManagerImpl::UpdateOwnership( | 1158 void UserManagerImpl::UpdateOwnership(bool is_owner) { |
| 1151 DeviceSettingsService::OwnershipStatus status, | 1159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1152 bool is_owner) { | |
| 1153 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); | |
| 1154 | 1160 |
| 1155 SetCurrentUserIsOwner(is_owner); | 1161 SetCurrentUserIsOwner(is_owner); |
| 1162 content::NotificationService::current()->Notify( |
| 1163 chrome::NOTIFICATION_OWNERSHIP_CHECKED, |
| 1164 content::NotificationService::AllSources(), |
| 1165 content::NotificationService::NoDetails()); |
| 1166 if (is_owner) { |
| 1167 // Also update cached value. |
| 1168 CrosSettings::Get()->SetString(kDeviceOwner, GetLoggedInUser().email()); |
| 1169 } |
| 1156 } | 1170 } |
| 1157 | 1171 |
| 1158 void UserManagerImpl::CheckOwnership() { | 1172 void UserManagerImpl::CheckOwnership() { |
| 1159 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 1173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1174 bool is_owner = OwnershipService::GetSharedInstance()->IsCurrentUserOwner(); |
| 1175 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); |
| 1176 |
| 1177 // UserManagerImpl should be accessed only on UI thread. |
| 1178 BrowserThread::PostTask( |
| 1179 BrowserThread::UI, |
| 1180 FROM_HERE, |
| 1160 base::Bind(&UserManagerImpl::UpdateOwnership, | 1181 base::Bind(&UserManagerImpl::UpdateOwnership, |
| 1161 base::Unretained(this))); | 1182 base::Unretained(this), |
| 1183 is_owner)); |
| 1162 } | 1184 } |
| 1163 | 1185 |
| 1164 // ProfileDownloaderDelegate override. | 1186 // ProfileDownloaderDelegate override. |
| 1165 bool UserManagerImpl::NeedsProfilePicture() const { | 1187 bool UserManagerImpl::NeedsProfilePicture() const { |
| 1166 return downloading_profile_image_; | 1188 return downloading_profile_image_; |
| 1167 } | 1189 } |
| 1168 | 1190 |
| 1169 // ProfileDownloaderDelegate override. | 1191 // ProfileDownloaderDelegate override. |
| 1170 int UserManagerImpl::GetDesiredImageSideLength() const { | 1192 int UserManagerImpl::GetDesiredImageSideLength() const { |
| 1171 return GetCurrentUserImageSize(); | 1193 return GetCurrentUserImageSize(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 BrowserThread::PostTask( | 1388 BrowserThread::PostTask( |
| 1367 BrowserThread::FILE, | 1389 BrowserThread::FILE, |
| 1368 FROM_HERE, | 1390 FROM_HERE, |
| 1369 base::Bind(&UserManagerImpl::DeleteUserImage, | 1391 base::Bind(&UserManagerImpl::DeleteUserImage, |
| 1370 base::Unretained(this), | 1392 base::Unretained(this), |
| 1371 image_path)); | 1393 image_path)); |
| 1372 } | 1394 } |
| 1373 } | 1395 } |
| 1374 | 1396 |
| 1375 } // namespace chromeos | 1397 } // namespace chromeos |
| OLD | NEW |