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

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

Issue 14269004: Add LoginState class to src/chromeos/login (redux) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/policy/browser_policy_connector.h" 36 #include "chrome/browser/policy/browser_policy_connector.h"
37 #include "chrome/browser/prefs/scoped_user_pref_update.h" 37 #include "chrome/browser/prefs/scoped_user_pref_update.h"
38 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
39 #include "chrome/browser/sync/profile_sync_service.h" 39 #include "chrome/browser/sync/profile_sync_service.h"
40 #include "chrome/browser/sync/profile_sync_service_factory.h" 40 #include "chrome/browser/sync/profile_sync_service_factory.h"
41 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_switches.h" 42 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
44 #include "chromeos/chromeos_switches.h" 44 #include "chromeos/chromeos_switches.h"
45 #include "chromeos/cryptohome/async_method_caller.h" 45 #include "chromeos/cryptohome/async_method_caller.h"
46 #include "chromeos/login/login_state.h"
46 #include "content/public/browser/browser_thread.h" 47 #include "content/public/browser/browser_thread.h"
47 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/notification_service.h"
48 #include "google_apis/gaia/gaia_auth_util.h" 49 #include "google_apis/gaia/gaia_auth_util.h"
49 #include "google_apis/gaia/google_service_auth_error.h" 50 #include "google_apis/gaia/google_service_auth_error.h"
50 #include "policy/policy_constants.h" 51 #include "policy/policy_constants.h"
51 52
52 using content::BrowserThread; 53 using content::BrowserThread;
53 54
54 namespace chromeos { 55 namespace chromeos {
55 56
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 merge_session_state_(MERGE_STATUS_NOT_STARTED), 200 merge_session_state_(MERGE_STATUS_NOT_STARTED),
200 observed_sync_service_(NULL), 201 observed_sync_service_(NULL),
201 user_image_manager_(new UserImageManagerImpl) { 202 user_image_manager_(new UserImageManagerImpl) {
202 // UserManager instance should be used only on UI thread. 203 // UserManager instance should be used only on UI thread.
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, 205 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
205 content::NotificationService::AllSources()); 206 content::NotificationService::AllSources());
206 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 207 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
207 content::NotificationService::AllSources()); 208 content::NotificationService::AllSources());
208 RetrieveTrustedDevicePolicies(); 209 RetrieveTrustedDevicePolicies();
210 UpdateLoginState();
209 } 211 }
210 212
211 UserManagerImpl::~UserManagerImpl() { 213 UserManagerImpl::~UserManagerImpl() {
212 // Can't use STLDeleteElements because of the private destructor of User. 214 // Can't use STLDeleteElements because of the private destructor of User.
213 for (UserList::iterator it = users_.begin(); it != users_.end(); 215 for (UserList::iterator it = users_.begin(); it != users_.end();
214 it = users_.erase(it)) { 216 it = users_.erase(it)) {
215 if (active_user_ == *it) 217 if (active_user_ == *it)
216 active_user_ = NULL; 218 active_user_ = NULL;
217 delete *it; 219 delete *it;
218 } 220 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // http://crbug.com/230857 337 // http://crbug.com/230857
336 content::NotificationService::current()->Notify( 338 content::NotificationService::current()->Notify(
337 chrome::NOTIFICATION_ACTIVE_USER_CHANGED, 339 chrome::NOTIFICATION_ACTIVE_USER_CHANGED,
338 content::Source<UserManager>(this), 340 content::Source<UserManager>(this),
339 content::Details<const User>(active_user_)); 341 content::Details<const User>(active_user_));
340 } 342 }
341 343
342 void UserManagerImpl::SessionStarted() { 344 void UserManagerImpl::SessionStarted() {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
344 session_started_ = true; 346 session_started_ = true;
347 UpdateLoginState();
345 content::NotificationService::current()->Notify( 348 content::NotificationService::current()->Notify(
346 chrome::NOTIFICATION_SESSION_STARTED, 349 chrome::NOTIFICATION_SESSION_STARTED,
347 content::Source<UserManager>(this), 350 content::Source<UserManager>(this),
348 content::Details<const User>(active_user_)); 351 content::Details<const User>(active_user_));
349 if (is_current_user_new_) { 352 if (is_current_user_new_) {
350 // Make sure that the new user's data is persisted to Local State. 353 // Make sure that the new user's data is persisted to Local State.
351 g_browser_process->local_state()->CommitPendingWrite(); 354 g_browser_process->local_state()->CommitPendingWrite();
352 } 355 }
353 } 356 }
354 357
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 bool UserManagerImpl::IsCurrentUserOwner() const { 657 bool UserManagerImpl::IsCurrentUserOwner() const {
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
656 base::AutoLock lk(is_current_user_owner_lock_); 659 base::AutoLock lk(is_current_user_owner_lock_);
657 return is_current_user_owner_; 660 return is_current_user_owner_;
658 } 661 }
659 662
660 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { 663 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) {
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
662 base::AutoLock lk(is_current_user_owner_lock_); 665 base::AutoLock lk(is_current_user_owner_lock_);
663 is_current_user_owner_ = is_current_user_owner; 666 is_current_user_owner_ = is_current_user_owner;
667 UpdateLoginState();
664 } 668 }
665 669
666 bool UserManagerImpl::IsCurrentUserNew() const { 670 bool UserManagerImpl::IsCurrentUserNew() const {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
668 return is_current_user_new_; 672 return is_current_user_new_;
669 } 673 }
670 674
671 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { 675 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const {
672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
673 return IsUserLoggedIn() && 677 return IsUserLoggedIn() &&
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 is_current_user_new_ = true; 1077 is_current_user_new_ = true;
1074 active_user_ = User::CreateRetailModeUser(); 1078 active_user_ = User::CreateRetailModeUser();
1075 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, 1079 user_image_manager_->UserLoggedIn(kRetailModeUserEMail,
1076 is_current_user_new_, 1080 is_current_user_new_,
1077 true); 1081 true);
1078 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false); 1082 WallpaperManager::Get()->SetInitialUserWallpaper(kRetailModeUserEMail, false);
1079 } 1083 }
1080 1084
1081 void UserManagerImpl::NotifyOnLogin() { 1085 void UserManagerImpl::NotifyOnLogin() {
1082 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1086 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1087 UpdateLoginState();
1083 content::NotificationService::current()->Notify( 1088 content::NotificationService::current()->Notify(
1084 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 1089 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
1085 content::Source<UserManager>(this), 1090 content::Source<UserManager>(this),
1086 content::Details<const User>(active_user_)); 1091 content::Details<const User>(active_user_));
1087 1092
1088 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 1093 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
1089 1094
1090 // Indicate to DeviceSettingsService that the owner key may have become 1095 // Indicate to DeviceSettingsService that the owner key may have become
1091 // available. 1096 // available.
1092 DeviceSettingsService::Get()->SetUsername(active_user_->email()); 1097 DeviceSettingsService::Get()->SetUsername(active_user_->email());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 content::Source<UserManager>(this), 1391 content::Source<UserManager>(this),
1387 content::NotificationService::NoDetails()); 1392 content::NotificationService::NoDetails());
1388 } 1393 }
1389 1394
1390 void UserManagerImpl::NotifyMergeSessionStateChanged() { 1395 void UserManagerImpl::NotifyMergeSessionStateChanged() {
1391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1392 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, 1397 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_,
1393 MergeSessionStateChanged(merge_session_state_)); 1398 MergeSessionStateChanged(merge_session_state_));
1394 } 1399 }
1395 1400
1401 void UserManagerImpl::UpdateLoginState() {
1402 if (!LoginState::IsInitialized())
1403 return; // LoginState may not be intialized in tests.
1404 LoginState::LoggedInState logged_in_state;
1405 logged_in_state = active_user_ ? LoginState::LOGGED_IN_ACTIVE
1406 : LoginState::LOGGED_IN_NONE;
1407
1408 LoginState::LoggedInUserType login_user_type;
1409 if (logged_in_state == LoginState::LOGGED_IN_NONE)
1410 login_user_type = LoginState::LOGGED_IN_USER_NONE;
1411 else if (is_current_user_owner_)
1412 login_user_type = LoginState::LOGGED_IN_USER_OWNER;
1413 else if (active_user_->GetType() == User::USER_TYPE_GUEST)
1414 login_user_type = LoginState::LOGGED_IN_USER_GUEST;
1415 else if (active_user_->GetType() == User::USER_TYPE_RETAIL_MODE)
1416 login_user_type = LoginState::LOGGED_IN_USER_RETAIL_MODE;
1417 else if (active_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT)
1418 login_user_type = LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT;
1419 else if (active_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED)
1420 login_user_type = LoginState::LOGGED_IN_USER_LOCALLY_MANAGED;
1421 else if (active_user_->GetType() == User::USER_TYPE_KIOSK_APP)
1422 login_user_type = LoginState::LOGGED_IN_USER_KIOSK_APP;
1423 else
1424 login_user_type = LoginState::LOGGED_IN_USER_REGULAR;
1425
1426 LoginState::Get()->SetLoggedInState(logged_in_state, login_user_type);
1427 }
1428
1396 } // namespace chromeos 1429 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | chrome/browser/chromeos/options/wifi_config_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698