| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/session/user_session_manager.h" | 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); | 215 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); |
| 216 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); | 216 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); |
| 217 } | 217 } |
| 218 | 218 |
| 219 UserSessionManager::UserSessionManager() | 219 UserSessionManager::UserSessionManager() |
| 220 : delegate_(NULL), | 220 : delegate_(NULL), |
| 221 has_auth_cookies_(false), | 221 has_auth_cookies_(false), |
| 222 user_sessions_restored_(false), | 222 user_sessions_restored_(false), |
| 223 exit_after_session_restore_(false), | 223 exit_after_session_restore_(false), |
| 224 session_restore_strategy_( | 224 session_restore_strategy_( |
| 225 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { | 225 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN), |
| 226 running_easy_unlock_key_ops_(false) { |
| 226 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 227 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 227 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 228 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 228 } | 229 } |
| 229 | 230 |
| 230 UserSessionManager::~UserSessionManager() { | 231 UserSessionManager::~UserSessionManager() { |
| 231 // UserManager is destroyed before singletons, so we need to check if it | 232 // UserManager is destroyed before singletons, so we need to check if it |
| 232 // still exists. | 233 // still exists. |
| 233 // TODO(nkostylev): fix order of destruction of UserManager | 234 // TODO(nkostylev): fix order of destruction of UserManager |
| 234 // / UserSessionManager objects. | 235 // / UserSessionManager objects. |
| 235 if (user_manager::UserManager::IsInitialized()) | 236 if (user_manager::UserManager::IsInitialized()) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const bool enable_layouts = | 436 const bool enable_layouts = |
| 436 user_manager::UserManager::Get()->IsLoggedInAsGuest(); | 437 user_manager::UserManager::Get()->IsLoggedInAsGuest(); |
| 437 locale_util::SwitchLanguage(pref_locale, | 438 locale_util::SwitchLanguage(pref_locale, |
| 438 enable_layouts, | 439 enable_layouts, |
| 439 false /* login_layouts_only */, | 440 false /* login_layouts_only */, |
| 440 callback.Pass()); | 441 callback.Pass()); |
| 441 | 442 |
| 442 return true; | 443 return true; |
| 443 } | 444 } |
| 444 | 445 |
| 446 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { |
| 447 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 448 chromeos::switches::kEnableEasySignin) && |
| 449 !user_context_.GetUserID().empty() && |
| 450 user_context_.GetUserType() == user_manager::USER_TYPE_REGULAR && |
| 451 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); |
| 452 } |
| 453 |
| 454 bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) { |
| 455 if (!running_easy_unlock_key_ops_) |
| 456 return false; |
| 457 |
| 458 // Assumes only one deferred callback is needed. |
| 459 DCHECK(easy_unlock_key_ops_finished_callback_.is_null()); |
| 460 |
| 461 easy_unlock_key_ops_finished_callback_ = callback; |
| 462 return true; |
| 463 } |
| 464 |
| 445 void UserSessionManager::AddSessionStateObserver( | 465 void UserSessionManager::AddSessionStateObserver( |
| 446 chromeos::UserSessionStateObserver* observer) { | 466 chromeos::UserSessionStateObserver* observer) { |
| 447 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 467 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 448 session_state_observer_list_.AddObserver(observer); | 468 session_state_observer_list_.AddObserver(observer); |
| 449 } | 469 } |
| 450 | 470 |
| 451 void UserSessionManager::RemoveSessionStateObserver( | 471 void UserSessionManager::RemoveSessionStateObserver( |
| 452 chromeos::UserSessionStateObserver* observer) { | 472 chromeos::UserSessionStateObserver* observer) { |
| 453 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 473 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 454 session_state_observer_list_.RemoveObserver(observer); | 474 session_state_observer_list_.RemoveObserver(observer); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 799 |
| 780 // Initialize various services only for primary user. | 800 // Initialize various services only for primary user. |
| 781 const user_manager::User* user = | 801 const user_manager::User* user = |
| 782 ProfileHelper::Get()->GetUserByProfile(profile); | 802 ProfileHelper::Get()->GetUserByProfile(profile); |
| 783 if (user_manager->GetPrimaryUser() == user) { | 803 if (user_manager->GetPrimaryUser() == user) { |
| 784 InitRlz(profile); | 804 InitRlz(profile); |
| 785 InitializeCerts(profile); | 805 InitializeCerts(profile); |
| 786 InitializeCRLSetFetcher(user); | 806 InitializeCRLSetFetcher(user); |
| 787 } | 807 } |
| 788 | 808 |
| 809 UpdateEasyUnlockKeys(profile); |
| 810 user_context_.ClearSecrets(); |
| 811 |
| 789 // TODO(nkostylev): This pointer should probably never be NULL, but it looks | 812 // TODO(nkostylev): This pointer should probably never be NULL, but it looks |
| 790 // like LoginUtilsImpl::OnProfileCreated() may be getting called before | 813 // like LoginUtilsImpl::OnProfileCreated() may be getting called before |
| 791 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is | 814 // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is |
| 792 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace | 815 // killed during shutdown in tests -- see http://crosbug.com/18269. Replace |
| 793 // this 'if' statement with a CHECK(delegate_) once the underlying issue is | 816 // this 'if' statement with a CHECK(delegate_) once the underlying issue is |
| 794 // resolved. | 817 // resolved. |
| 795 if (delegate_) | 818 if (delegate_) |
| 796 delegate_->OnProfilePrepared(profile); | 819 delegate_->OnProfilePrepared(profile); |
| 797 | |
| 798 UpdateEasyUnlockKeys(profile); | |
| 799 user_context_.ClearSecrets(); | |
| 800 } | 820 } |
| 801 | 821 |
| 802 void UserSessionManager::InitSessionRestoreStrategy() { | 822 void UserSessionManager::InitSessionRestoreStrategy() { |
| 803 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 823 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 804 bool in_app_mode = chrome::IsRunningInForcedAppMode(); | 824 bool in_app_mode = chrome::IsRunningInForcedAppMode(); |
| 805 | 825 |
| 806 // Are we in kiosk app mode? | 826 // Are we in kiosk app mode? |
| 807 if (in_app_mode) { | 827 if (in_app_mode) { |
| 808 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { | 828 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { |
| 809 oauth2_refresh_token_ = command_line->GetSwitchValueASCII( | 829 oauth2_refresh_token_ = command_line->GetSwitchValueASCII( |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 | 1033 |
| 1014 // |user_context_| and |user_profile| must belong to the same user. | 1034 // |user_context_| and |user_profile| must belong to the same user. |
| 1015 DCHECK_EQ(SigninManagerFactory::GetForProfile(user_profile) | 1035 DCHECK_EQ(SigninManagerFactory::GetForProfile(user_profile) |
| 1016 ->GetAuthenticatedAccountId(), | 1036 ->GetAuthenticatedAccountId(), |
| 1017 user_context_.GetUserID()); | 1037 user_context_.GetUserID()); |
| 1018 | 1038 |
| 1019 const base::ListValue* device_list = NULL; | 1039 const base::ListValue* device_list = NULL; |
| 1020 if (EasyUnlockService::Get(user_profile)) | 1040 if (EasyUnlockService::Get(user_profile)) |
| 1021 device_list = EasyUnlockService::Get(user_profile)->GetRemoteDevices(); | 1041 device_list = EasyUnlockService::Get(user_profile)->GetRemoteDevices(); |
| 1022 | 1042 |
| 1043 running_easy_unlock_key_ops_ = true; |
| 1023 if (device_list) { | 1044 if (device_list) { |
| 1024 easy_unlock_key_manager_->RefreshKeys( | 1045 easy_unlock_key_manager_->RefreshKeys( |
| 1025 user_context_, | 1046 user_context_, |
| 1026 *device_list, | 1047 *device_list, |
| 1027 EasyUnlockKeyManager::RefreshKeysCallback()); | 1048 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, |
| 1049 AsWeakPtr())); |
| 1028 } else { | 1050 } else { |
| 1029 easy_unlock_key_manager_->RemoveKeys( | 1051 easy_unlock_key_manager_->RemoveKeys( |
| 1030 user_context_, 0, EasyUnlockKeyManager::RemoveKeysCallback()); | 1052 user_context_, |
| 1053 0, |
| 1054 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, |
| 1055 AsWeakPtr())); |
| 1031 } | 1056 } |
| 1032 } | 1057 } |
| 1033 | 1058 |
| 1059 void UserSessionManager::OnEasyUnlockKeyOpsFinished(bool success) { |
| 1060 running_easy_unlock_key_ops_ = false; |
| 1061 if (!easy_unlock_key_ops_finished_callback_.is_null()) |
| 1062 easy_unlock_key_ops_finished_callback_.Run(); |
| 1063 } |
| 1064 |
| 1034 void UserSessionManager::ActiveUserChanged( | 1065 void UserSessionManager::ActiveUserChanged( |
| 1035 const user_manager::User* active_user) { | 1066 const user_manager::User* active_user) { |
| 1036 Profile* profile = ProfileHelper::Get()->GetProfileByUser(active_user); | 1067 Profile* profile = ProfileHelper::Get()->GetProfileByUser(active_user); |
| 1037 // If profile has not yet been initialized, delay initialization of IME. | 1068 // If profile has not yet been initialized, delay initialization of IME. |
| 1038 if (!profile) | 1069 if (!profile) |
| 1039 return; | 1070 return; |
| 1040 | 1071 |
| 1041 input_method::InputMethodManager* manager = | 1072 input_method::InputMethodManager* manager = |
| 1042 input_method::InputMethodManager::Get(); | 1073 input_method::InputMethodManager::Get(); |
| 1043 manager->SetState( | 1074 manager->SetState( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1062 return NULL; | 1093 return NULL; |
| 1063 } | 1094 } |
| 1064 | 1095 |
| 1065 if (!easy_unlock_key_manager_) | 1096 if (!easy_unlock_key_manager_) |
| 1066 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); | 1097 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); |
| 1067 | 1098 |
| 1068 return easy_unlock_key_manager_.get(); | 1099 return easy_unlock_key_manager_.get(); |
| 1069 } | 1100 } |
| 1070 | 1101 |
| 1071 } // namespace chromeos | 1102 } // namespace chromeos |
| OLD | NEW |