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

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

Powered by Google App Engine
This is Rietveld 408576698