Chromium Code Reviews| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
| 24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 25 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
| 26 #include "base/threading/worker_pool.h" | 26 #include "base/threading/worker_pool.h" |
| 27 #include "base/time.h" | 27 #include "base/time.h" |
| 28 #include "base/utf_string_conversions.h" | 28 #include "base/utf_string_conversions.h" |
| 29 #include "cc/switches.h" | 29 #include "cc/switches.h" |
| 30 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
| 31 #include "chrome/browser/browser_shutdown.h" | 31 #include "chrome/browser/browser_shutdown.h" |
| 32 #include "chrome/browser/chromeos/boot_times_loader.h" | 32 #include "chrome/browser/chromeos/boot_times_loader.h" |
| 33 #include "chrome/browser/chromeos/cros/cert_library.h" | |
| 34 #include "chrome/browser/chromeos/cros/cros_library.h" | 33 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 35 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 34 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 36 #include "chrome/browser/chromeos/cros/network_library.h" | 35 #include "chrome/browser/chromeos/cros/network_library.h" |
| 37 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 36 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 38 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 37 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 39 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 38 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 40 #include "chrome/browser/chromeos/login/language_switch_menu.h" | 39 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
| 41 #include "chrome/browser/chromeos/login/login_display_host.h" | 40 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 42 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" | 41 #include "chrome/browser/chromeos/login/oauth_login_manager.h" |
| 43 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" | |
| 44 #include "chrome/browser/chromeos/login/parallel_authenticator.h" | 42 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 45 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" | |
| 46 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 43 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 47 #include "chrome/browser/chromeos/login/screen_locker.h" | 44 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 48 #include "chrome/browser/chromeos/login/user_manager.h" | 45 #include "chrome/browser/chromeos/login/user_manager.h" |
| 49 #include "chrome/browser/chromeos/settings/cros_settings.h" | 46 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 50 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 47 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 51 #include "chrome/browser/extensions/extension_service.h" | 48 #include "chrome/browser/extensions/extension_service.h" |
| 52 #include "chrome/browser/first_run/first_run.h" | 49 #include "chrome/browser/first_run/first_run.h" |
| 53 #include "chrome/browser/google/google_util_chromeos.h" | 50 #include "chrome/browser/google/google_util_chromeos.h" |
| 54 #include "chrome/browser/net/chrome_url_request_context.h" | 51 #include "chrome/browser/net/chrome_url_request_context.h" |
| 55 #include "chrome/browser/net/preconnect.h" | 52 #include "chrome/browser/net/preconnect.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 75 #include "chrome/common/pref_names.h" | 72 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 73 #include "chrome/common/url_constants.h" |
| 77 #include "chromeos/chromeos_switches.h" | 74 #include "chromeos/chromeos_switches.h" |
| 78 #include "chromeos/dbus/dbus_thread_manager.h" | 75 #include "chromeos/dbus/dbus_thread_manager.h" |
| 79 #include "chromeos/dbus/session_manager_client.h" | 76 #include "chromeos/dbus/session_manager_client.h" |
| 80 #include "content/public/browser/browser_thread.h" | 77 #include "content/public/browser/browser_thread.h" |
| 81 #include "content/public/browser/notification_observer.h" | 78 #include "content/public/browser/notification_observer.h" |
| 82 #include "content/public/browser/notification_service.h" | 79 #include "content/public/browser/notification_service.h" |
| 83 #include "content/public/common/content_switches.h" | 80 #include "content/public/common/content_switches.h" |
| 84 #include "google_apis/gaia/gaia_auth_consumer.h" | 81 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 82 #include "google_apis/gaia/gaia_constants.h" | |
| 85 #include "google_apis/gaia/gaia_urls.h" | 83 #include "google_apis/gaia/gaia_urls.h" |
| 86 #include "googleurl/src/gurl.h" | 84 #include "googleurl/src/gurl.h" |
| 87 #include "media/base/media_switches.h" | 85 #include "media/base/media_switches.h" |
| 88 #include "net/base/network_change_notifier.h" | 86 #include "net/base/network_change_notifier.h" |
| 89 #include "net/url_request/url_request_context.h" | 87 #include "net/url_request/url_request_context.h" |
| 90 #include "net/url_request/url_request_context_getter.h" | 88 #include "net/url_request/url_request_context_getter.h" |
| 91 #include "ui/base/ui_base_switches.h" | 89 #include "ui/base/ui_base_switches.h" |
| 92 #include "ui/compositor/compositor_switches.h" | 90 #include "ui/compositor/compositor_switches.h" |
| 93 #include "ui/gfx/switches.h" | 91 #include "ui/gfx/switches.h" |
| 94 #include "ui/gl/gl_switches.h" | 92 #include "ui/gl/gl_switches.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } | 170 } |
| 173 | 171 |
| 174 int pid_; | 172 int pid_; |
| 175 std::string command_line_; | 173 std::string command_line_; |
| 176 PrefService* local_state_; | 174 PrefService* local_state_; |
| 177 base::OneShotTimer<JobRestartRequest> timer_; | 175 base::OneShotTimer<JobRestartRequest> timer_; |
| 178 }; | 176 }; |
| 179 | 177 |
| 180 class LoginUtilsImpl | 178 class LoginUtilsImpl |
| 181 : public LoginUtils, | 179 : public LoginUtils, |
| 182 public OAuth1TokenFetcher::Delegate, | 180 public OAuthLoginManager::Delegate, |
| 183 public OAuthLoginVerifier::Delegate, | |
| 184 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 181 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 185 public content::NotificationObserver, | 182 public content::NotificationObserver, |
| 186 public base::SupportsWeakPtr<LoginUtilsImpl> { | 183 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 187 public: | 184 public: |
| 188 LoginUtilsImpl() | 185 LoginUtilsImpl() |
| 189 : pending_requests_(false), | 186 : using_oauth_(false), |
| 190 using_oauth_(false), | 187 force_oauth2_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 188 ::switches::kForceOAuth2)), | |
| 191 has_web_auth_cookies_(false), | 189 has_web_auth_cookies_(false), |
| 190 login_manager_(OAuthLoginManager::Create(this)), | |
| 192 delegate_(NULL), | 191 delegate_(NULL), |
| 193 job_restart_request_(NULL), | 192 job_restart_request_(NULL), |
| 194 should_restore_auth_session_(false), | 193 should_restore_auth_session_(false), |
| 195 url_request_context_getter_(NULL) { | 194 url_request_context_getter_(NULL) { |
| 196 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 195 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 197 // During tests, the browser_process may not be initialized yet causing | 196 // During tests, the browser_process may not be initialized yet causing |
| 198 // this to fail. | 197 // this to fail. |
| 199 if (g_browser_process) { | 198 if (g_browser_process) { |
| 200 registrar_.Add( | 199 registrar_.Add( |
| 201 this, | 200 this, |
| 202 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, | 201 chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED, |
| 203 content::Source<Profile>(ProfileManager::GetDefaultProfile())); | 202 content::Source<Profile>(ProfileManager::GetDefaultProfile())); |
| 204 } | 203 } |
| 205 } | 204 } |
| 206 | 205 |
| 207 virtual ~LoginUtilsImpl() { | 206 virtual ~LoginUtilsImpl() { |
| 208 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 207 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 209 } | 208 } |
| 210 | 209 |
| 211 // LoginUtils implementation: | 210 // LoginUtils implementation: |
| 212 virtual void DoBrowserLaunch(Profile* profile, | 211 virtual void DoBrowserLaunch(Profile* profile, |
| 213 LoginDisplayHost* login_host) OVERRIDE; | 212 LoginDisplayHost* login_host) OVERRIDE; |
| 214 virtual void PrepareProfile( | 213 virtual void PrepareProfile( |
| 215 const std::string& username, | 214 const std::string& username, |
| 216 const std::string& display_email, | 215 const std::string& display_email, |
| 217 const std::string& password, | 216 const std::string& password, |
| 218 bool pending_requests, | |
| 219 bool using_oauth, | 217 bool using_oauth, |
| 220 bool has_cookies, | 218 bool has_cookies, |
| 221 LoginUtils::Delegate* delegate) OVERRIDE; | 219 LoginUtils::Delegate* delegate) OVERRIDE; |
| 222 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 220 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
| 223 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 221 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
| 224 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 222 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
| 225 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 223 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
| 226 LoginStatusConsumer* consumer) OVERRIDE; | 224 LoginStatusConsumer* consumer) OVERRIDE; |
| 227 virtual void PrewarmAuthentication() OVERRIDE; | 225 virtual void PrewarmAuthentication() OVERRIDE; |
| 228 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; | 226 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
| 229 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 227 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
| 230 virtual void StartSignedInServices( | |
| 231 Profile* profile, | |
| 232 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | |
| 233 virtual void StopBackgroundFetchers() OVERRIDE; | 228 virtual void StopBackgroundFetchers() OVERRIDE; |
| 234 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; | 229 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
| 235 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; | 230 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; |
| 236 | 231 |
| 237 // OAuth1TokenFetcher::Delegate overrides. | 232 // OAuthLoginManager::Delegate overrides. |
| 238 void OnOAuth1AccessTokenAvailable(const std::string& token, | 233 virtual void OnCompletedAuthentication(Profile* user_profile) OVERRIDE; |
| 239 const std::string& secret) OVERRIDE; | 234 virtual void OnFoundStoredTokens() OVERRIDE; |
| 240 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; | |
| 241 | |
| 242 // OAuthLoginVerifier::Delegate overrides. | |
| 243 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | |
| 244 const std::string& sid, | |
| 245 const std::string& lsid, | |
| 246 const std::string& auth) OVERRIDE; | |
| 247 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | |
| 248 | 235 |
| 249 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 236 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 250 virtual void OnConnectionTypeChanged( | 237 virtual void OnConnectionTypeChanged( |
| 251 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 238 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 252 | 239 |
| 253 // content::NotificationObserver overrides. | 240 // content::NotificationObserver overrides. |
| 254 virtual void Observe(int type, | 241 virtual void Observe(int type, |
| 255 const content::NotificationSource& source, | 242 const content::NotificationSource& source, |
| 256 const content::NotificationDetails& details) OVERRIDE; | 243 const content::NotificationDetails& details) OVERRIDE; |
| 257 | 244 |
| 258 protected: | 245 protected: |
| 259 virtual std::string GetOffTheRecordCommandLine( | 246 virtual std::string GetOffTheRecordCommandLine( |
| 260 const GURL& start_url, | 247 const GURL& start_url, |
| 261 const CommandLine& base_command_line, | 248 const CommandLine& base_command_line, |
| 262 CommandLine *command_line); | 249 CommandLine *command_line); |
| 263 | 250 |
| 264 private: | 251 private: |
| 265 // Restarts OAuth session authentication check. | 252 // Restarts OAuth session authentication check. |
| 266 void KickStartAuthentication(Profile* profile); | 253 void KickStartAuthentication(Profile* profile); |
| 267 | 254 |
| 268 // Reads OAuth1 token from user profile's prefs. | |
| 269 bool ReadOAuth1AccessToken(Profile* user_profile, | |
| 270 std::string* token, | |
| 271 std::string* secret); | |
| 272 | |
| 273 // Stores OAuth1 token + secret in profile's prefs. | |
| 274 void StoreOAuth1AccessToken(Profile* user_profile, | |
| 275 const std::string& token, | |
| 276 const std::string& secret); | |
| 277 | |
| 278 // Verifies OAuth1 token by doing OAuthLogin and fetching credentials. | |
| 279 void VerifyOAuth1AccessToken(Profile* user_profile, | |
| 280 const std::string& token, | |
| 281 const std::string& secret); | |
| 282 | |
| 283 // Fetch all secondary (OAuth2) tokens given OAuth1 access |token| and | |
| 284 // |secret|. | |
| 285 void FetchSecondaryTokens(Profile* offrecord_profile, | |
| 286 const std::string& token, | |
| 287 const std::string& secret); | |
| 288 | |
| 289 // Fetch user credentials (sid/lsid) given OAuth1 access |token| and |secret|. | |
| 290 void FetchCredentials(Profile* user_profile, | |
| 291 const std::string& token, | |
| 292 const std::string& secret); | |
| 293 | |
| 294 // Fetch enterprise policy OAuth2 given OAuth1 access |token| and |secret|. | |
| 295 void FetchPolicyToken(Profile* offrecord_profile, | |
| 296 const std::string& token, | |
| 297 const std::string& secret); | |
| 298 | |
| 299 // Check user's profile for kApplicationLocale setting. | 255 // Check user's profile for kApplicationLocale setting. |
| 300 void RespectLocalePreference(Profile* pref); | 256 void RespectLocalePreference(Profile* pref); |
| 301 | 257 |
| 302 // Initializes basic preferences for newly created profile. | 258 // Initializes basic preferences for newly created profile. |
| 303 void InitProfilePreferences(Profile* user_profile); | 259 void InitProfilePreferences(Profile* user_profile); |
| 304 | 260 |
| 305 // Callback for asynchronous profile creation. | 261 // Callback for asynchronous profile creation. |
| 306 void OnProfileCreated(Profile* profile, | 262 void OnProfileCreated(Profile* profile, |
| 307 Profile::CreateStatus status); | 263 Profile::CreateStatus status); |
| 308 | 264 |
| 309 // Finalized profile preparation. | 265 // Finalized profile preparation. |
| 310 void FinalizePrepareProfile(Profile* user_profile); | 266 void FinalizePrepareProfile(Profile* user_profile); |
| 311 | 267 |
| 312 // Restores GAIA auth cookies for the created profile. | 268 // Restores GAIA auth cookies for the created user profile from OAuth2 token. |
| 313 void RestoreAuthCookies(Profile* user_profile); | 269 void RestoreAuthSession(Profile* user_profile, |
| 270 bool restore_from_auth_cookies); | |
| 271 | |
| 272 // Removes deprecated OAuth1 token and secret form preference store. | |
|
Joao da Silva
2013/01/11 20:13:15
*from
zel
2013/01/11 20:54:20
That method is nuked actually.
| |
| 273 void RemoveOAuth1Tokens(Profile* user_profile); | |
| 314 | 274 |
| 315 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 275 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 316 void InitRlz(Profile* user_profile, bool disabled); | 276 void InitRlz(Profile* user_profile, bool disabled); |
| 317 | 277 |
| 278 // Starts signing related services. Initiates TokenService token retrieval. | |
| 279 void StartSignedInServices(Profile* profile); | |
| 280 | |
| 318 std::string password_; | 281 std::string password_; |
| 319 bool pending_requests_; | |
| 320 bool using_oauth_; | 282 bool using_oauth_; |
| 283 bool force_oauth2_; | |
| 321 // True if the authenrication profile's cookie jar should contain | 284 // True if the authenrication profile's cookie jar should contain |
| 322 // authentication cookies from the authentication extension log in flow. | 285 // authentication cookies from the authentication extension log in flow. |
| 323 bool has_web_auth_cookies_; | 286 bool has_web_auth_cookies_; |
| 324 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 287 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 325 scoped_refptr<Authenticator> authenticator_; | 288 scoped_refptr<Authenticator> authenticator_; |
| 326 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 289 scoped_ptr<OAuthLoginManager> login_manager_; |
| 327 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; | |
| 328 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | |
| 329 | 290 |
| 330 // Delegate to be fired when the profile will be prepared. | 291 // Delegate to be fired when the profile will be prepared. |
| 331 LoginUtils::Delegate* delegate_; | 292 LoginUtils::Delegate* delegate_; |
| 332 | 293 |
| 333 // Used to restart Chrome to switch to the guest mode. | 294 // Used to restart Chrome to switch to the guest mode. |
| 334 JobRestartRequest* job_restart_request_; | 295 JobRestartRequest* job_restart_request_; |
| 335 | 296 |
| 336 // True if should restore authentication session when notified about | 297 // True if should restore authentication session when notified about |
| 337 // online state change. | 298 // online state change. |
| 338 bool should_restore_auth_session_; | 299 bool should_restore_auth_session_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 // browser before it is dereferenced by the login host. | 364 // browser before it is dereferenced by the login host. |
| 404 if (login_host) | 365 if (login_host) |
| 405 login_host->OnSessionStart(); | 366 login_host->OnSessionStart(); |
| 406 UserManager::Get()->SessionStarted(); | 367 UserManager::Get()->SessionStarted(); |
| 407 } | 368 } |
| 408 | 369 |
| 409 void LoginUtilsImpl::PrepareProfile( | 370 void LoginUtilsImpl::PrepareProfile( |
| 410 const std::string& username, | 371 const std::string& username, |
| 411 const std::string& display_email, | 372 const std::string& display_email, |
| 412 const std::string& password, | 373 const std::string& password, |
| 413 bool pending_requests, | |
| 414 bool using_oauth, | 374 bool using_oauth, |
| 415 bool has_cookies, | 375 bool has_cookies, |
| 416 LoginUtils::Delegate* delegate) { | 376 LoginUtils::Delegate* delegate) { |
| 417 BootTimesLoader* btl = BootTimesLoader::Get(); | 377 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 418 | 378 |
| 419 VLOG(1) << "Completing login for " << username; | 379 VLOG(1) << "Completing login for " << username; |
| 420 | 380 |
| 421 btl->AddLoginTimeMarker("StartSession-Start", false); | 381 btl->AddLoginTimeMarker("StartSession-Start", false); |
| 422 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( | 382 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
| 423 username); | 383 username); |
| 424 btl->AddLoginTimeMarker("StartSession-End", false); | 384 btl->AddLoginTimeMarker("StartSession-End", false); |
| 425 | 385 |
| 426 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); | 386 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
| 427 UserManager* user_manager = UserManager::Get(); | 387 UserManager* user_manager = UserManager::Get(); |
| 428 user_manager->UserLoggedIn(username, false); | 388 user_manager->UserLoggedIn(username, false); |
| 429 btl->AddLoginTimeMarker("UserLoggedIn-End", false); | 389 btl->AddLoginTimeMarker("UserLoggedIn-End", false); |
| 430 | 390 |
| 431 // Switch log file as soon as possible. | 391 // Switch log file as soon as possible. |
| 432 if (base::chromeos::IsRunningOnChromeOS()) | 392 if (base::chromeos::IsRunningOnChromeOS()) |
| 433 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); | 393 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); |
| 434 | 394 |
| 435 // Update user's displayed email. | 395 // Update user's displayed email. |
| 436 if (!display_email.empty()) | 396 if (!display_email.empty()) |
| 437 user_manager->SaveUserDisplayEmail(username, display_email); | 397 user_manager->SaveUserDisplayEmail(username, display_email); |
| 438 | 398 |
| 439 password_ = password; | 399 password_ = password; |
| 440 | 400 |
| 441 pending_requests_ = pending_requests; | |
| 442 using_oauth_ = using_oauth; | 401 using_oauth_ = using_oauth; |
| 443 has_web_auth_cookies_ = has_cookies; | 402 has_web_auth_cookies_ = has_cookies; |
| 444 delegate_ = delegate; | 403 delegate_ = delegate; |
| 445 | 404 |
| 446 policy::BrowserPolicyConnector* connector = | 405 policy::BrowserPolicyConnector* connector = |
| 447 g_browser_process->browser_policy_connector(); | 406 g_browser_process->browser_policy_connector(); |
| 448 | 407 |
| 449 // If this is an enterprise device and the user belongs to the enterprise | 408 // If this is an enterprise device and the user belongs to the enterprise |
| 450 // domain, then wait for a policy fetch before logging the user in. This | 409 // domain, then wait for a policy fetch before logging the user in. This |
| 451 // will delay Profile creation until the policy is fetched, so that features | 410 // will delay Profile creation until the policy is fetched, so that features |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 474 // requires the DeviceManagement token. Try to fetch it now. | 433 // requires the DeviceManagement token. Try to fetch it now. |
| 475 // TODO(atwilson): This is somewhat racy, as we are trying to fetch a | 434 // TODO(atwilson): This is somewhat racy, as we are trying to fetch a |
| 476 // DMToken in parallel with loading the cached policy blob (there could | 435 // DMToken in parallel with loading the cached policy blob (there could |
| 477 // already be a DMToken in the cached policy). Once the legacy policy | 436 // already be a DMToken in the cached policy). Once the legacy policy |
| 478 // framework is removed, this code can register a | 437 // framework is removed, this code can register a |
| 479 // CloudPolicyService::Observer to check whether the CloudPolicyClient was | 438 // CloudPolicyService::Observer to check whether the CloudPolicyClient was |
| 480 // able to register itself using the cached policy data, and then only | 439 // able to register itself using the cached policy data, and then only |
| 481 // create a PolicyOAuthFetcher if the client is still unregistered | 440 // create a PolicyOAuthFetcher if the client is still unregistered |
| 482 // (http://crbug.com/143187). | 441 // (http://crbug.com/143187). |
| 483 VLOG(1) << "Profile creation requires policy token, fetching now"; | 442 VLOG(1) << "Profile creation requires policy token, fetching now"; |
| 484 policy_oauth_fetcher_.reset( | 443 login_manager_->RestorePolicyTokens( |
| 485 new PolicyOAuthFetcher(authenticator_->authentication_profile())); | 444 authenticator_->authentication_profile()->GetRequestContext()); |
| 486 policy_oauth_fetcher_->Start(); | |
| 487 } | 445 } |
| 488 } | 446 } |
| 489 | 447 |
| 490 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { | 448 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { |
| 491 if (delegate_ == delegate) | 449 if (delegate_ == delegate) |
| 492 delegate_ = NULL; | 450 delegate_ = NULL; |
| 493 } | 451 } |
| 494 | 452 |
| 495 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { | 453 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { |
| 496 if (UserManager::Get()->IsCurrentUserNew()) | 454 if (UserManager::Get()->IsCurrentUserNew()) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 514 GetNetworkConfigurationUpdater(); | 472 GetNetworkConfigurationUpdater(); |
| 515 if (network_configuration_updater) | 473 if (network_configuration_updater) |
| 516 network_configuration_updater->OnUserPolicyInitialized(); | 474 network_configuration_updater->OnUserPolicyInitialized(); |
| 517 RespectLocalePreference(user_profile); | 475 RespectLocalePreference(user_profile); |
| 518 } | 476 } |
| 519 | 477 |
| 520 void LoginUtilsImpl::OnProfileCreated( | 478 void LoginUtilsImpl::OnProfileCreated( |
| 521 Profile* user_profile, | 479 Profile* user_profile, |
| 522 Profile::CreateStatus status) { | 480 Profile::CreateStatus status) { |
| 523 CHECK(user_profile); | 481 CHECK(user_profile); |
| 524 | |
| 525 if (delegate_) | 482 if (delegate_) |
| 526 delegate_->OnProfileCreated(user_profile); | 483 delegate_->OnProfileCreated(user_profile); |
| 527 | 484 |
| 528 switch (status) { | 485 switch (status) { |
| 529 case Profile::CREATE_STATUS_INITIALIZED: | 486 case Profile::CREATE_STATUS_INITIALIZED: |
| 530 break; | 487 break; |
| 531 case Profile::CREATE_STATUS_CREATED: { | 488 case Profile::CREATE_STATUS_CREATED: { |
| 532 InitProfilePreferences(user_profile); | 489 InitProfilePreferences(user_profile); |
| 533 return; | 490 return; |
| 534 } | 491 } |
| 535 case Profile::CREATE_STATUS_FAIL: | 492 case Profile::CREATE_STATUS_FAIL: |
| 536 default: | 493 default: |
| 537 NOTREACHED(); | 494 NOTREACHED(); |
| 538 return; | 495 return; |
| 539 } | 496 } |
| 540 | 497 |
| 541 BootTimesLoader* btl = BootTimesLoader::Get(); | 498 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 542 btl->AddLoginTimeMarker("UserProfileGotten", false); | 499 btl->AddLoginTimeMarker("UserProfileGotten", false); |
| 543 | 500 |
| 544 if (using_oauth_) { | 501 if (using_oauth_) { |
| 545 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was | |
| 546 // used to fetch policies before Profile creation. | |
| 547 if (policy_oauth_fetcher_.get() && | |
| 548 !policy_oauth_fetcher_->oauth1_token().empty()) { | |
| 549 VLOG(1) << "Resuming profile creation after fetching policy token"; | |
| 550 StoreOAuth1AccessToken(user_profile, | |
| 551 policy_oauth_fetcher_->oauth1_token(), | |
| 552 policy_oauth_fetcher_->oauth1_secret()); | |
| 553 } | |
| 554 | |
| 555 // Transfer proxy authentication cache, cookies (optionally) and server | 502 // Transfer proxy authentication cache, cookies (optionally) and server |
| 556 // bound certs from the profile that was used for authentication. This | 503 // bound certs from the profile that was used for authentication. This |
| 557 // profile contains cookies that auth extension should have already put in | 504 // profile contains cookies that auth extension should have already put in |
| 558 // place that will ensure that the newly created session is authenticated | 505 // place that will ensure that the newly created session is authenticated |
| 559 // for the websites that work with the used authentication schema. | 506 // for the websites that work with the used authentication schema. |
| 560 ProfileAuthData::Transfer(authenticator_->authentication_profile(), | 507 ProfileAuthData::Transfer(authenticator_->authentication_profile(), |
| 561 user_profile, | 508 user_profile, |
| 562 has_web_auth_cookies_, // transfer_cookies | 509 has_web_auth_cookies_, // transfer_cookies |
| 563 base::Bind( | 510 base::Bind( |
| 564 &LoginUtilsImpl::CompleteProfileCreate, | 511 &LoginUtilsImpl::CompleteProfileCreate, |
| 565 AsWeakPtr(), | 512 AsWeakPtr(), |
| 566 user_profile)); | 513 user_profile)); |
| 567 return; | 514 return; |
| 568 } | 515 } |
| 569 | 516 |
| 570 FinalizePrepareProfile(user_profile); | 517 FinalizePrepareProfile(user_profile); |
| 571 } | 518 } |
| 572 | 519 |
| 573 void LoginUtilsImpl::RestoreAuthCookies(Profile* user_profile) { | 520 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { |
| 574 std::string oauth1_token; | 521 RestoreAuthSession(user_profile, has_web_auth_cookies_); |
| 575 std::string oauth1_secret; | 522 FinalizePrepareProfile(user_profile); |
| 576 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || | |
| 577 !has_web_auth_cookies_) { | |
| 578 // Verify OAuth access token when we find it in the profile and always if | |
| 579 // if we don't have cookies. | |
| 580 // TODO(xiyuan): Change back to use authenticator to verify token when | |
| 581 // we support Gaia in lock screen. | |
| 582 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | |
| 583 } else { | |
| 584 // If we don't have it, fetch OAuth1 access token. | |
| 585 // Once we get that, we will kick off individual requests for OAuth2 | |
| 586 // tokens for all our services. | |
| 587 // Use off-the-record profile that was used for this step. It should | |
| 588 // already contain all needed cookies that will let us skip GAIA's user | |
| 589 // authentication UI. | |
| 590 // | |
| 591 // TODO(rickcam) We should use an isolated App here. | |
| 592 oauth1_token_fetcher_.reset( | |
| 593 new OAuth1TokenFetcher(this, | |
| 594 authenticator_->authentication_profile())); | |
| 595 oauth1_token_fetcher_->Start(); | |
| 596 } | |
| 597 } | 523 } |
| 598 | 524 |
| 599 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { | 525 void LoginUtilsImpl::RestoreAuthSession(Profile* user_profile, |
| 600 RestoreAuthCookies(user_profile); | 526 bool restore_from_auth_cookies) { |
| 601 FinalizePrepareProfile(user_profile); | 527 DCHECK(authenticator_ || !restore_from_auth_cookies); |
| 528 // Remove legacy OAuth1 token if we have one. If it's valid, we should already | |
| 529 // have OAuth2 refresh token in TokenService that could be used to retrieve | |
| 530 // all other tokens and credentials. | |
| 531 login_manager_->RestoreSession( | |
| 532 user_profile, | |
| 533 authenticator_ ? | |
| 534 authenticator_->authentication_profile()->GetRequestContext() : | |
| 535 NULL, | |
| 536 restore_from_auth_cookies); | |
| 602 } | 537 } |
| 603 | 538 |
| 604 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { | 539 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { |
| 605 BootTimesLoader* btl = BootTimesLoader::Get(); | 540 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 606 // Own TPM device if, for any reason, it has not been done in EULA | 541 // Own TPM device if, for any reason, it has not been done in EULA |
| 607 // wizard screen. | 542 // wizard screen. |
| 608 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); | 543 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 609 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 544 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
| 610 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | 545 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { |
| 611 if (cryptohome->TpmIsOwned()) { | 546 if (cryptohome->TpmIsOwned()) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 // recorded. | 607 // recorded. |
| 673 RLZTracker::InitRlzFromProfileDelayed( | 608 RLZTracker::InitRlzFromProfileDelayed( |
| 674 user_profile, UserManager::Get()->IsCurrentUserNew(), | 609 user_profile, UserManager::Get()->IsCurrentUserNew(), |
| 675 ping_delay < 0, base::TimeDelta::FromMilliseconds(abs(ping_delay))); | 610 ping_delay < 0, base::TimeDelta::FromMilliseconds(abs(ping_delay))); |
| 676 if (delegate_) | 611 if (delegate_) |
| 677 delegate_->OnRlzInitialized(user_profile); | 612 delegate_->OnRlzInitialized(user_profile); |
| 678 #endif | 613 #endif |
| 679 } | 614 } |
| 680 | 615 |
| 681 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 616 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
| 682 std::string oauth1_token; | 617 RestoreAuthSession(user_profile, false); |
| 683 std::string oauth1_secret; | |
| 684 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | |
| 685 return; | |
| 686 | |
| 687 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), | |
| 688 oauth1_token, oauth1_secret); | |
| 689 } | 618 } |
| 690 | 619 |
| 691 void LoginUtilsImpl::StartSignedInServices( | 620 void LoginUtilsImpl::StartSignedInServices(Profile* user_profile) { |
| 692 Profile* user_profile, | |
| 693 const GaiaAuthConsumer::ClientLoginResult& credentials) { | |
| 694 // Fetch/Create the SigninManager - this will cause the TokenService to load | 621 // Fetch/Create the SigninManager - this will cause the TokenService to load |
| 695 // tokens for the currently signed-in user if the SigninManager hasn't already | 622 // tokens for the currently signed-in user if the SigninManager hasn't already |
| 696 // been initialized. | 623 // been initialized. |
| 697 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); | 624 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); |
| 698 DCHECK(signin); | 625 DCHECK(signin); |
| 699 // Make sure SigninManager is connected to our current user (this should | 626 // Make sure SigninManager is connected to our current user (this should |
| 700 // happen automatically because we set kGoogleServicesUsername in | 627 // happen automatically because we set kGoogleServicesUsername in |
| 701 // OnProfileCreated()). | 628 // OnProfileCreated()). |
| 702 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), | 629 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), |
| 703 signin->GetAuthenticatedUsername()); | 630 signin->GetAuthenticatedUsername()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 715 GoogleServiceSigninSuccessDetails details( | 642 GoogleServiceSigninSuccessDetails details( |
| 716 signin->GetAuthenticatedUsername(), | 643 signin->GetAuthenticatedUsername(), |
| 717 password_); | 644 password_); |
| 718 content::NotificationService::current()->Notify( | 645 content::NotificationService::current()->Notify( |
| 719 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 646 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 720 content::Source<Profile>(user_profile), | 647 content::Source<Profile>(user_profile), |
| 721 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 648 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 722 } | 649 } |
| 723 } | 650 } |
| 724 password_.clear(); | 651 password_.clear(); |
| 725 TokenService* token_service = | |
| 726 TokenServiceFactory::GetForProfile(user_profile); | |
| 727 token_service->UpdateCredentials(credentials); | |
| 728 if (token_service->AreCredentialsValid()) | |
| 729 token_service->StartFetchingTokens(); | |
| 730 } | 652 } |
| 731 | 653 |
| 732 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { | 654 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { |
| 733 DCHECK(profile != NULL); | 655 DCHECK(profile != NULL); |
| 734 PrefService* prefs = profile->GetPrefs(); | 656 PrefService* prefs = profile->GetPrefs(); |
| 735 DCHECK(prefs != NULL); | 657 DCHECK(prefs != NULL); |
| 736 if (g_browser_process == NULL) | 658 if (g_browser_process == NULL) |
| 737 return; | 659 return; |
| 738 | 660 |
| 739 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); | 661 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { | 940 void LoginUtilsImpl::RestoreAuthenticationSession(Profile* user_profile) { |
| 1019 // We don't need to restore session for demo/guest users. | 941 // We don't need to restore session for demo/guest users. |
| 1020 if (!UserManager::Get()->IsUserLoggedIn() || | 942 if (!UserManager::Get()->IsUserLoggedIn() || |
| 1021 UserManager::Get()->IsLoggedInAsGuest() || | 943 UserManager::Get()->IsLoggedInAsGuest() || |
| 1022 UserManager::Get()->IsLoggedInAsDemoUser()) { | 944 UserManager::Get()->IsLoggedInAsDemoUser()) { |
| 1023 return; | 945 return; |
| 1024 } | 946 } |
| 1025 | 947 |
| 1026 if (!net::NetworkChangeNotifier::IsOffline()) { | 948 if (!net::NetworkChangeNotifier::IsOffline()) { |
| 1027 should_restore_auth_session_ = false; | 949 should_restore_auth_session_ = false; |
| 1028 KickStartAuthentication(user_profile); | 950 RestoreAuthSession(user_profile, false); |
| 1029 } else { | 951 } else { |
| 1030 // Even if we're online we should wait till initial | 952 // Even if we're online we should wait till initial |
| 1031 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may | 953 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may |
| 1032 // end up cancelling all request when initial network connection type is | 954 // end up cancelling all request when initial network connection type is |
| 1033 // processed. See http://crbug.com/121643. | 955 // processed. See http://crbug.com/121643. |
| 1034 should_restore_auth_session_ = true; | 956 should_restore_auth_session_ = true; |
| 1035 } | 957 } |
| 1036 } | 958 } |
| 1037 | 959 |
| 1038 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 960 void LoginUtilsImpl::StopBackgroundFetchers() { |
| 1039 std::string oauth1_token; | 961 login_manager_.reset(); |
| 1040 std::string oauth1_secret; | |
| 1041 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | |
| 1042 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | |
| 1043 } | 962 } |
| 1044 | 963 |
| 1045 void LoginUtilsImpl::StopBackgroundFetchers() { | 964 void LoginUtilsImpl::OnCompletedAuthentication(Profile* user_profile) { |
| 1046 policy_oauth_fetcher_.reset(); | 965 StartSignedInServices(user_profile); |
| 1047 oauth1_token_fetcher_.reset(); | |
| 1048 oauth_login_verifier_.reset(); | |
| 1049 } | 966 } |
| 1050 | 967 |
| 1051 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, | 968 void LoginUtilsImpl::OnFoundStoredTokens() { |
| 1052 const std::string& token, | 969 // We don't need authenticator instance any more since its cookie jar |
| 1053 const std::string& secret) { | 970 // is not going to needed to mint OAuth tokens. Reset it so that |
| 1054 FetchPolicyToken(offrecord_profile, token, secret); | |
| 1055 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | |
| 1056 // capable of handling OAuth1 tokens directly. | |
| 1057 } | |
| 1058 | |
| 1059 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | |
| 1060 std::string* token, | |
| 1061 std::string* secret) { | |
| 1062 // Skip reading oauth token if user does not have a valid status. | |
| 1063 if (UserManager::Get()->IsUserLoggedIn() && | |
| 1064 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != | |
| 1065 User::OAUTH_TOKEN_STATUS_VALID) { | |
| 1066 return false; | |
| 1067 } | |
| 1068 | |
| 1069 PrefService* pref_service = user_profile->GetPrefs(); | |
| 1070 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); | |
| 1071 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); | |
| 1072 if (!encoded_token.length() || !encoded_secret.length()) | |
| 1073 return false; | |
| 1074 | |
| 1075 std::string decoded_token = | |
| 1076 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); | |
| 1077 std::string decoded_secret = | |
| 1078 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); | |
| 1079 if (!decoded_token.length() || !decoded_secret.length()) | |
| 1080 return false; | |
| 1081 | |
| 1082 *token = decoded_token; | |
| 1083 *secret = decoded_secret; | |
| 1084 return true; | |
| 1085 } | |
| 1086 | |
| 1087 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, | |
| 1088 const std::string& token, | |
| 1089 const std::string& secret) { | |
| 1090 // First store OAuth1 token + service for the current user profile... | |
| 1091 std::string encrypted_token = | |
| 1092 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token); | |
| 1093 std::string encrypted_secret = | |
| 1094 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret); | |
| 1095 PrefService* pref_service = user_profile->GetPrefs(); | |
| 1096 User* user = UserManager::Get()->GetLoggedInUser(); | |
| 1097 if (!encrypted_token.empty() && !encrypted_secret.empty()) { | |
| 1098 pref_service->SetString(prefs::kOAuth1Token, encrypted_token); | |
| 1099 pref_service->SetString(prefs::kOAuth1Secret, encrypted_secret); | |
| 1100 | |
| 1101 // ...then record the presence of valid OAuth token for this account in | |
| 1102 // local state as well. | |
| 1103 UserManager::Get()->SaveUserOAuthStatus( | |
| 1104 user->email(), User::OAUTH_TOKEN_STATUS_VALID); | |
| 1105 } else { | |
| 1106 LOG(WARNING) << "Failed to get OAuth1 token/secret encrypted."; | |
| 1107 // Set the OAuth status invalid so that the user will go through full | |
| 1108 // GAIA login next time. | |
| 1109 UserManager::Get()->SaveUserOAuthStatus( | |
| 1110 user->email(), User::OAUTH_TOKEN_STATUS_INVALID); | |
| 1111 } | |
| 1112 } | |
| 1113 | |
| 1114 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, | |
| 1115 const std::string& token, | |
| 1116 const std::string& secret) { | |
| 1117 // Kick off verification of OAuth1 access token (via OAuthLogin), this should | |
| 1118 // let us fetch credentials that will be used to initialize sync engine. | |
| 1119 FetchCredentials(user_profile, token, secret); | |
| 1120 | |
| 1121 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); | |
| 1122 } | |
| 1123 | |
| 1124 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | |
| 1125 const std::string& token, | |
| 1126 const std::string& secret) { | |
| 1127 oauth_login_verifier_.reset(new OAuthLoginVerifier( | |
| 1128 this, user_profile, token, secret, | |
| 1129 UserManager::Get()->GetLoggedInUser()->email())); | |
| 1130 oauth_login_verifier_->StartOAuthVerification(); | |
| 1131 } | |
| 1132 | |
| 1133 | |
| 1134 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | |
| 1135 const std::string& token, | |
| 1136 const std::string& secret) { | |
| 1137 // Fetch dm service token now, if it hasn't been fetched yet. | |
| 1138 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { | |
| 1139 // Get the default system profile to use with the policy fetching. If there | |
| 1140 // is no |authenticator_| profile, manually load default system profile. | |
| 1141 // Otherwise, just use |authenticator_|'s profile. | |
| 1142 Profile* profile = NULL; | |
| 1143 if (authenticator_) | |
| 1144 profile = authenticator_->authentication_profile(); | |
| 1145 | |
| 1146 if (!profile) { | |
| 1147 FilePath user_data_dir; | |
| 1148 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
| 1149 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 1150 // Temporarily allow until fix: http://crosbug.com/30391. | |
| 1151 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 1152 profile = profile_manager->GetProfile(user_data_dir)-> | |
| 1153 GetOffTheRecordProfile(); | |
| 1154 } | |
| 1155 | |
| 1156 // Trigger oauth token fetch for user policy. | |
| 1157 policy_oauth_fetcher_.reset(new PolicyOAuthFetcher(profile, token, secret)); | |
| 1158 policy_oauth_fetcher_->Start(); | |
| 1159 } | |
| 1160 | |
| 1161 // TODO(zelidrag): We should add initialization of other services somewhere | |
| 1162 // here as well. This could be handled with TokenService class once it is | |
| 1163 // ready to handle OAuth tokens. | |
| 1164 | |
| 1165 // We don't need authenticator instance any more, reset it so that | |
| 1166 // ScreenLocker would create a separate instance. | 971 // ScreenLocker would create a separate instance. |
| 1167 // TODO(nkostylev): There's a potential race if SL would be created before | |
| 1168 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | |
| 1169 authenticator_ = NULL; | 972 authenticator_ = NULL; |
| 1170 } | 973 } |
| 1171 | 974 |
| 1172 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { | |
| 1173 UserManager::Get()->SaveUserOAuthStatus(user_name, | |
| 1174 User::OAUTH_TOKEN_STATUS_INVALID); | |
| 1175 } | |
| 1176 | |
| 1177 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, | |
| 1178 const std::string& secret) { | |
| 1179 Profile* user_profile = ProfileManager::GetDefaultProfile(); | |
| 1180 StoreOAuth1AccessToken(user_profile, token, secret); | |
| 1181 | |
| 1182 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. If we | |
| 1183 // have just transfered auth cookies out of authenticated cookie jar, there | |
| 1184 // is no need to try to mint them from OAuth token again. | |
| 1185 VerifyOAuth1AccessToken(user_profile, token, secret); | |
| 1186 } | |
| 1187 | |
| 1188 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { | |
| 1189 // TODO(kochi): Show failure notification UI here? | |
| 1190 LOG(ERROR) << "Failed to fetch OAuth1 access token."; | |
| 1191 g_browser_process->browser_policy_connector()->RegisterForUserPolicy( | |
| 1192 EmptyString()); | |
| 1193 } | |
| 1194 | |
| 1195 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | |
| 1196 const std::string& user_name, const std::string& sid, | |
| 1197 const std::string& lsid, const std::string& auth) { | |
| 1198 // Kick off sync engine. | |
| 1199 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | |
| 1200 std::string()); | |
| 1201 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); | |
| 1202 } | |
| 1203 | |
| 1204 | |
| 1205 void LoginUtilsImpl::OnConnectionTypeChanged( | 975 void LoginUtilsImpl::OnConnectionTypeChanged( |
| 1206 net::NetworkChangeNotifier::ConnectionType type) { | 976 net::NetworkChangeNotifier::ConnectionType type) { |
| 977 if (!login_manager_.get()) | |
| 978 return; | |
| 979 | |
| 1207 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && | 980 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && |
| 1208 UserManager::Get()->IsUserLoggedIn()) { | 981 UserManager::Get()->IsUserLoggedIn()) { |
| 1209 if (oauth_login_verifier_.get() && | 982 if (login_manager_->state() == |
| 1210 !oauth_login_verifier_->is_done()) { | 983 OAuthLoginManager::SESSION_RESTORE_IN_PROGRESS) { |
| 1211 // If we come online for the first time after successful offline login, | 984 // If we come online for the first time after successful offline login, |
| 1212 // we need to kick off OAuth token verification process again. | 985 // we need to kick off OAuth token verification process again. |
| 1213 oauth_login_verifier_->ContinueVerification(); | 986 login_manager_->ContinueSessionRestore(); |
| 1214 } else if (should_restore_auth_session_) { | 987 } else if (should_restore_auth_session_) { |
| 1215 should_restore_auth_session_ = false; | 988 should_restore_auth_session_ = false; |
| 1216 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 989 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1217 KickStartAuthentication(user_profile); | 990 RestoreAuthSession(user_profile, has_web_auth_cookies_); |
| 1218 } | 991 } |
| 1219 } | 992 } |
| 1220 } | 993 } |
| 1221 | 994 |
| 1222 void LoginUtilsImpl::Observe(int type, | 995 void LoginUtilsImpl::Observe(int type, |
| 1223 const content::NotificationSource& source, | 996 const content::NotificationSource& source, |
| 1224 const content::NotificationDetails& details) { | 997 const content::NotificationDetails& details) { |
| 1225 switch (type) { | 998 switch (type) { |
| 1226 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { | 999 case chrome::NOTIFICATION_PROFILE_URL_REQUEST_CONTEXT_GETTER_INITIALIZED: { |
| 1227 Profile* profile = content::Source<Profile>(source).ptr(); | 1000 Profile* profile = content::Source<Profile>(source).ptr(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1251 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1024 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 1252 CrosSettings* cros_settings = CrosSettings::Get(); | 1025 CrosSettings* cros_settings = CrosSettings::Get(); |
| 1253 bool allow_new_user = false; | 1026 bool allow_new_user = false; |
| 1254 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1027 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 1255 if (allow_new_user) | 1028 if (allow_new_user) |
| 1256 return true; | 1029 return true; |
| 1257 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1030 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 1258 } | 1031 } |
| 1259 | 1032 |
| 1260 } // namespace chromeos | 1033 } // namespace chromeos |
| OLD | NEW |