Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 #include "components/user_manager/user.h" | 66 #include "components/user_manager/user.h" |
| 67 #include "components/user_manager/user_type.h" | 67 #include "components/user_manager/user_type.h" |
| 68 #include "content/public/browser/browser_thread.h" | 68 #include "content/public/browser/browser_thread.h" |
| 69 #include "content/public/browser/notification_service.h" | 69 #include "content/public/browser/notification_service.h" |
| 70 | 70 |
| 71 namespace chromeos { | 71 namespace chromeos { |
| 72 | 72 |
| 73 namespace { | 73 namespace { |
| 74 | 74 |
| 75 void InitLocaleAndInputMethodsForNewUser( | 75 void InitLocaleAndInputMethodsForNewUser( |
| 76 PrefService* prefs, | 76 Profile* profile, |
| 77 const std::string& public_session_locale, | 77 const std::string& public_session_locale, |
| 78 const std::string& public_session_input_method) { | 78 const std::string& public_session_input_method) { |
| 79 PrefService* prefs = profile->GetPrefs(); | |
| 79 std::string locale; | 80 std::string locale; |
| 80 if (!public_session_locale.empty()) { | 81 if (!public_session_locale.empty()) { |
| 81 // If this is a public session and the user chose a |public_session_locale|, | 82 // If this is a public session and the user chose a |public_session_locale|, |
| 82 // write it to |prefs| so that the UI switches to it. | 83 // write it to |prefs| so that the UI switches to it. |
| 83 locale = public_session_locale; | 84 locale = public_session_locale; |
| 84 prefs->SetString(prefs::kApplicationLocale, locale); | 85 prefs->SetString(prefs::kApplicationLocale, locale); |
| 85 | 86 |
| 86 // Suppress the locale change dialog. | 87 // Suppress the locale change dialog. |
| 87 prefs->SetString(prefs::kApplicationLocaleAccepted, locale); | 88 prefs->SetString(prefs::kApplicationLocaleAccepted, locale); |
| 88 } else { | 89 } else { |
| 89 // Otherwise, assume that the session will use the current UI locale. | 90 // Otherwise, assume that the session will use the current UI locale. |
| 90 locale = g_browser_process->GetApplicationLocale(); | 91 locale = g_browser_process->GetApplicationLocale(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 // First, we'll set kLanguagePreloadEngines. | 94 // First, we'll set kLanguagePreloadEngines. |
| 94 input_method::InputMethodManager* manager = | 95 input_method::InputMethodManager* manager = |
| 95 input_method::InputMethodManager::Get(); | 96 input_method::InputMethodManager::Get(); |
| 96 std::vector<std::string> input_method_ids; | 97 std::vector<std::string> input_method_ids; |
| 97 | 98 |
| 98 if (!public_session_input_method.empty()) { | 99 if (!public_session_input_method.empty()) { |
| 99 // If this is a public session and the user chose a | 100 // If this is a public session and the user chose a |
| 100 // |public_session_input_method|, set kLanguagePreloadEngines to this input | 101 // |public_session_input_method|, set kLanguagePreloadEngines to this input |
| 101 // method only. | 102 // method only. |
| 102 input_method_ids.push_back(public_session_input_method); | 103 input_method_ids.push_back(public_session_input_method); |
| 103 } else { | 104 } else { |
| 104 // Otherwise, set kLanguagePreloadEngines to a list of input methods derived | 105 // Otherwise, set kLanguagePreloadEngines to a list of input methods derived |
| 105 // from the |locale| and the currently active input method. | 106 // from the |locale| and the currently active input method. |
| 106 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( | 107 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( |
| 107 locale, manager->GetCurrentInputMethod(), &input_method_ids); | 108 locale, |
| 109 manager->GetDefaultState(profile)->GetCurrentInputMethod(), | |
| 110 &input_method_ids); | |
| 108 } | 111 } |
| 109 | 112 |
| 110 // Save the input methods in the user's preferences. | 113 // Save the input methods in the user's preferences. |
| 111 StringPrefMember language_preload_engines; | 114 StringPrefMember language_preload_engines; |
| 112 language_preload_engines.Init(prefs::kLanguagePreloadEngines, prefs); | 115 language_preload_engines.Init(prefs::kLanguagePreloadEngines, prefs); |
| 113 language_preload_engines.SetValue(JoinString(input_method_ids, ',')); | 116 language_preload_engines.SetValue(JoinString(input_method_ids, ',')); |
| 114 BootTimesLoader::Get()->AddLoginTimeMarker("IMEStarted", false); | 117 BootTimesLoader::Get()->AddLoginTimeMarker("IMEStarted", false); |
| 115 | 118 |
| 116 // Second, we'll set kLanguagePreferredLanguages. | 119 // Second, we'll set kLanguagePreferredLanguages. |
| 117 std::vector<std::string> language_codes; | 120 std::vector<std::string> language_codes; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 } | 214 } |
| 212 | 215 |
| 213 UserSessionManager::UserSessionManager() | 216 UserSessionManager::UserSessionManager() |
| 214 : delegate_(NULL), | 217 : delegate_(NULL), |
| 215 has_auth_cookies_(false), | 218 has_auth_cookies_(false), |
| 216 user_sessions_restored_(false), | 219 user_sessions_restored_(false), |
| 217 exit_after_session_restore_(false), | 220 exit_after_session_restore_(false), |
| 218 session_restore_strategy_( | 221 session_restore_strategy_( |
| 219 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { | 222 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { |
| 220 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 223 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 224 UserManager::Get()->AddSessionStateObserver(this); | |
| 221 } | 225 } |
| 222 | 226 |
| 223 UserSessionManager::~UserSessionManager() { | 227 UserSessionManager::~UserSessionManager() { |
| 228 if (UserManager::IsInitialized()) | |
|
Nikita (slow)
2014/08/13 10:56:41
nit: Please add TODO(nkostylev) comment why this i
Alexander Alekseev
2014/08/13 23:29:32
Done.
| |
| 229 UserManager::Get()->RemoveSessionStateObserver(this); | |
| 224 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 230 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 225 } | 231 } |
| 226 | 232 |
| 227 void UserSessionManager::StartSession( | 233 void UserSessionManager::StartSession( |
| 228 const UserContext& user_context, | 234 const UserContext& user_context, |
| 229 scoped_refptr<Authenticator> authenticator, | 235 scoped_refptr<Authenticator> authenticator, |
| 230 bool has_auth_cookies, | 236 bool has_auth_cookies, |
| 231 bool has_active_session, | 237 bool has_active_session, |
| 232 UserSessionManagerDelegate* delegate) { | 238 UserSessionManagerDelegate* delegate) { |
| 233 authenticator_ = authenticator; | 239 authenticator_ = authenticator; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 #endif | 324 #endif |
| 319 } | 325 } |
| 320 | 326 |
| 321 OAuth2LoginManager::SessionRestoreStrategy | 327 OAuth2LoginManager::SessionRestoreStrategy |
| 322 UserSessionManager::GetSigninSessionRestoreStrategy() { | 328 UserSessionManager::GetSigninSessionRestoreStrategy() { |
| 323 return session_restore_strategy_; | 329 return session_restore_strategy_; |
| 324 } | 330 } |
| 325 | 331 |
| 326 // static | 332 // static |
| 327 void UserSessionManager::SetFirstLoginPrefs( | 333 void UserSessionManager::SetFirstLoginPrefs( |
| 328 PrefService* prefs, | 334 Profile* profile, |
| 329 const std::string& public_session_locale, | 335 const std::string& public_session_locale, |
| 330 const std::string& public_session_input_method) { | 336 const std::string& public_session_input_method) { |
| 331 VLOG(1) << "Setting first login prefs"; | 337 VLOG(1) << "Setting first login prefs"; |
| 332 InitLocaleAndInputMethodsForNewUser(prefs, | 338 InitLocaleAndInputMethodsForNewUser( |
| 333 public_session_locale, | 339 profile, public_session_locale, public_session_input_method); |
| 334 public_session_input_method); | |
| 335 } | 340 } |
| 336 | 341 |
| 337 bool UserSessionManager::GetAppModeChromeClientOAuthInfo( | 342 bool UserSessionManager::GetAppModeChromeClientOAuthInfo( |
| 338 std::string* chrome_client_id, std::string* chrome_client_secret) { | 343 std::string* chrome_client_id, std::string* chrome_client_secret) { |
| 339 if (!chrome::IsRunningInForcedAppMode() || | 344 if (!chrome::IsRunningInForcedAppMode() || |
| 340 chrome_client_id_.empty() || | 345 chrome_client_id_.empty() || |
| 341 chrome_client_secret_.empty()) { | 346 chrome_client_secret_.empty()) { |
| 342 return false; | 347 return false; |
| 343 } | 348 } |
| 344 | 349 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 const bool enable_layouts = UserManager::Get()->IsLoggedInAsGuest(); | 434 const bool enable_layouts = UserManager::Get()->IsLoggedInAsGuest(); |
| 430 locale_util::SwitchLanguage(pref_locale, | 435 locale_util::SwitchLanguage(pref_locale, |
| 431 enable_layouts, | 436 enable_layouts, |
| 432 false /* login_layouts_only */, | 437 false /* login_layouts_only */, |
| 433 callback.Pass()); | 438 callback.Pass()); |
| 434 | 439 |
| 435 return true; | 440 return true; |
| 436 } | 441 } |
| 437 | 442 |
| 438 void UserSessionManager::AddSessionStateObserver( | 443 void UserSessionManager::AddSessionStateObserver( |
| 439 UserSessionStateObserver* observer) { | 444 chromeos::UserSessionStateObserver* observer) { |
| 440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 445 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 441 session_state_observer_list_.AddObserver(observer); | 446 session_state_observer_list_.AddObserver(observer); |
| 442 } | 447 } |
| 443 | 448 |
| 444 void UserSessionManager::RemoveSessionStateObserver( | 449 void UserSessionManager::RemoveSessionStateObserver( |
| 445 UserSessionStateObserver* observer) { | 450 chromeos::UserSessionStateObserver* observer) { |
| 446 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 451 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 447 session_state_observer_list_.RemoveObserver(observer); | 452 session_state_observer_list_.RemoveObserver(observer); |
| 448 } | 453 } |
| 449 | 454 |
| 450 void UserSessionManager::OnSessionRestoreStateChanged( | 455 void UserSessionManager::OnSessionRestoreStateChanged( |
| 451 Profile* user_profile, | 456 Profile* user_profile, |
| 452 OAuth2LoginManager::SessionRestoreState state) { | 457 OAuth2LoginManager::SessionRestoreState state) { |
| 453 user_manager::User::OAuthTokenStatus user_status = | 458 user_manager::User::OAuthTokenStatus user_status = |
| 454 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 459 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 455 OAuth2LoginManager* login_manager = | 460 OAuth2LoginManager* login_manager = |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 case Profile::MAX_CREATE_STATUS: | 639 case Profile::MAX_CREATE_STATUS: |
| 635 NOTREACHED(); | 640 NOTREACHED(); |
| 636 break; | 641 break; |
| 637 } | 642 } |
| 638 } | 643 } |
| 639 | 644 |
| 640 void UserSessionManager::InitProfilePreferences( | 645 void UserSessionManager::InitProfilePreferences( |
| 641 Profile* profile, | 646 Profile* profile, |
| 642 const UserContext& user_context) { | 647 const UserContext& user_context) { |
| 643 if (UserManager::Get()->IsCurrentUserNew()) { | 648 if (UserManager::Get()->IsCurrentUserNew()) { |
| 644 SetFirstLoginPrefs(profile->GetPrefs(), | 649 SetFirstLoginPrefs(profile, |
| 645 user_context.GetPublicSessionLocale(), | 650 user_context.GetPublicSessionLocale(), |
| 646 user_context.GetPublicSessionInputMethod()); | 651 user_context.GetPublicSessionInputMethod()); |
| 647 } | 652 } |
| 648 | 653 |
| 649 if (UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 654 if (UserManager::Get()->IsLoggedInAsSupervisedUser()) { |
| 650 user_manager::User* active_user = UserManager::Get()->GetActiveUser(); | 655 user_manager::User* active_user = UserManager::Get()->GetActiveUser(); |
| 651 std::string supervised_user_sync_id = | 656 std::string supervised_user_sync_id = |
| 652 UserManager::Get()->GetSupervisedUserManager()-> | 657 UserManager::Get()->GetSupervisedUserManager()-> |
| 653 GetUserSyncId(active_user->email()); | 658 GetUserSyncId(active_user->email()); |
| 654 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 659 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 true, // has_active_session | 970 true, // has_active_session |
| 966 this); | 971 this); |
| 967 } else { | 972 } else { |
| 968 RestorePendingUserSessions(); | 973 RestorePendingUserSessions(); |
| 969 } | 974 } |
| 970 } | 975 } |
| 971 | 976 |
| 972 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { | 977 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { |
| 973 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 978 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 974 user_sessions_restored_ = true; | 979 user_sessions_restored_ = true; |
| 975 FOR_EACH_OBSERVER(UserSessionStateObserver, | 980 FOR_EACH_OBSERVER(chromeos::UserSessionStateObserver, |
| 976 session_state_observer_list_, | 981 session_state_observer_list_, |
| 977 PendingUserSessionsRestoreFinished()); | 982 PendingUserSessionsRestoreFinished()); |
| 978 } | 983 } |
| 979 | 984 |
| 985 void UserSessionManager::ActiveUserChanged( | |
| 986 const user_manager::User* active_user) { | |
| 987 input_method::InputMethodManager* manager = | |
| 988 input_method::InputMethodManager::Get(); | |
| 989 manager->SetState(manager->GetDefaultState( | |
| 990 ProfileHelper::Get()->GetProfileByUser(active_user))); | |
| 991 } | |
| 992 | |
| 980 } // namespace chromeos | 993 } // namespace chromeos |
| OLD | NEW |