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

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

Issue 13495003: Add LoginState class to src/chromeos/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 24 matching lines...) Expand all
35 #include "chrome/browser/chromeos/session_length_limiter.h" 35 #include "chrome/browser/chromeos/session_length_limiter.h"
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/cryptohome/async_method_caller.h" 44 #include "chromeos/cryptohome/async_method_caller.h"
45 #include "chromeos/login/login_state.h"
45 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
46 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
47 #include "google_apis/gaia/gaia_auth_util.h" 48 #include "google_apis/gaia/gaia_auth_util.h"
48 #include "google_apis/gaia/google_service_auth_error.h" 49 #include "google_apis/gaia/google_service_auth_error.h"
49 #include "policy/policy_constants.h" 50 #include "policy/policy_constants.h"
50 51
51 using content::BrowserThread; 52 using content::BrowserThread;
52 53
53 namespace chromeos { 54 namespace chromeos {
54 55
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 merge_session_state_(MERGE_STATUS_NOT_STARTED), 199 merge_session_state_(MERGE_STATUS_NOT_STARTED),
199 observed_sync_service_(NULL), 200 observed_sync_service_(NULL),
200 user_image_manager_(new UserImageManagerImpl) { 201 user_image_manager_(new UserImageManagerImpl) {
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 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, 204 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
204 content::NotificationService::AllSources()); 205 content::NotificationService::AllSources());
205 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 206 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
206 content::NotificationService::AllSources()); 207 content::NotificationService::AllSources());
207 RetrieveTrustedDevicePolicies(); 208 RetrieveTrustedDevicePolicies();
209 UpdateLoginState();
208 } 210 }
209 211
210 UserManagerImpl::~UserManagerImpl() { 212 UserManagerImpl::~UserManagerImpl() {
211 // Can't use STLDeleteElements because of the private destructor of User. 213 // Can't use STLDeleteElements because of the private destructor of User.
212 for (UserList::iterator it = users_.begin(); it != users_.end(); 214 for (UserList::iterator it = users_.begin(); it != users_.end();
213 it = users_.erase(it)) { 215 it = users_.erase(it)) {
214 if (logged_in_user_ == *it) 216 if (logged_in_user_ == *it)
215 logged_in_user_ = NULL; 217 logged_in_user_ = NULL;
216 delete *it; 218 delete *it;
217 } 219 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 is_current_user_new_ = true; 407 is_current_user_new_ = true;
406 is_current_user_ephemeral_regular_user_ = true; 408 is_current_user_ephemeral_regular_user_ = true;
407 logged_in_user_ = User::CreateRegularUser(email); 409 logged_in_user_ = User::CreateRegularUser(email);
408 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); 410 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false);
409 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); 411 WallpaperManager::Get()->SetInitialUserWallpaper(email, false);
410 } 412 }
411 413
412 void UserManagerImpl::SessionStarted() { 414 void UserManagerImpl::SessionStarted() {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 session_started_ = true; 416 session_started_ = true;
417 UpdateLoginState();
415 content::NotificationService::current()->Notify( 418 content::NotificationService::current()->Notify(
416 chrome::NOTIFICATION_SESSION_STARTED, 419 chrome::NOTIFICATION_SESSION_STARTED,
417 content::NotificationService::AllSources(), 420 content::NotificationService::AllSources(),
418 content::NotificationService::NoDetails()); 421 content::NotificationService::NoDetails());
419 if (is_current_user_new_) { 422 if (is_current_user_new_) {
420 // Make sure that the new user's data is persisted to Local State. 423 // Make sure that the new user's data is persisted to Local State.
421 g_browser_process->local_state()->CommitPendingWrite(); 424 g_browser_process->local_state()->CommitPendingWrite();
422 } 425 }
423 } 426 }
424 427
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 bool UserManagerImpl::IsCurrentUserOwner() const { 709 bool UserManagerImpl::IsCurrentUserOwner() const {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708 base::AutoLock lk(is_current_user_owner_lock_); 711 base::AutoLock lk(is_current_user_owner_lock_);
709 return is_current_user_owner_; 712 return is_current_user_owner_;
710 } 713 }
711 714
712 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { 715 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) {
713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 716 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
714 base::AutoLock lk(is_current_user_owner_lock_); 717 base::AutoLock lk(is_current_user_owner_lock_);
715 is_current_user_owner_ = is_current_user_owner; 718 is_current_user_owner_ = is_current_user_owner;
719 UpdateLoginState();
716 } 720 }
717 721
718 bool UserManagerImpl::IsCurrentUserNew() const { 722 bool UserManagerImpl::IsCurrentUserNew() const {
719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
720 return is_current_user_new_; 724 return is_current_user_new_;
721 } 725 }
722 726
723 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { 727 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const {
724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
725 return IsUserLoggedIn() && 729 return IsUserLoggedIn() &&
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 const UserList& users = GetUsers(); 983 const UserList& users = GetUsers();
980 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 984 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
981 if ((*it)->email() == email) 985 if ((*it)->email() == email)
982 return *it; 986 return *it;
983 } 987 }
984 return NULL; 988 return NULL;
985 } 989 }
986 990
987 void UserManagerImpl::NotifyOnLogin() { 991 void UserManagerImpl::NotifyOnLogin() {
988 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 992 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
993 UpdateLoginState();
989 content::NotificationService::current()->Notify( 994 content::NotificationService::current()->Notify(
990 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 995 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
991 content::Source<UserManager>(this), 996 content::Source<UserManager>(this),
992 content::Details<const User>(logged_in_user_)); 997 content::Details<const User>(logged_in_user_));
993 998
994 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); 999 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore();
995 1000
996 // Indicate to DeviceSettingsService that the owner key may have become 1001 // Indicate to DeviceSettingsService that the owner key may have become
997 // available. 1002 // available.
998 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); 1003 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 content::Source<UserManager>(this), 1297 content::Source<UserManager>(this),
1293 content::NotificationService::NoDetails()); 1298 content::NotificationService::NoDetails());
1294 } 1299 }
1295 1300
1296 void UserManagerImpl::NotifyMergeSessionStateChanged() { 1301 void UserManagerImpl::NotifyMergeSessionStateChanged() {
1297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1298 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, 1303 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_,
1299 MergeSessionStateChanged(merge_session_state_)); 1304 MergeSessionStateChanged(merge_session_state_));
1300 } 1305 }
1301 1306
1307 void UserManagerImpl::UpdateLoginState() {
1308 LoginState::State login_state;
1309 if (!IsSessionStarted())
1310 login_state = LoginState::LOGGED_IN_NONE;
1311 else if (IsCurrentUserOwner())
1312 login_state = LoginState::LOGGED_IN_OWNER;
1313 else if (IsLoggedInAsGuest())
1314 login_state = LoginState::LOGGED_IN_GUEST;
1315 else if (IsLoggedInAsDemoUser())
1316 login_state = LoginState::LOGGED_IN_KIOSK_APP;
bartfab (slow) 2013/04/03 08:21:36 Ugh. Does single-app mode really reuse the retail
stevenjb 2013/04/03 17:21:42 I'm not sure I understand the question, but I copi
Nikita (slow) 2013/04/03 17:48:13 I think these two should be separated. DemoUser =
1317 else if (IsLoggedInAsPublicAccount())
1318 login_state = LoginState::LOGGED_IN_PUBLIC;
1319 else
1320 login_state = LoginState::LOGGED_IN_USER;
1321 LoginState::Get()->SetLoginState(login_state);
1322 }
1323
1302 } // namespace chromeos 1324 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698