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

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

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

Powered by Google App Engine
This is Rietveld 408576698