OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/prefs/pref_member.h" | 23 #include "base/prefs/pref_member.h" |
| 24 #include "base/prefs/pref_registry_simple.h" |
24 #include "base/prefs/pref_service.h" | 25 #include "base/prefs/pref_service.h" |
25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
27 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
28 #include "base/sys_info.h" | 29 #include "base/sys_info.h" |
29 #include "base/task_runner_util.h" | 30 #include "base/task_runner_util.h" |
30 #include "base/threading/worker_pool.h" | 31 #include "base/threading/worker_pool.h" |
31 #include "base/time/time.h" | 32 #include "base/time/time.h" |
32 #include "chrome/browser/about_flags.h" | 33 #include "chrome/browser/about_flags.h" |
33 #include "chrome/browser/app_mode/app_mode_utils.h" | 34 #include "chrome/browser/app_mode/app_mode_utils.h" |
34 #include "chrome/browser/browser_process.h" | 35 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/browser_shutdown.h" | 36 #include "chrome/browser/browser_shutdown.h" |
36 #include "chrome/browser/chrome_notification_types.h" | 37 #include "chrome/browser/chrome_notification_types.h" |
37 #include "chrome/browser/chromeos/boot_times_loader.h" | 38 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 39 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
38 #include "chrome/browser/chromeos/login/auth/parallel_authenticator.h" | 40 #include "chrome/browser/chromeos/login/auth/parallel_authenticator.h" |
39 #include "chrome/browser/chromeos/login/auth/user_context.h" | 41 #include "chrome/browser/chromeos/login/auth/user_context.h" |
40 #include "chrome/browser/chromeos/login/chrome_restart_request.h" | 42 #include "chrome/browser/chromeos/login/chrome_restart_request.h" |
41 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" | 43 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" |
42 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 44 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
43 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 45 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
44 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" | 46 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" |
45 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory
.h" | 47 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory
.h" |
46 #include "chrome/browser/chromeos/login/session/session_manager.h" | |
47 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 48 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
48 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 49 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
49 #include "chrome/browser/chromeos/login/startup_utils.h" | 50 #include "chrome/browser/chromeos/login/startup_utils.h" |
50 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" | 51 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" |
51 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 52 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
52 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 53 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
53 #include "chrome/browser/chromeos/login/users/user.h" | 54 #include "chrome/browser/chromeos/login/users/user.h" |
54 #include "chrome/browser/chromeos/login/users/user_manager.h" | 55 #include "chrome/browser/chromeos/login/users/user_manager.h" |
55 #include "chrome/browser/chromeos/settings/cros_settings.h" | 56 #include "chrome/browser/chromeos/settings/cros_settings.h" |
56 #include "chrome/browser/extensions/extension_service.h" | 57 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 11 matching lines...) Expand all Loading... |
68 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 69 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
69 #include "chrome/common/chrome_switches.h" | 70 #include "chrome/common/chrome_switches.h" |
70 #include "chrome/common/logging_chrome.h" | 71 #include "chrome/common/logging_chrome.h" |
71 #include "chrome/common/pref_names.h" | 72 #include "chrome/common/pref_names.h" |
72 #include "chromeos/chromeos_switches.h" | 73 #include "chromeos/chromeos_switches.h" |
73 #include "chromeos/cryptohome/cryptohome_util.h" | 74 #include "chromeos/cryptohome/cryptohome_util.h" |
74 #include "chromeos/dbus/cryptohome_client.h" | 75 #include "chromeos/dbus/cryptohome_client.h" |
75 #include "chromeos/dbus/dbus_method_call_status.h" | 76 #include "chromeos/dbus/dbus_method_call_status.h" |
76 #include "chromeos/dbus/dbus_thread_manager.h" | 77 #include "chromeos/dbus/dbus_thread_manager.h" |
77 #include "chromeos/dbus/session_manager_client.h" | 78 #include "chromeos/dbus/session_manager_client.h" |
| 79 #include "chromeos/ime/input_method_manager.h" |
78 #include "chromeos/settings/cros_settings_names.h" | 80 #include "chromeos/settings/cros_settings_names.h" |
79 #include "components/signin/core/browser/signin_manager.h" | 81 #include "components/signin/core/browser/signin_manager.h" |
80 #include "content/public/browser/browser_thread.h" | 82 #include "content/public/browser/browser_thread.h" |
81 #include "content/public/browser/notification_service.h" | 83 #include "content/public/browser/notification_service.h" |
82 #include "google_apis/gaia/gaia_auth_consumer.h" | 84 #include "google_apis/gaia/gaia_auth_consumer.h" |
83 #include "net/base/network_change_notifier.h" | 85 #include "net/base/network_change_notifier.h" |
84 #include "net/url_request/url_request_context.h" | 86 #include "net/url_request/url_request_context.h" |
85 #include "net/url_request/url_request_context_getter.h" | 87 #include "net/url_request/url_request_context_getter.h" |
86 #include "url/gurl.h" | 88 #include "url/gurl.h" |
87 | 89 |
(...skipping 14 matching lines...) Expand all Loading... |
102 return homedir.Append(kRLZDisabledFlagName); | 104 return homedir.Append(kRLZDisabledFlagName); |
103 } | 105 } |
104 #endif | 106 #endif |
105 | 107 |
106 } // namespace | 108 } // namespace |
107 | 109 |
108 struct DoBrowserLaunchOnLocaleLoadedData; | 110 struct DoBrowserLaunchOnLocaleLoadedData; |
109 | 111 |
110 class LoginUtilsImpl | 112 class LoginUtilsImpl |
111 : public LoginUtils, | 113 : public LoginUtils, |
112 public base::SupportsWeakPtr<LoginUtilsImpl>, | 114 public OAuth2LoginManager::Observer, |
113 public SessionManager::Delegate { | 115 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 116 public base::SupportsWeakPtr<LoginUtilsImpl> { |
114 public: | 117 public: |
115 LoginUtilsImpl() | 118 LoginUtilsImpl() |
116 : delegate_(NULL) { | 119 : has_web_auth_cookies_(false), |
| 120 delegate_(NULL), |
| 121 exit_after_session_restore_(false), |
| 122 session_restore_strategy_( |
| 123 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { |
| 124 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
117 } | 125 } |
118 | 126 |
119 virtual ~LoginUtilsImpl() { | 127 virtual ~LoginUtilsImpl() { |
| 128 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
120 } | 129 } |
121 | 130 |
122 // LoginUtils implementation: | 131 // LoginUtils implementation: |
123 virtual void DoBrowserLaunch(Profile* profile, | 132 virtual void DoBrowserLaunch(Profile* profile, |
124 LoginDisplayHost* login_host) OVERRIDE; | 133 LoginDisplayHost* login_host) OVERRIDE; |
125 virtual void PrepareProfile( | 134 virtual void PrepareProfile( |
126 const UserContext& user_context, | 135 const UserContext& user_context, |
| 136 const std::string& display_email, |
127 bool has_cookies, | 137 bool has_cookies, |
128 bool has_active_session, | 138 bool has_active_session, |
129 LoginUtils::Delegate* delegate) OVERRIDE; | 139 LoginUtils::Delegate* delegate) OVERRIDE; |
130 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 140 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
131 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 141 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
| 142 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
132 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 143 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
133 LoginStatusConsumer* consumer) OVERRIDE; | 144 LoginStatusConsumer* consumer) OVERRIDE; |
| 145 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
| 146 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
134 | 147 |
135 // SessionManager::Delegate implementation: | 148 // OAuth2LoginManager::Observer overrides. |
136 virtual void OnProfilePrepared(Profile* profile) OVERRIDE; | 149 virtual void OnSessionRestoreStateChanged( |
137 #if defined(ENABLE_RLZ) | 150 Profile* user_profile, |
138 virtual void OnRlzInitialized() OVERRIDE; | 151 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; |
139 #endif | 152 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; |
| 153 |
| 154 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 155 virtual void OnConnectionTypeChanged( |
| 156 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
140 | 157 |
141 private: | 158 private: |
| 159 typedef std::set<std::string> SessionRestoreStateSet; |
| 160 |
142 // DoBrowserLaunch is split into two parts. | 161 // DoBrowserLaunch is split into two parts. |
143 // This one is called after asynchronous locale switch. | 162 // This one is called after anynchronous locale switch. |
144 void DoBrowserLaunchOnLocaleLoadedImpl(Profile* profile, | 163 void DoBrowserLaunchOnLocaleLoadedImpl(Profile* profile, |
145 LoginDisplayHost* login_host); | 164 LoginDisplayHost* login_host); |
146 | 165 |
147 // Callback for locale_util::SwitchLanguage(). | 166 // Callback for locale_util::SwitchLanguage(). |
148 static void DoBrowserLaunchOnLocaleLoaded( | 167 static void DoBrowserLaunchOnLocaleLoaded( |
149 scoped_ptr<DoBrowserLaunchOnLocaleLoadedData> context, | 168 scoped_ptr<DoBrowserLaunchOnLocaleLoadedData> context, |
150 const std::string& locale, | 169 const std::string& locale, |
151 const std::string& loaded_locale, | 170 const std::string& loaded_locale, |
152 const bool success); | 171 const bool success); |
153 | 172 |
| 173 // Restarts OAuth session authentication check. |
| 174 void KickStartAuthentication(Profile* profile); |
| 175 |
| 176 // Callback for Profile::CREATE_STATUS_CREATED profile state. |
| 177 // Initializes basic preferences for newly created profile. Any other |
| 178 // early profile initialization that needs to happen before |
| 179 // ProfileManager::DoFinalInit() gets called is done here. |
| 180 void InitProfilePreferences(Profile* user_profile, |
| 181 const std::string& email); |
| 182 |
| 183 // Callback for asynchronous profile creation. |
| 184 void OnProfileCreated(const std::string& email, |
| 185 Profile* profile, |
| 186 Profile::CreateStatus status); |
| 187 |
| 188 // Callback for asynchronous off the record profile creation. |
| 189 void OnOTRProfileCreated(const std::string& email, |
| 190 Profile* profile, |
| 191 Profile::CreateStatus status); |
| 192 |
| 193 // Callback for Profile::CREATE_STATUS_INITIALIZED profile state. |
| 194 // Profile is created, extensions and promo resources are initialized. |
| 195 void UserProfileInitialized(Profile* user_profile); |
| 196 |
| 197 // Callback for Profile::CREATE_STATUS_INITIALIZED profile state for an OTR |
| 198 // login. |
| 199 void OTRProfileInitialized(Profile* user_profile); |
| 200 |
| 201 // Callback to resume profile creation after transferring auth data from |
| 202 // the authentication profile. |
| 203 void CompleteProfileCreate(Profile* user_profile); |
| 204 |
| 205 // Finalized profile preparation. |
| 206 void FinalizePrepareProfile(Profile* user_profile); |
| 207 |
| 208 // Initializes member variables needed for session restore process via |
| 209 // OAuthLoginManager. |
| 210 void InitSessionRestoreStrategy(); |
| 211 |
| 212 // Restores GAIA auth cookies for the created user profile from OAuth2 token. |
| 213 void RestoreAuthSession(Profile* user_profile, |
| 214 bool restore_from_auth_cookies); |
| 215 |
| 216 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 217 void InitRlz(Profile* user_profile, bool disabled); |
| 218 |
154 // Attempts restarting the browser process and esures that this does | 219 // Attempts restarting the browser process and esures that this does |
155 // not happen while we are still fetching new OAuth refresh tokens. | 220 // not happen while we are still fetching new OAuth refresh tokens. |
156 void AttemptRestart(Profile* profile); | 221 void AttemptRestart(Profile* profile); |
157 | 222 |
| 223 UserContext user_context_; |
| 224 |
| 225 // True if the authentication profile's cookie jar should contain |
| 226 // authentication cookies from the authentication extension log in flow. |
| 227 bool has_web_auth_cookies_; |
158 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 228 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
159 scoped_refptr<Authenticator> authenticator_; | 229 scoped_refptr<Authenticator> authenticator_; |
160 | 230 |
161 // Delegate to be fired when the profile will be prepared. | 231 // Delegate to be fired when the profile will be prepared. |
162 LoginUtils::Delegate* delegate_; | 232 LoginUtils::Delegate* delegate_; |
163 | 233 |
| 234 // Set of user_id for those users that we should restore authentication |
| 235 // session when notified about online state change. |
| 236 SessionRestoreStateSet pending_restore_sessions_; |
| 237 |
| 238 // True if we should restart chrome right after session restore. |
| 239 bool exit_after_session_restore_; |
| 240 |
| 241 // Sesion restore strategy. |
| 242 OAuth2LoginManager::SessionRestoreStrategy session_restore_strategy_; |
| 243 // OAuth2 refresh token for session restore. |
| 244 std::string oauth2_refresh_token_; |
| 245 |
164 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); | 246 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
165 }; | 247 }; |
166 | 248 |
167 class LoginUtilsWrapper { | 249 class LoginUtilsWrapper { |
168 public: | 250 public: |
169 static LoginUtilsWrapper* GetInstance() { | 251 static LoginUtilsWrapper* GetInstance() { |
170 return Singleton<LoginUtilsWrapper>::get(); | 252 return Singleton<LoginUtilsWrapper>::get(); |
171 } | 253 } |
172 | 254 |
173 LoginUtils* get() { | 255 LoginUtils* get() { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 base::Bind(&LoginUtilsImpl::DoBrowserLaunchOnLocaleLoaded, | 378 base::Bind(&LoginUtilsImpl::DoBrowserLaunchOnLocaleLoaded, |
297 base::Passed(data.Pass())))); | 379 base::Passed(data.Pass())))); |
298 if (!UserManager::Get()-> | 380 if (!UserManager::Get()-> |
299 RespectLocalePreference(profile, user, callback.Pass())) { | 381 RespectLocalePreference(profile, user, callback.Pass())) { |
300 DoBrowserLaunchOnLocaleLoadedImpl(profile, login_host); | 382 DoBrowserLaunchOnLocaleLoadedImpl(profile, login_host); |
301 } | 383 } |
302 } | 384 } |
303 | 385 |
304 void LoginUtilsImpl::PrepareProfile( | 386 void LoginUtilsImpl::PrepareProfile( |
305 const UserContext& user_context, | 387 const UserContext& user_context, |
| 388 const std::string& display_email, |
306 bool has_cookies, | 389 bool has_cookies, |
307 bool has_active_session, | 390 bool has_active_session, |
308 LoginUtils::Delegate* delegate) { | 391 LoginUtils::Delegate* delegate) { |
309 // TODO(nkostylev): We have to initialize LoginUtils delegate as long | 392 BootTimesLoader* btl = BootTimesLoader::Get(); |
310 // as it coexist with SessionManager. | 393 |
| 394 VLOG(1) << "Completing login for " << user_context.GetUserID(); |
| 395 |
| 396 if (!has_active_session) { |
| 397 btl->AddLoginTimeMarker("StartSession-Start", false); |
| 398 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
| 399 user_context.GetUserID()); |
| 400 btl->AddLoginTimeMarker("StartSession-End", false); |
| 401 } |
| 402 |
| 403 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
| 404 UserManager* user_manager = UserManager::Get(); |
| 405 user_manager->UserLoggedIn(user_context.GetUserID(), |
| 406 user_context.GetUserIDHash(), |
| 407 false); |
| 408 btl->AddLoginTimeMarker("UserLoggedIn-End", false); |
| 409 |
| 410 // Switch log file as soon as possible. |
| 411 if (base::SysInfo::IsRunningOnChromeOS()) |
| 412 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); |
| 413 |
| 414 // Update user's displayed email. |
| 415 if (!display_email.empty()) |
| 416 user_manager->SaveUserDisplayEmail(user_context.GetUserID(), display_email); |
| 417 |
| 418 user_context_ = user_context; |
| 419 |
| 420 has_web_auth_cookies_ = has_cookies; |
311 delegate_ = delegate; | 421 delegate_ = delegate; |
312 | 422 InitSessionRestoreStrategy(); |
313 // For the transition part LoginUtils will just delegate profile | 423 |
314 // creation and initialization to SessionManager. Later LoginUtils will be | 424 if (DemoAppLauncher::IsDemoAppSession(user_context.GetUserID())) { |
315 // removed and all LoginUtils clients will just work with SessionManager | 425 g_browser_process->profile_manager()->CreateProfileAsync( |
316 // directly. | 426 user_manager->GetUserProfileDir(user_context.GetUserID()), |
317 SessionManager::GetInstance()->StartSession(user_context, | 427 base::Bind(&LoginUtilsImpl::OnOTRProfileCreated, AsWeakPtr(), |
318 authenticator_, | 428 user_context.GetUserID()), |
319 has_cookies, | 429 base::string16(), base::string16(), std::string()); |
320 has_active_session, | 430 } else { |
321 this); | 431 // Can't use display_email because it is empty when existing user logs in |
| 432 // using sing-in pod on login screen (i.e. user didn't type email). |
| 433 g_browser_process->profile_manager()->CreateProfileAsync( |
| 434 user_manager->GetUserProfileDir(user_context.GetUserID()), |
| 435 base::Bind(&LoginUtilsImpl::OnProfileCreated, AsWeakPtr(), |
| 436 user_context.GetUserID()), |
| 437 base::string16(), base::string16(), std::string()); |
| 438 } |
322 } | 439 } |
323 | 440 |
324 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { | 441 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { |
325 if (delegate_ == delegate) | 442 if (delegate_ == delegate) |
326 delegate_ = NULL; | 443 delegate_ = NULL; |
327 } | 444 } |
328 | 445 |
| 446 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile, |
| 447 const std::string& user_id) { |
| 448 if (UserManager::Get()->IsCurrentUserNew()) |
| 449 SetFirstLoginPrefs(user_profile->GetPrefs()); |
| 450 |
| 451 if (UserManager::Get()->IsLoggedInAsLocallyManagedUser()) { |
| 452 User* active_user = UserManager::Get()->GetActiveUser(); |
| 453 std::string managed_user_sync_id = |
| 454 UserManager::Get()->GetSupervisedUserManager()-> |
| 455 GetUserSyncId(active_user->email()); |
| 456 |
| 457 // TODO(ibraaaa): Remove that when 97% of our users are using M31. |
| 458 // http://crbug.com/276163 |
| 459 if (managed_user_sync_id.empty()) |
| 460 managed_user_sync_id = "DUMMY_ID"; |
| 461 |
| 462 user_profile->GetPrefs()->SetString(prefs::kManagedUserId, |
| 463 managed_user_sync_id); |
| 464 } else if (UserManager::Get()->IsLoggedInAsRegularUser()) { |
| 465 // Make sure that the google service username is properly set (we do this |
| 466 // on every sign in, not just the first login, to deal with existing |
| 467 // profiles that might not have it set yet). |
| 468 SigninManagerBase* signin_manager = |
| 469 SigninManagerFactory::GetForProfile(user_profile); |
| 470 signin_manager->SetAuthenticatedUsername(user_id); |
| 471 } |
| 472 } |
| 473 |
| 474 void LoginUtilsImpl::InitSessionRestoreStrategy() { |
| 475 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 476 bool in_app_mode = chrome::IsRunningInForcedAppMode(); |
| 477 |
| 478 // Are we in kiosk app mode? |
| 479 if (in_app_mode) { |
| 480 if (command_line->HasSwitch(::switches::kAppModeOAuth2Token)) { |
| 481 oauth2_refresh_token_ = command_line->GetSwitchValueASCII( |
| 482 ::switches::kAppModeOAuth2Token); |
| 483 } |
| 484 |
| 485 if (command_line->HasSwitch(::switches::kAppModeAuthCode)) { |
| 486 user_context_.SetAuthCode(command_line->GetSwitchValueASCII( |
| 487 ::switches::kAppModeAuthCode)); |
| 488 } |
| 489 |
| 490 DCHECK(!has_web_auth_cookies_); |
| 491 if (!user_context_.GetAuthCode().empty()) { |
| 492 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_AUTH_CODE; |
| 493 } else if (!oauth2_refresh_token_.empty()) { |
| 494 session_restore_strategy_ = |
| 495 OAuth2LoginManager::RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN; |
| 496 } else { |
| 497 session_restore_strategy_ = |
| 498 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; |
| 499 } |
| 500 return; |
| 501 } |
| 502 |
| 503 if (has_web_auth_cookies_) { |
| 504 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR; |
| 505 } else if (!user_context_.GetAuthCode().empty()) { |
| 506 session_restore_strategy_ = OAuth2LoginManager::RESTORE_FROM_AUTH_CODE; |
| 507 } else { |
| 508 session_restore_strategy_ = |
| 509 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN; |
| 510 } |
| 511 } |
| 512 |
| 513 |
| 514 void LoginUtilsImpl::OnProfileCreated( |
| 515 const std::string& user_id, |
| 516 Profile* user_profile, |
| 517 Profile::CreateStatus status) { |
| 518 CHECK(user_profile); |
| 519 |
| 520 switch (status) { |
| 521 case Profile::CREATE_STATUS_CREATED: |
| 522 InitProfilePreferences(user_profile, user_id); |
| 523 break; |
| 524 case Profile::CREATE_STATUS_INITIALIZED: |
| 525 UserProfileInitialized(user_profile); |
| 526 break; |
| 527 case Profile::CREATE_STATUS_LOCAL_FAIL: |
| 528 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 529 case Profile::CREATE_STATUS_CANCELED: |
| 530 case Profile::MAX_CREATE_STATUS: |
| 531 NOTREACHED(); |
| 532 break; |
| 533 } |
| 534 } |
| 535 |
| 536 void LoginUtilsImpl::OnOTRProfileCreated( |
| 537 const std::string& user_id, |
| 538 Profile* user_profile, |
| 539 Profile::CreateStatus status) { |
| 540 CHECK(user_profile); |
| 541 |
| 542 switch (status) { |
| 543 case Profile::CREATE_STATUS_CREATED: |
| 544 InitProfilePreferences(user_profile, user_id); |
| 545 break; |
| 546 case Profile::CREATE_STATUS_INITIALIZED: |
| 547 OTRProfileInitialized(user_profile); |
| 548 break; |
| 549 case Profile::CREATE_STATUS_LOCAL_FAIL: |
| 550 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 551 case Profile::CREATE_STATUS_CANCELED: |
| 552 case Profile::MAX_CREATE_STATUS: |
| 553 NOTREACHED(); |
| 554 break; |
| 555 } |
| 556 } |
| 557 |
| 558 void LoginUtilsImpl::UserProfileInitialized(Profile* user_profile) { |
| 559 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 560 btl->AddLoginTimeMarker("UserProfileGotten", false); |
| 561 |
| 562 if (user_context_.IsUsingOAuth()) { |
| 563 // Transfer proxy authentication cache, cookies (optionally) and server |
| 564 // bound certs from the profile that was used for authentication. This |
| 565 // profile contains cookies that auth extension should have already put in |
| 566 // place that will ensure that the newly created session is authenticated |
| 567 // for the websites that work with the used authentication schema. |
| 568 ProfileAuthData::Transfer(authenticator_->authentication_profile(), |
| 569 user_profile, |
| 570 has_web_auth_cookies_, // transfer_cookies |
| 571 base::Bind( |
| 572 &LoginUtilsImpl::CompleteProfileCreate, |
| 573 AsWeakPtr(), |
| 574 user_profile)); |
| 575 return; |
| 576 } |
| 577 |
| 578 FinalizePrepareProfile(user_profile); |
| 579 } |
| 580 |
| 581 void LoginUtilsImpl::OTRProfileInitialized(Profile* user_profile) { |
| 582 user_profile->OnLogin(); |
| 583 // Send the notification before creating the browser so additional objects |
| 584 // that need the profile (e.g. the launcher) can be created first. |
| 585 content::NotificationService::current()->Notify( |
| 586 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 587 content::NotificationService::AllSources(), |
| 588 content::Details<Profile>(user_profile)); |
| 589 |
| 590 if (delegate_) |
| 591 delegate_->OnProfilePrepared(user_profile); |
| 592 } |
| 593 |
| 594 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { |
| 595 RestoreAuthSession(user_profile, has_web_auth_cookies_); |
| 596 FinalizePrepareProfile(user_profile); |
| 597 } |
| 598 |
| 599 void LoginUtilsImpl::RestoreAuthSession(Profile* user_profile, |
| 600 bool restore_from_auth_cookies) { |
| 601 CHECK((authenticator_.get() && authenticator_->authentication_profile()) || |
| 602 !restore_from_auth_cookies); |
| 603 |
| 604 if (chrome::IsRunningInForcedAppMode() || |
| 605 CommandLine::ForCurrentProcess()->HasSwitch( |
| 606 chromeos::switches::kOobeSkipPostLogin)) { |
| 607 return; |
| 608 } |
| 609 |
| 610 exit_after_session_restore_ = false; |
| 611 // Remove legacy OAuth1 token if we have one. If it's valid, we should already |
| 612 // have OAuth2 refresh token in OAuth2TokenService that could be used to |
| 613 // retrieve all other tokens and user_context. |
| 614 OAuth2LoginManager* login_manager = |
| 615 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(user_profile); |
| 616 login_manager->AddObserver(this); |
| 617 login_manager->RestoreSession( |
| 618 authenticator_.get() && authenticator_->authentication_profile() |
| 619 ? authenticator_->authentication_profile()->GetRequestContext() |
| 620 : NULL, |
| 621 session_restore_strategy_, |
| 622 oauth2_refresh_token_, |
| 623 user_context_.GetAuthCode()); |
| 624 } |
| 625 |
| 626 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { |
| 627 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 628 // Own TPM device if, for any reason, it has not been done in EULA |
| 629 // wizard screen. |
| 630 CryptohomeClient* client = DBusThreadManager::Get()->GetCryptohomeClient(); |
| 631 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
| 632 if (cryptohome_util::TpmIsEnabled() && !cryptohome_util::TpmIsBeingOwned()) { |
| 633 if (cryptohome_util::TpmIsOwned()) { |
| 634 client->CallTpmClearStoredPasswordAndBlock(); |
| 635 } else { |
| 636 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback()); |
| 637 } |
| 638 } |
| 639 btl->AddLoginTimeMarker("TPMOwn-End", false); |
| 640 |
| 641 if (UserManager::Get()->IsLoggedInAsRegularUser()) { |
| 642 SAMLOfflineSigninLimiter* saml_offline_signin_limiter = |
| 643 SAMLOfflineSigninLimiterFactory::GetForProfile(user_profile); |
| 644 if (saml_offline_signin_limiter) |
| 645 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow()); |
| 646 } |
| 647 |
| 648 user_profile->OnLogin(); |
| 649 |
| 650 // Send the notification before creating the browser so additional objects |
| 651 // that need the profile (e.g. the launcher) can be created first. |
| 652 content::NotificationService::current()->Notify( |
| 653 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 654 content::NotificationService::AllSources(), |
| 655 content::Details<Profile>(user_profile)); |
| 656 |
| 657 // Initialize RLZ only for primary user. |
| 658 if (UserManager::Get()->GetPrimaryUser() == |
| 659 UserManager::Get()->GetUserByProfile(user_profile)) { |
| 660 InitRlzDelayed(user_profile); |
| 661 } |
| 662 // TODO(altimofeev): This pointer should probably never be NULL, but it looks |
| 663 // like LoginUtilsImpl::OnProfileCreated() may be getting called before |
| 664 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed |
| 665 // during shutdown in tests -- see http://crosbug.com/18269. Replace this |
| 666 // 'if' statement with a CHECK(delegate_) once the underlying issue is |
| 667 // resolved. |
| 668 if (delegate_) |
| 669 delegate_->OnProfilePrepared(user_profile); |
| 670 } |
| 671 |
| 672 void LoginUtilsImpl::InitRlzDelayed(Profile* user_profile) { |
| 673 #if defined(ENABLE_RLZ) |
| 674 if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) { |
| 675 // Read brand code asynchronously from an OEM data and repost ourselves. |
| 676 google_brand::chromeos::InitBrand( |
| 677 base::Bind(&LoginUtilsImpl::InitRlzDelayed, AsWeakPtr(), user_profile)); |
| 678 return; |
| 679 } |
| 680 base::PostTaskAndReplyWithResult( |
| 681 base::WorkerPool::GetTaskRunner(false), |
| 682 FROM_HERE, |
| 683 base::Bind(&base::PathExists, GetRlzDisabledFlagPath()), |
| 684 base::Bind(&LoginUtilsImpl::InitRlz, AsWeakPtr(), user_profile)); |
| 685 #endif |
| 686 } |
| 687 |
| 688 void LoginUtilsImpl::InitRlz(Profile* user_profile, bool disabled) { |
| 689 #if defined(ENABLE_RLZ) |
| 690 PrefService* local_state = g_browser_process->local_state(); |
| 691 if (disabled) { |
| 692 // Empty brand code means an organic install (no RLZ pings are sent). |
| 693 google_brand::chromeos::ClearBrandForCurrentSession(); |
| 694 } |
| 695 if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) { |
| 696 // When switching to RLZ enabled/disabled state, clear all recorded events. |
| 697 RLZTracker::ClearRlzState(); |
| 698 local_state->SetBoolean(prefs::kRLZDisabled, disabled); |
| 699 } |
| 700 // Init the RLZ library. |
| 701 int ping_delay = user_profile->GetPrefs()->GetInteger( |
| 702 first_run::GetPingDelayPrefName().c_str()); |
| 703 // Negative ping delay means to send ping immediately after a first search is |
| 704 // recorded. |
| 705 RLZTracker::InitRlzFromProfileDelayed( |
| 706 user_profile, UserManager::Get()->IsCurrentUserNew(), |
| 707 ping_delay < 0, base::TimeDelta::FromMilliseconds(abs(ping_delay))); |
| 708 if (delegate_) |
| 709 delegate_->OnRlzInitialized(user_profile); |
| 710 #endif |
| 711 } |
| 712 |
329 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { | 713 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { |
330 VLOG(1) << "Completing incognito login"; | 714 VLOG(1) << "Completing incognito login"; |
331 | 715 |
332 // For guest session we ask session manager to restart Chrome with --bwsi | 716 // For guest session we ask session manager to restart Chrome with --bwsi |
333 // flag. We keep only some of the arguments of this process. | 717 // flag. We keep only some of the arguments of this process. |
334 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 718 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
335 CommandLine command_line(browser_command_line.GetProgram()); | 719 CommandLine command_line(browser_command_line.GetProgram()); |
336 std::string cmd_line_str = | 720 std::string cmd_line_str = |
337 GetOffTheRecordCommandLine(start_url, | 721 GetOffTheRecordCommandLine(start_url, |
338 StartupUtils::IsOobeCompleted(), | 722 StartupUtils::IsOobeCompleted(), |
339 browser_command_line, | 723 browser_command_line, |
340 &command_line); | 724 &command_line); |
341 | 725 |
342 RestartChrome(cmd_line_str); | 726 RestartChrome(cmd_line_str); |
343 } | 727 } |
344 | 728 |
| 729 void LoginUtilsImpl::SetFirstLoginPrefs(PrefService* prefs) { |
| 730 VLOG(1) << "Setting first login prefs"; |
| 731 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 732 std::string locale = g_browser_process->GetApplicationLocale(); |
| 733 |
| 734 // First, we'll set kLanguagePreloadEngines. |
| 735 input_method::InputMethodManager* manager = |
| 736 input_method::InputMethodManager::Get(); |
| 737 std::vector<std::string> input_method_ids; |
| 738 manager->GetInputMethodUtil()->GetFirstLoginInputMethodIds( |
| 739 locale, manager->GetCurrentInputMethod(), &input_method_ids); |
| 740 // Save the input methods in the user's preferences. |
| 741 StringPrefMember language_preload_engines; |
| 742 language_preload_engines.Init(prefs::kLanguagePreloadEngines, |
| 743 prefs); |
| 744 language_preload_engines.SetValue(JoinString(input_method_ids, ',')); |
| 745 btl->AddLoginTimeMarker("IMEStarted", false); |
| 746 |
| 747 // Second, we'll set kLanguagePreferredLanguages. |
| 748 std::vector<std::string> language_codes; |
| 749 // The current locale should be on the top. |
| 750 language_codes.push_back(locale); |
| 751 |
| 752 // Add input method IDs based on the input methods, as there may be |
| 753 // input methods that are unrelated to the current locale. Example: the |
| 754 // hardware keyboard layout xkb:us::eng is used for logging in, but the |
| 755 // UI language is set to French. In this case, we should set "fr,en" |
| 756 // to the preferred languages preference. |
| 757 std::vector<std::string> candidates; |
| 758 manager->GetInputMethodUtil()->GetLanguageCodesFromInputMethodIds( |
| 759 input_method_ids, &candidates); |
| 760 for (size_t i = 0; i < candidates.size(); ++i) { |
| 761 const std::string& candidate = candidates[i]; |
| 762 // Skip if it's already in language_codes. |
| 763 if (std::count(language_codes.begin(), language_codes.end(), |
| 764 candidate) == 0) { |
| 765 language_codes.push_back(candidate); |
| 766 } |
| 767 } |
| 768 // Save the preferred languages in the user's preferences. |
| 769 StringPrefMember language_preferred_languages; |
| 770 language_preferred_languages.Init(prefs::kLanguagePreferredLanguages, |
| 771 prefs); |
| 772 language_preferred_languages.SetValue(JoinString(language_codes, ',')); |
| 773 } |
| 774 |
345 scoped_refptr<Authenticator> LoginUtilsImpl::CreateAuthenticator( | 775 scoped_refptr<Authenticator> LoginUtilsImpl::CreateAuthenticator( |
346 LoginStatusConsumer* consumer) { | 776 LoginStatusConsumer* consumer) { |
347 // Screen locker needs new Authenticator instance each time. | 777 // Screen locker needs new Authenticator instance each time. |
348 if (ScreenLocker::default_screen_locker()) { | 778 if (ScreenLocker::default_screen_locker()) { |
349 if (authenticator_.get()) | 779 if (authenticator_.get()) |
350 authenticator_->SetConsumer(NULL); | 780 authenticator_->SetConsumer(NULL); |
351 authenticator_ = NULL; | 781 authenticator_ = NULL; |
352 } | 782 } |
353 | 783 |
354 if (authenticator_.get() == NULL) { | 784 if (authenticator_.get() == NULL) { |
355 authenticator_ = new ParallelAuthenticator(consumer); | 785 authenticator_ = new ParallelAuthenticator(consumer); |
356 } else { | 786 } else { |
357 // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. | 787 // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. |
358 authenticator_->SetConsumer(consumer); | 788 authenticator_->SetConsumer(consumer); |
359 } | 789 } |
360 return authenticator_; | 790 return authenticator_; |
361 } | 791 } |
362 | 792 |
363 void LoginUtilsImpl::OnProfilePrepared(Profile* profile) { | 793 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { |
364 if (delegate_) | 794 UserManager* user_manager = UserManager::Get(); |
365 delegate_->OnProfilePrepared(profile); | 795 // We don't need to restore session for demo/guest/stub/public account users. |
| 796 if (!user_manager->IsUserLoggedIn() || |
| 797 user_manager->IsLoggedInAsGuest() || |
| 798 user_manager->IsLoggedInAsPublicAccount() || |
| 799 user_manager->IsLoggedInAsDemoUser() || |
| 800 user_manager->IsLoggedInAsStub()) { |
| 801 return; |
| 802 } |
| 803 |
| 804 User* user = user_manager->GetUserByProfile(user_profile); |
| 805 DCHECK(user); |
| 806 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 807 pending_restore_sessions_.erase(user->email()); |
| 808 RestoreAuthSession(user_profile, false); |
| 809 } else { |
| 810 // Even if we're online we should wait till initial |
| 811 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may |
| 812 // end up canceling all request when initial network connection type is |
| 813 // processed. See http://crbug.com/121643. |
| 814 pending_restore_sessions_.insert(user->email()); |
| 815 } |
366 } | 816 } |
367 | 817 |
368 #if defined(ENABLE_RLZ) | 818 void LoginUtilsImpl::OnSessionRestoreStateChanged( |
369 void LoginUtilsImpl::OnRlzInitialized() { | 819 Profile* user_profile, |
370 if (delegate_) | 820 OAuth2LoginManager::SessionRestoreState state) { |
371 delegate_->OnRlzInitialized(); | 821 User::OAuthTokenStatus user_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 822 OAuth2LoginManager* login_manager = |
| 823 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(user_profile); |
| 824 |
| 825 bool connection_error = false; |
| 826 switch (state) { |
| 827 case OAuth2LoginManager::SESSION_RESTORE_DONE: |
| 828 user_status = User::OAUTH2_TOKEN_STATUS_VALID; |
| 829 break; |
| 830 case OAuth2LoginManager::SESSION_RESTORE_FAILED: |
| 831 user_status = User::OAUTH2_TOKEN_STATUS_INVALID; |
| 832 break; |
| 833 case OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED: |
| 834 connection_error = true; |
| 835 break; |
| 836 case OAuth2LoginManager::SESSION_RESTORE_NOT_STARTED: |
| 837 case OAuth2LoginManager::SESSION_RESTORE_PREPARING: |
| 838 case OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS: |
| 839 return; |
| 840 } |
| 841 |
| 842 // We should not be clearing existing token state if that was a connection |
| 843 // error. http://crbug.com/295245 |
| 844 if (!connection_error) { |
| 845 // We are in one of "done" states here. |
| 846 UserManager::Get()->SaveUserOAuthStatus( |
| 847 UserManager::Get()->GetLoggedInUser()->email(), |
| 848 user_status); |
| 849 } |
| 850 |
| 851 login_manager->RemoveObserver(this); |
372 } | 852 } |
373 #endif | 853 |
| 854 void LoginUtilsImpl::OnNewRefreshTokenAvaiable(Profile* user_profile) { |
| 855 // Check if we were waiting to restart chrome. |
| 856 if (!exit_after_session_restore_) |
| 857 return; |
| 858 |
| 859 OAuth2LoginManager* login_manager = |
| 860 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(user_profile); |
| 861 login_manager->RemoveObserver(this); |
| 862 |
| 863 // Mark user auth token status as valid. |
| 864 UserManager::Get()->SaveUserOAuthStatus( |
| 865 UserManager::Get()->GetLoggedInUser()->email(), |
| 866 User::OAUTH2_TOKEN_STATUS_VALID); |
| 867 |
| 868 LOG(WARNING) << "Exiting after new refresh token fetched"; |
| 869 // We need to restart cleanly in this case to make sure OAuth2 RT is actually |
| 870 // saved. |
| 871 chrome::AttemptRestart(); |
| 872 } |
| 873 |
| 874 void LoginUtilsImpl::OnConnectionTypeChanged( |
| 875 net::NetworkChangeNotifier::ConnectionType type) { |
| 876 UserManager* user_manager = UserManager::Get(); |
| 877 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || |
| 878 user_manager->IsLoggedInAsGuest() || !user_manager->IsUserLoggedIn()) { |
| 879 return; |
| 880 } |
| 881 |
| 882 // Need to iterate over all users and their OAuth2 session state. |
| 883 const UserList& users = user_manager->GetLoggedInUsers(); |
| 884 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 885 Profile* user_profile = user_manager->GetProfileByUser(*it); |
| 886 bool should_restore_session = |
| 887 pending_restore_sessions_.find((*it)->email()) != |
| 888 pending_restore_sessions_.end(); |
| 889 OAuth2LoginManager* login_manager = |
| 890 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(user_profile); |
| 891 if (login_manager->state() == |
| 892 OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS) { |
| 893 // If we come online for the first time after successful offline login, |
| 894 // we need to kick off OAuth token verification process again. |
| 895 login_manager->ContinueSessionRestore(); |
| 896 } else if (should_restore_session) { |
| 897 pending_restore_sessions_.erase((*it)->email()); |
| 898 RestoreAuthSession(user_profile, has_web_auth_cookies_); |
| 899 } |
| 900 } |
| 901 } |
374 | 902 |
375 void LoginUtilsImpl::AttemptRestart(Profile* profile) { | 903 void LoginUtilsImpl::AttemptRestart(Profile* profile) { |
376 if (SessionManager::GetInstance()->GetSigninSessionRestoreStrategy() != | 904 if (session_restore_strategy_ != |
377 OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR) { | 905 OAuth2LoginManager::RESTORE_FROM_COOKIE_JAR) { |
378 chrome::AttemptRestart(); | 906 chrome::AttemptRestart(); |
379 return; | 907 return; |
380 } | 908 } |
381 | 909 |
382 // We can't really quit if the session restore process that mints new | 910 // We can't really quit if the session restore process that mints new |
383 // refresh token is still in progress. | 911 // refresh token is still in progress. |
384 OAuth2LoginManager* login_manager = | 912 OAuth2LoginManager* login_manager = |
385 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); | 913 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(profile); |
386 if (login_manager->state() != | 914 if (login_manager->state() != |
387 OAuth2LoginManager::SESSION_RESTORE_PREPARING && | 915 OAuth2LoginManager::SESSION_RESTORE_PREPARING && |
388 login_manager->state() != | 916 login_manager->state() != |
389 OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS) { | 917 OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS) { |
390 chrome::AttemptRestart(); | 918 chrome::AttemptRestart(); |
391 return; | 919 return; |
392 } | 920 } |
393 | 921 |
394 LOG(WARNING) << "Attempting browser restart during session restore."; | 922 LOG(WARNING) << "Attempting browser restart during session restore."; |
395 SessionManager::GetInstance()->set_exit_after_session_restore(true); | 923 exit_after_session_restore_ = true; |
396 } | 924 } |
397 | 925 |
398 // static | 926 // static |
| 927 void LoginUtils::RegisterPrefs(PrefRegistrySimple* registry) { |
| 928 registry->RegisterBooleanPref(prefs::kFactoryResetRequested, false); |
| 929 registry->RegisterBooleanPref(prefs::kRollbackRequested, false); |
| 930 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); |
| 931 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); |
| 932 } |
| 933 |
| 934 // static |
399 LoginUtils* LoginUtils::Get() { | 935 LoginUtils* LoginUtils::Get() { |
400 return LoginUtilsWrapper::GetInstance()->get(); | 936 return LoginUtilsWrapper::GetInstance()->get(); |
401 } | 937 } |
402 | 938 |
403 // static | 939 // static |
404 void LoginUtils::Set(LoginUtils* mock) { | 940 void LoginUtils::Set(LoginUtils* mock) { |
405 LoginUtilsWrapper::GetInstance()->reset(mock); | 941 LoginUtilsWrapper::GetInstance()->reset(mock); |
406 } | 942 } |
407 | 943 |
408 // static | 944 // static |
409 bool LoginUtils::IsWhitelisted(const std::string& username, | 945 bool LoginUtils::IsWhitelisted(const std::string& username, |
410 bool* wildcard_match) { | 946 bool* wildcard_match) { |
411 // Skip whitelist check for tests. | 947 // Skip whitelist check for tests. |
412 if (CommandLine::ForCurrentProcess()->HasSwitch( | 948 if (CommandLine::ForCurrentProcess()->HasSwitch( |
413 chromeos::switches::kOobeSkipPostLogin)) { | 949 chromeos::switches::kOobeSkipPostLogin)) { |
414 return true; | 950 return true; |
415 } | 951 } |
416 | 952 |
417 CrosSettings* cros_settings = CrosSettings::Get(); | 953 CrosSettings* cros_settings = CrosSettings::Get(); |
418 bool allow_new_user = false; | 954 bool allow_new_user = false; |
419 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 955 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
420 if (allow_new_user) | 956 if (allow_new_user) |
421 return true; | 957 return true; |
422 return cros_settings->FindEmailInList( | 958 return cros_settings->FindEmailInList( |
423 kAccountsPrefUsers, username, wildcard_match); | 959 kAccountsPrefUsers, username, wildcard_match); |
424 } | 960 } |
425 | 961 |
426 } // namespace chromeos | 962 } // namespace chromeos |
OLD | NEW |