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

Side by Side Diff: chrome/browser/chromeos/login/session/user_session_manager.cc

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixed. Re-sorted methods of StateImpl and IMM. Created 6 years, 4 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
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "components/user_manager/user_manager.h" 67 #include "components/user_manager/user_manager.h"
68 #include "components/user_manager/user_type.h" 68 #include "components/user_manager/user_type.h"
69 #include "content/public/browser/browser_thread.h" 69 #include "content/public/browser/browser_thread.h"
70 #include "content/public/browser/notification_service.h" 70 #include "content/public/browser/notification_service.h"
71 71
72 namespace chromeos { 72 namespace chromeos {
73 73
74 namespace { 74 namespace {
75 75
76 void InitLocaleAndInputMethodsForNewUser( 76 void InitLocaleAndInputMethodsForNewUser(
77 PrefService* prefs, 77 UserSessionManager* session_manager,
78 Profile* profile,
78 const std::string& public_session_locale, 79 const std::string& public_session_locale,
79 const std::string& public_session_input_method) { 80 const std::string& public_session_input_method) {
81 PrefService* prefs = profile->GetPrefs();
80 std::string locale; 82 std::string locale;
81 if (!public_session_locale.empty()) { 83 if (!public_session_locale.empty()) {
82 // If this is a public session and the user chose a |public_session_locale|, 84 // If this is a public session and the user chose a |public_session_locale|,
83 // write it to |prefs| so that the UI switches to it. 85 // write it to |prefs| so that the UI switches to it.
84 locale = public_session_locale; 86 locale = public_session_locale;
85 prefs->SetString(prefs::kApplicationLocale, locale); 87 prefs->SetString(prefs::kApplicationLocale, locale);
86 88
87 // Suppress the locale change dialog. 89 // Suppress the locale change dialog.
88 prefs->SetString(prefs::kApplicationLocaleAccepted, locale); 90 prefs->SetString(prefs::kApplicationLocaleAccepted, locale);
89 } else { 91 } else {
90 // Otherwise, assume that the session will use the current UI locale. 92 // Otherwise, assume that the session will use the current UI locale.
91 locale = g_browser_process->GetApplicationLocale(); 93 locale = g_browser_process->GetApplicationLocale();
92 } 94 }
93 95
94 // First, we'll set kLanguagePreloadEngines. 96 // First, we'll set kLanguagePreloadEngines.
95 input_method::InputMethodManager* manager = 97 input_method::InputMethodManager* manager =
96 input_method::InputMethodManager::Get(); 98 input_method::InputMethodManager::Get();
97 std::vector<std::string> input_method_ids; 99 std::vector<std::string> input_method_ids;
98 100
99 if (!public_session_input_method.empty()) { 101 if (!public_session_input_method.empty()) {
100 // If this is a public session and the user chose a 102 // If this is a public session and the user chose a
101 // |public_session_input_method|, set kLanguagePreloadEngines to this input 103 // |public_session_input_method|, set kLanguagePreloadEngines to this input
102 // method only. 104 // method only.
103 input_method_ids.push_back(public_session_input_method); 105 input_method_ids.push_back(public_session_input_method);
104 } else { 106 } else {
105 // Otherwise, set kLanguagePreloadEngines to a list of input methods derived 107 // Otherwise, set kLanguagePreloadEngines to a list of input methods derived
106 // from the |locale| and the currently active input method. 108 // from the |locale| and the currently active input method.
107 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( 109 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds(
108 locale, manager->GetCurrentInputMethod(), &input_method_ids); 110 locale,
111 session_manager->GetDefaultIMEState(profile)->GetCurrentInputMethod(),
112 &input_method_ids);
109 } 113 }
110 114
111 // Save the input methods in the user's preferences. 115 // Save the input methods in the user's preferences.
112 StringPrefMember language_preload_engines; 116 StringPrefMember language_preload_engines;
113 language_preload_engines.Init(prefs::kLanguagePreloadEngines, prefs); 117 language_preload_engines.Init(prefs::kLanguagePreloadEngines, prefs);
114 language_preload_engines.SetValue(JoinString(input_method_ids, ',')); 118 language_preload_engines.SetValue(JoinString(input_method_ids, ','));
115 BootTimesLoader::Get()->AddLoginTimeMarker("IMEStarted", false); 119 BootTimesLoader::Get()->AddLoginTimeMarker("IMEStarted", false);
116 120
117 // Second, we'll set kLanguagePreferredLanguages. 121 // Second, we'll set kLanguagePreferredLanguages.
118 std::vector<std::string> language_codes; 122 std::vector<std::string> language_codes;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 216 }
213 217
214 UserSessionManager::UserSessionManager() 218 UserSessionManager::UserSessionManager()
215 : delegate_(NULL), 219 : delegate_(NULL),
216 has_auth_cookies_(false), 220 has_auth_cookies_(false),
217 user_sessions_restored_(false), 221 user_sessions_restored_(false),
218 exit_after_session_restore_(false), 222 exit_after_session_restore_(false),
219 session_restore_strategy_( 223 session_restore_strategy_(
220 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { 224 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) {
221 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 225 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
226 user_manager::UserManager::Get()->AddSessionStateObserver(this);
222 } 227 }
223 228
224 UserSessionManager::~UserSessionManager() { 229 UserSessionManager::~UserSessionManager() {
230 // UserManager is destroyed before singletons, so we need to check if it
231 // still exists.
232 // TODO(nkostylev): fix order of destruction of UserManager
233 // / UserSessionManager objects.
234 if (user_manager::UserManager::IsInitialized())
235 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
225 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 236 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
226 } 237 }
227 238
228 void UserSessionManager::StartSession( 239 void UserSessionManager::StartSession(
229 const UserContext& user_context, 240 const UserContext& user_context,
230 scoped_refptr<Authenticator> authenticator, 241 scoped_refptr<Authenticator> authenticator,
231 bool has_auth_cookies, 242 bool has_auth_cookies,
232 bool has_active_session, 243 bool has_active_session,
233 UserSessionManagerDelegate* delegate) { 244 UserSessionManagerDelegate* delegate) {
234 authenticator_ = authenticator; 245 authenticator_ = authenticator;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()), 328 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()),
318 base::Bind(&UserSessionManager::InitRlzImpl, AsWeakPtr(), profile)); 329 base::Bind(&UserSessionManager::InitRlzImpl, AsWeakPtr(), profile));
319 #endif 330 #endif
320 } 331 }
321 332
322 OAuth2LoginManager::SessionRestoreStrategy 333 OAuth2LoginManager::SessionRestoreStrategy
323 UserSessionManager::GetSigninSessionRestoreStrategy() { 334 UserSessionManager::GetSigninSessionRestoreStrategy() {
324 return session_restore_strategy_; 335 return session_restore_strategy_;
325 } 336 }
326 337
327 // static
328 void UserSessionManager::SetFirstLoginPrefs( 338 void UserSessionManager::SetFirstLoginPrefs(
329 PrefService* prefs, 339 Profile* profile,
330 const std::string& public_session_locale, 340 const std::string& public_session_locale,
331 const std::string& public_session_input_method) { 341 const std::string& public_session_input_method) {
332 VLOG(1) << "Setting first login prefs"; 342 VLOG(1) << "Setting first login prefs";
333 InitLocaleAndInputMethodsForNewUser(prefs, 343 InitLocaleAndInputMethodsForNewUser(
334 public_session_locale, 344 this, profile, public_session_locale, public_session_input_method);
335 public_session_input_method);
336 } 345 }
337 346
338 bool UserSessionManager::GetAppModeChromeClientOAuthInfo( 347 bool UserSessionManager::GetAppModeChromeClientOAuthInfo(
339 std::string* chrome_client_id, std::string* chrome_client_secret) { 348 std::string* chrome_client_id, std::string* chrome_client_secret) {
340 if (!chrome::IsRunningInForcedAppMode() || 349 if (!chrome::IsRunningInForcedAppMode() ||
341 chrome_client_id_.empty() || 350 chrome_client_id_.empty() ||
342 chrome_client_secret_.empty()) { 351 chrome_client_secret_.empty()) {
343 return false; 352 return false;
344 } 353 }
345 354
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 user_manager::UserManager::Get()->IsLoggedInAsGuest(); 440 user_manager::UserManager::Get()->IsLoggedInAsGuest();
432 locale_util::SwitchLanguage(pref_locale, 441 locale_util::SwitchLanguage(pref_locale,
433 enable_layouts, 442 enable_layouts,
434 false /* login_layouts_only */, 443 false /* login_layouts_only */,
435 callback.Pass()); 444 callback.Pass());
436 445
437 return true; 446 return true;
438 } 447 }
439 448
440 void UserSessionManager::AddSessionStateObserver( 449 void UserSessionManager::AddSessionStateObserver(
441 UserSessionStateObserver* observer) { 450 chromeos::UserSessionStateObserver* observer) {
442 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 451 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
443 session_state_observer_list_.AddObserver(observer); 452 session_state_observer_list_.AddObserver(observer);
444 } 453 }
445 454
446 void UserSessionManager::RemoveSessionStateObserver( 455 void UserSessionManager::RemoveSessionStateObserver(
447 UserSessionStateObserver* observer) { 456 chromeos::UserSessionStateObserver* observer) {
448 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 457 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
449 session_state_observer_list_.RemoveObserver(observer); 458 session_state_observer_list_.RemoveObserver(observer);
450 } 459 }
451 460
452 void UserSessionManager::OnSessionRestoreStateChanged( 461 void UserSessionManager::OnSessionRestoreStateChanged(
453 Profile* user_profile, 462 Profile* user_profile,
454 OAuth2LoginManager::SessionRestoreState state) { 463 OAuth2LoginManager::SessionRestoreState state) {
455 user_manager::User::OAuthTokenStatus user_status = 464 user_manager::User::OAuthTokenStatus user_status =
456 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; 465 user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN;
457 OAuth2LoginManager* login_manager = 466 OAuth2LoginManager* login_manager =
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 case Profile::MAX_CREATE_STATUS: 645 case Profile::MAX_CREATE_STATUS:
637 NOTREACHED(); 646 NOTREACHED();
638 break; 647 break;
639 } 648 }
640 } 649 }
641 650
642 void UserSessionManager::InitProfilePreferences( 651 void UserSessionManager::InitProfilePreferences(
643 Profile* profile, 652 Profile* profile,
644 const UserContext& user_context) { 653 const UserContext& user_context) {
645 if (user_manager::UserManager::Get()->IsCurrentUserNew()) { 654 if (user_manager::UserManager::Get()->IsCurrentUserNew()) {
646 SetFirstLoginPrefs(profile->GetPrefs(), 655 SetFirstLoginPrefs(profile,
647 user_context.GetPublicSessionLocale(), 656 user_context.GetPublicSessionLocale(),
648 user_context.GetPublicSessionInputMethod()); 657 user_context.GetPublicSessionInputMethod());
649 } 658 }
650 659
651 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { 660 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
652 user_manager::User* active_user = 661 user_manager::User* active_user =
653 user_manager::UserManager::Get()->GetActiveUser(); 662 user_manager::UserManager::Get()->GetActiveUser();
654 std::string supervised_user_sync_id = 663 std::string supervised_user_sync_id =
655 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( 664 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
656 active_user->email()); 665 active_user->email());
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 true, // has_active_session 979 true, // has_active_session
971 this); 980 this);
972 } else { 981 } else {
973 RestorePendingUserSessions(); 982 RestorePendingUserSessions();
974 } 983 }
975 } 984 }
976 985
977 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { 986 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() {
978 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 987 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
979 user_sessions_restored_ = true; 988 user_sessions_restored_ = true;
980 FOR_EACH_OBSERVER(UserSessionStateObserver, 989 FOR_EACH_OBSERVER(chromeos::UserSessionStateObserver,
981 session_state_observer_list_, 990 session_state_observer_list_,
982 PendingUserSessionsRestoreFinished()); 991 PendingUserSessionsRestoreFinished());
983 } 992 }
984 993
994 void UserSessionManager::ActiveUserChanged(
995 const user_manager::User* active_user) {
996 input_method::InputMethodManager* manager =
997 input_method::InputMethodManager::Get();
998 manager->SetState(
999 GetDefaultIMEState(ProfileHelper::Get()->GetProfileByUser(active_user)));
1000 }
1001
1002 scoped_refptr<input_method::InputMethodManager::State>
1003 UserSessionManager::GetDefaultIMEState(Profile* profile) {
1004 scoped_refptr<input_method::InputMethodManager::State> state =
1005 default_ime_states_[profile];
1006 if (!state) {
1007 // Profile can be NULL in tests.
1008 state = input_method::InputMethodManager::Get()->CreateNewState(profile);
1009 default_ime_states_[profile] = state;
1010 }
1011 return state;
1012 }
1013
985 } // namespace chromeos 1014 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698