| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 (logged_in_user_ == *it) | 217 if (logged_in_user_ == *it) |
| 216 logged_in_user_ = NULL; | 218 logged_in_user_ = NULL; |
| 217 delete *it; | 219 delete *it; |
| 218 } | 220 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 is_current_user_new_ = true; | 408 is_current_user_new_ = true; |
| 407 is_current_user_ephemeral_regular_user_ = true; | 409 is_current_user_ephemeral_regular_user_ = true; |
| 408 logged_in_user_ = User::CreateRegularUser(email); | 410 logged_in_user_ = User::CreateRegularUser(email); |
| 409 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); | 411 user_image_manager_->UserLoggedIn(email, is_current_user_new_, false); |
| 410 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); | 412 WallpaperManager::Get()->SetInitialUserWallpaper(email, false); |
| 411 } | 413 } |
| 412 | 414 |
| 413 void UserManagerImpl::SessionStarted() { | 415 void UserManagerImpl::SessionStarted() { |
| 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 415 session_started_ = true; | 417 session_started_ = true; |
| 418 UpdateLoginState(); |
| 416 content::NotificationService::current()->Notify( | 419 content::NotificationService::current()->Notify( |
| 417 chrome::NOTIFICATION_SESSION_STARTED, | 420 chrome::NOTIFICATION_SESSION_STARTED, |
| 418 content::NotificationService::AllSources(), | 421 content::NotificationService::AllSources(), |
| 419 content::NotificationService::NoDetails()); | 422 content::NotificationService::NoDetails()); |
| 420 if (is_current_user_new_) { | 423 if (is_current_user_new_) { |
| 421 // Make sure that the new user's data is persisted to Local State. | 424 // Make sure that the new user's data is persisted to Local State. |
| 422 g_browser_process->local_state()->CommitPendingWrite(); | 425 g_browser_process->local_state()->CommitPendingWrite(); |
| 423 } | 426 } |
| 424 } | 427 } |
| 425 | 428 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 bool UserManagerImpl::IsCurrentUserOwner() const { | 710 bool UserManagerImpl::IsCurrentUserOwner() const { |
| 708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 709 base::AutoLock lk(is_current_user_owner_lock_); | 712 base::AutoLock lk(is_current_user_owner_lock_); |
| 710 return is_current_user_owner_; | 713 return is_current_user_owner_; |
| 711 } | 714 } |
| 712 | 715 |
| 713 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { | 716 void UserManagerImpl::SetCurrentUserIsOwner(bool is_current_user_owner) { |
| 714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 715 base::AutoLock lk(is_current_user_owner_lock_); | 718 base::AutoLock lk(is_current_user_owner_lock_); |
| 716 is_current_user_owner_ = is_current_user_owner; | 719 is_current_user_owner_ = is_current_user_owner; |
| 720 UpdateLoginState(); |
| 717 } | 721 } |
| 718 | 722 |
| 719 bool UserManagerImpl::IsCurrentUserNew() const { | 723 bool UserManagerImpl::IsCurrentUserNew() const { |
| 720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 721 return is_current_user_new_; | 725 return is_current_user_new_; |
| 722 } | 726 } |
| 723 | 727 |
| 724 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { | 728 bool UserManagerImpl::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| 725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 726 return IsUserLoggedIn() && | 730 return IsUserLoggedIn() && |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 const UserList& users = GetUsers(); | 984 const UserList& users = GetUsers(); |
| 981 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 985 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 982 if ((*it)->email() == email) | 986 if ((*it)->email() == email) |
| 983 return *it; | 987 return *it; |
| 984 } | 988 } |
| 985 return NULL; | 989 return NULL; |
| 986 } | 990 } |
| 987 | 991 |
| 988 void UserManagerImpl::NotifyOnLogin() { | 992 void UserManagerImpl::NotifyOnLogin() { |
| 989 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 993 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 994 UpdateLoginState(); |
| 990 content::NotificationService::current()->Notify( | 995 content::NotificationService::current()->Notify( |
| 991 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 996 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 992 content::Source<UserManager>(this), | 997 content::Source<UserManager>(this), |
| 993 content::Details<const User>(logged_in_user_)); | 998 content::Details<const User>(logged_in_user_)); |
| 994 | 999 |
| 995 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); | 1000 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); |
| 996 | 1001 |
| 997 // Indicate to DeviceSettingsService that the owner key may have become | 1002 // Indicate to DeviceSettingsService that the owner key may have become |
| 998 // available. | 1003 // available. |
| 999 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); | 1004 DeviceSettingsService::Get()->SetUsername(logged_in_user_->email()); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 content::Source<UserManager>(this), | 1298 content::Source<UserManager>(this), |
| 1294 content::NotificationService::NoDetails()); | 1299 content::NotificationService::NoDetails()); |
| 1295 } | 1300 } |
| 1296 | 1301 |
| 1297 void UserManagerImpl::NotifyMergeSessionStateChanged() { | 1302 void UserManagerImpl::NotifyMergeSessionStateChanged() { |
| 1298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1299 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 1304 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, |
| 1300 MergeSessionStateChanged(merge_session_state_)); | 1305 MergeSessionStateChanged(merge_session_state_)); |
| 1301 } | 1306 } |
| 1302 | 1307 |
| 1308 void UserManagerImpl::UpdateLoginState() { |
| 1309 if (!LoginState::IsInitialized()) |
| 1310 return; // LoginState may not be intialized in tests. |
| 1311 LoginState::State login_state; |
| 1312 if (!logged_in_user_ || !session_started_) |
| 1313 login_state = LoginState::LOGGED_IN_NONE; |
| 1314 else if (is_current_user_owner_) |
| 1315 login_state = LoginState::LOGGED_IN_OWNER; |
| 1316 else if (logged_in_user_->GetType() == User::USER_TYPE_GUEST) |
| 1317 login_state = LoginState::LOGGED_IN_GUEST; |
| 1318 else if (logged_in_user_->GetType() == User::USER_TYPE_RETAIL_MODE) |
| 1319 login_state = LoginState::LOGGED_IN_RETAIL_MODE; |
| 1320 else if (logged_in_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) |
| 1321 login_state = LoginState::LOGGED_IN_PUBLIC; |
| 1322 else if (logged_in_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED) |
| 1323 login_state = LoginState::LOGGED_IN_LOCALLY_MANAGED; |
| 1324 else if (logged_in_user_->GetType() == User::USER_TYPE_KIOSK_APP) |
| 1325 login_state = LoginState::LOGGED_IN_KIOSK_APP; |
| 1326 else |
| 1327 login_state = LoginState::LOGGED_IN_USER; |
| 1328 LoginState::Get()->SetLoginState(login_state); |
| 1329 LoginState::Get()->SetSessionStarted(session_started_); |
| 1330 } |
| 1331 |
| 1303 } // namespace chromeos | 1332 } // namespace chromeos |
| OLD | NEW |