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

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, simplify migration. 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 30 matching lines...) Expand all
668 bool UserManagerImpl::IsLoggedInAsStub() const { 663 bool UserManagerImpl::IsLoggedInAsStub() const {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
670 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser; 665 return IsUserLoggedIn() && logged_in_user_->email() == kStubUser;
671 } 666 }
672 667
673 bool UserManagerImpl::IsSessionStarted() const { 668 bool UserManagerImpl::IsSessionStarted() const {
674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
675 return session_started_; 670 return session_started_;
676 } 671 }
677 672
678 void UserManagerImpl::AddObserver(Observer* obs) { 673 void UserManagerImpl::AddObserver(UserManager::Observer* obs) {
679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
680 observer_list_.AddObserver(obs); 675 observer_list_.AddObserver(obs);
681 } 676 }
682 677
683 void UserManagerImpl::RemoveObserver(Observer* obs) { 678 void UserManagerImpl::RemoveObserver(UserManager::Observer* obs) {
684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
685 observer_list_.RemoveObserver(obs); 680 observer_list_.RemoveObserver(obs);
686 } 681 }
687 682
688 const gfx::ImageSkia& UserManagerImpl::DownloadedProfileImage() const { 683 const gfx::ImageSkia& UserManagerImpl::DownloadedProfileImage() const {
689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 684 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
690 return downloaded_profile_image_; 685 return downloaded_profile_image_;
691 } 686 }
692 687
693 void UserManagerImpl::NotifyLocalStateChanged() { 688 void UserManagerImpl::NotifyLocalStateChanged() {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
695 FOR_EACH_OBSERVER( 690 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_,
696 Observer, 691 LocalStateChanged(this));
697 observer_list_,
698 LocalStateChanged(this));
699 } 692 }
700 693
701 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { 694 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) {
702 std::string filename = username + ".png"; 695 std::string filename = username + ".png";
703 FilePath user_data_dir; 696 FilePath user_data_dir;
704 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 697 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
705 return user_data_dir.AppendASCII(filename); 698 return user_data_dir.AppendASCII(filename);
706 } 699 }
707 700
708 void UserManagerImpl::EnsureUsersLoaded() { 701 void UserManagerImpl::EnsureUsersLoaded() {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 883
891 void UserManagerImpl::NotifyOnLogin() { 884 void UserManagerImpl::NotifyOnLogin() {
892 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 885 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
893 content::NotificationService::current()->Notify( 886 content::NotificationService::current()->Notify(
894 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 887 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
895 content::Source<UserManagerImpl>(this), 888 content::Source<UserManagerImpl>(this),
896 content::Details<const User>(logged_in_user_)); 889 content::Details<const User>(logged_in_user_));
897 890
898 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 891 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
899 892
900 // Schedules current user ownership check on file thread. 893 // Indicate to DeviceSettingsService that the owner key may have become
901 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 894 // available.
902 base::Bind(&UserManagerImpl::CheckOwnership, 895 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email());
903 base::Unretained(this)));
904 } 896 }
905 897
906 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 898 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
907 // Choose a random default image. 899 // Choose a random default image.
908 int image_id = 900 int image_id =
909 base::RandInt(kFirstDefaultImageIndex, kDefaultImagesCount - 1); 901 base::RandInt(kFirstDefaultImageIndex, kDefaultImagesCount - 1);
910 SaveUserDefaultImageIndex(username, image_id); 902 SaveUserDefaultImageIndex(username, image_id);
911 } 903 }
912 904
913 void UserManagerImpl::MigrateWallpaperData() { 905 void UserManagerImpl::MigrateWallpaperData() {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 } 1142 }
1151 1143
1152 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { 1144 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) {
1153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1154 if (!file_util::Delete(image_path, false)) { 1146 if (!file_util::Delete(image_path, false)) {
1155 LOG(ERROR) << "Failed to remove user image."; 1147 LOG(ERROR) << "Failed to remove user image.";
1156 return; 1148 return;
1157 } 1149 }
1158 } 1150 }
1159 1151
1160 void UserManagerImpl::UpdateOwnership(bool is_owner) { 1152 void UserManagerImpl::UpdateOwnership(
1161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1153 DeviceSettingsService::OwnershipStatus status,
1154 bool is_owner) {
1155 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1162 1156
1163 SetCurrentUserIsOwner(is_owner); 1157 SetCurrentUserIsOwner(is_owner);
1164 content::NotificationService::current()->Notify(
1165 chrome::NOTIFICATION_OWNERSHIP_CHECKED,
1166 content::NotificationService::AllSources(),
1167 content::NotificationService::NoDetails());
1168 if (is_owner) {
1169 // Also update cached value.
1170 CrosSettings::Get()->SetString(kDeviceOwner, GetLoggedInUser().email());
1171 }
1172 } 1158 }
1173 1159
1174 void UserManagerImpl::CheckOwnership() { 1160 void UserManagerImpl::CheckOwnership() {
1175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1161 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
1176 bool is_owner = OwnershipService::GetSharedInstance()->IsCurrentUserOwner();
1177 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1178
1179 // UserManagerImpl should be accessed only on UI thread.
1180 BrowserThread::PostTask(
1181 BrowserThread::UI,
1182 FROM_HERE,
1183 base::Bind(&UserManagerImpl::UpdateOwnership, 1162 base::Bind(&UserManagerImpl::UpdateOwnership,
1184 base::Unretained(this), 1163 base::Unretained(this)));
1185 is_owner));
1186 } 1164 }
1187 1165
1188 // ProfileDownloaderDelegate override. 1166 // ProfileDownloaderDelegate override.
1189 bool UserManagerImpl::NeedsProfilePicture() const { 1167 bool UserManagerImpl::NeedsProfilePicture() const {
1190 return downloading_profile_image_; 1168 return downloading_profile_image_;
1191 } 1169 }
1192 1170
1193 // ProfileDownloaderDelegate override. 1171 // ProfileDownloaderDelegate override.
1194 int UserManagerImpl::GetDesiredImageSideLength() const { 1172 int UserManagerImpl::GetDesiredImageSideLength() const {
1195 return GetCurrentUserImageSize(); 1173 return GetCurrentUserImageSize();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 BrowserThread::PostTask( 1360 BrowserThread::PostTask(
1383 BrowserThread::FILE, 1361 BrowserThread::FILE,
1384 FROM_HERE, 1362 FROM_HERE,
1385 base::Bind(&UserManagerImpl::DeleteUserImage, 1363 base::Bind(&UserManagerImpl::DeleteUserImage,
1386 base::Unretained(this), 1364 base::Unretained(this),
1387 image_path)); 1365 image_path));
1388 } 1366 }
1389 } 1367 }
1390 1368
1391 } // namespace chromeos 1369 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698