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

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, remove blocking GetOwnershipStatus() Created 8 years, 4 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 17 matching lines...) Expand all
28 #include "chrome/browser/chromeos/cros/cros_library.h" 28 #include "chrome/browser/chromeos/cros/cros_library.h"
29 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" 29 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h"
30 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 30 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
31 #include "chrome/browser/chromeos/login/default_user_images.h" 31 #include "chrome/browser/chromeos/login/default_user_images.h"
32 #include "chrome/browser/chromeos/login/helper.h" 32 #include "chrome/browser/chromeos/login/helper.h"
33 #include "chrome/browser/chromeos/login/login_display.h" 33 #include "chrome/browser/chromeos/login/login_display.h"
34 #include "chrome/browser/chromeos/login/remove_user_delegate.h" 34 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
35 #include "chrome/browser/chromeos/login/user_image.h" 35 #include "chrome/browser/chromeos/login/user_image.h"
36 #include "chrome/browser/chromeos/login/wizard_controller.h" 36 #include "chrome/browser/chromeos/login/wizard_controller.h"
37 #include "chrome/browser/chromeos/settings/cros_settings.h" 37 #include "chrome/browser/chromeos/settings/cros_settings.h"
38 #include "chrome/browser/chromeos/settings/ownership_service.h"
39 #include "chrome/browser/policy/browser_policy_connector.h" 38 #include "chrome/browser/policy/browser_policy_connector.h"
40 #include "chrome/browser/prefs/pref_service.h" 39 #include "chrome/browser/prefs/pref_service.h"
41 #include "chrome/browser/prefs/scoped_user_pref_update.h" 40 #include "chrome/browser/prefs/scoped_user_pref_update.h"
42 #include "chrome/browser/profiles/profile_downloader.h" 41 #include "chrome/browser/profiles/profile_downloader.h"
43 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
44 #include "chrome/browser/sync/profile_sync_service.h" 43 #include "chrome/browser/sync/profile_sync_service.h"
45 #include "chrome/browser/sync/profile_sync_service_factory.h" 44 #include "chrome/browser/sync/profile_sync_service_factory.h"
46 #include "chrome/browser/ui/webui/web_ui_util.h" 45 #include "chrome/browser/ui/webui/web_ui_util.h"
47 #include "chrome/common/chrome_notification_types.h" 46 #include "chrome/common/chrome_notification_types.h"
48 #include "chrome/common/chrome_paths.h" 47 #include "chrome/common/chrome_paths.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 is_current_user_ephemeral_(false), 194 is_current_user_ephemeral_(false),
196 ephemeral_users_enabled_(false), 195 ephemeral_users_enabled_(false),
197 observed_sync_service_(NULL), 196 observed_sync_service_(NULL),
198 last_image_set_async_(false), 197 last_image_set_async_(false),
199 downloaded_profile_image_data_url_(chrome::kAboutBlankURL), 198 downloaded_profile_image_data_url_(chrome::kAboutBlankURL),
200 downloading_profile_image_(false) { 199 downloading_profile_image_(false) {
201 // UserManager instance should be used only on UI thread. 200 // UserManager instance should be used only on UI thread.
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
203 202
204 MigrateWallpaperData(); 203 MigrateWallpaperData();
205 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 204 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
206 content::NotificationService::AllSources()); 205 content::NotificationService::AllSources());
207 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 206 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
208 content::NotificationService::AllSources()); 207 content::NotificationService::AllSources());
209 RetrieveTrustedDevicePolicies(); 208 RetrieveTrustedDevicePolicies();
210 } 209 }
211 210
212 UserManagerImpl::~UserManagerImpl() { 211 UserManagerImpl::~UserManagerImpl() {
213 // Can't use STLDeleteElements because of the private destructor of User. 212 // Can't use STLDeleteElements because of the private destructor of User.
214 for (size_t i = 0; i < users_.size();++i) 213 for (size_t i = 0; i < users_.size(); ++i)
215 delete users_[i]; 214 delete users_[i];
216 users_.clear(); 215 users_.clear();
217 if (is_current_user_ephemeral_) 216 if (is_current_user_ephemeral_)
218 delete logged_in_user_; 217 delete logged_in_user_;
219 } 218 }
220 219
221 const UserList& UserManagerImpl::GetUsers() const { 220 const UserList& UserManagerImpl::GetUsers() const {
222 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); 221 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded();
223 return users_; 222 return users_;
224 } 223 }
(...skipping 353 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 SkBitmap& UserManagerImpl::DownloadedProfileImage() const { 683 const SkBitmap& 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 885
893 void UserManagerImpl::NotifyOnLogin() { 886 void UserManagerImpl::NotifyOnLogin() {
894 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 887 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
895 content::NotificationService::current()->Notify( 888 content::NotificationService::current()->Notify(
896 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 889 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
897 content::Source<UserManagerImpl>(this), 890 content::Source<UserManagerImpl>(this),
898 content::Details<const User>(logged_in_user_)); 891 content::Details<const User>(logged_in_user_));
899 892
900 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 893 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
901 894
902 // Schedules current user ownership check on file thread. 895 // Indicate to DeviceSettingsService that the owner key may have become
903 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 896 // available.
904 base::Bind(&UserManagerImpl::CheckOwnership, 897 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email());
905 base::Unretained(this)));
906 } 898 }
907 899
908 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 900 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
909 // Choose a random default image. 901 // Choose a random default image.
910 int image_id = base::RandInt(0, kDefaultImagesCount - 1); 902 int image_id = base::RandInt(0, kDefaultImagesCount - 1);
911 SaveUserDefaultImageIndex(username, image_id); 903 SaveUserDefaultImageIndex(username, image_id);
912 } 904 }
913 905
914 void UserManagerImpl::MigrateWallpaperData() { 906 void UserManagerImpl::MigrateWallpaperData() {
915 PrefService* local_state = g_browser_process->local_state(); 907 PrefService* local_state = g_browser_process->local_state();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 } 1137 }
1146 1138
1147 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) { 1139 void UserManagerImpl::DeleteUserImage(const FilePath& image_path) {
1148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1149 if (!file_util::Delete(image_path, false)) { 1141 if (!file_util::Delete(image_path, false)) {
1150 LOG(ERROR) << "Failed to remove user image."; 1142 LOG(ERROR) << "Failed to remove user image.";
1151 return; 1143 return;
1152 } 1144 }
1153 } 1145 }
1154 1146
1155 void UserManagerImpl::UpdateOwnership(bool is_owner) { 1147 void UserManagerImpl::UpdateOwnership(
1156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1148 DeviceSettingsService::OwnershipStatus status,
1149 bool is_owner) {
1150 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1157 1151
1158 SetCurrentUserIsOwner(is_owner); 1152 SetCurrentUserIsOwner(is_owner);
1159 content::NotificationService::current()->Notify(
1160 chrome::NOTIFICATION_OWNERSHIP_CHECKED,
1161 content::NotificationService::AllSources(),
1162 content::NotificationService::NoDetails());
1163 if (is_owner) {
1164 // Also update cached value.
1165 CrosSettings::Get()->SetString(kDeviceOwner, GetLoggedInUser().email());
1166 }
1167 } 1153 }
1168 1154
1169 void UserManagerImpl::CheckOwnership() { 1155 void UserManagerImpl::CheckOwnership() {
1170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1156 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
1171 bool is_owner = OwnershipService::GetSharedInstance()->IsCurrentUserOwner();
1172 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1173
1174 // UserManagerImpl should be accessed only on UI thread.
1175 BrowserThread::PostTask(
1176 BrowserThread::UI,
1177 FROM_HERE,
1178 base::Bind(&UserManagerImpl::UpdateOwnership, 1157 base::Bind(&UserManagerImpl::UpdateOwnership,
1179 base::Unretained(this), 1158 base::Unretained(this)));
1180 is_owner));
1181 } 1159 }
1182 1160
1183 // ProfileDownloaderDelegate override. 1161 // ProfileDownloaderDelegate override.
1184 bool UserManagerImpl::NeedsProfilePicture() const { 1162 bool UserManagerImpl::NeedsProfilePicture() const {
1185 return downloading_profile_image_; 1163 return downloading_profile_image_;
1186 } 1164 }
1187 1165
1188 // ProfileDownloaderDelegate override. 1166 // ProfileDownloaderDelegate override.
1189 int UserManagerImpl::GetDesiredImageSideLength() const { 1167 int UserManagerImpl::GetDesiredImageSideLength() const {
1190 return GetCurrentUserImageSize(); 1168 return GetCurrentUserImageSize();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 BrowserThread::PostTask( 1350 BrowserThread::PostTask(
1373 BrowserThread::FILE, 1351 BrowserThread::FILE,
1374 FROM_HERE, 1352 FROM_HERE,
1375 base::Bind(&UserManagerImpl::DeleteUserImage, 1353 base::Bind(&UserManagerImpl::DeleteUserImage,
1376 base::Unretained(this), 1354 base::Unretained(this),
1377 image_path)); 1355 image_path));
1378 } 1356 }
1379 } 1357 }
1380 1358
1381 } // namespace chromeos 1359 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698