| 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 21 matching lines...) Expand all Loading... |
| 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" | 33 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 34 #include "chrome/browser/chromeos/cros/cros_library.h" | 34 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 35 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 35 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 36 #include "chrome/browser/chromeos/cros/network_library.h" | 36 #include "chrome/browser/chromeos/cros/network_library.h" |
| 37 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 37 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 38 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 38 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 39 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 39 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 40 #include "chrome/browser/chromeos/login/language_switch_menu.h" | 40 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
| 41 #include "chrome/browser/chromeos/login/login_display_host.h" | 41 #include "chrome/browser/chromeos/login/login_display_host.h" |
| 42 #include "chrome/browser/chromeos/login/oauth1_login_verifier.h" |
| 42 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" | 43 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" |
| 43 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" | 44 #include "chrome/browser/chromeos/login/oauth_login_manager.h" |
| 44 #include "chrome/browser/chromeos/login/parallel_authenticator.h" | 45 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 45 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" | 46 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" |
| 46 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 47 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 47 #include "chrome/browser/chromeos/login/screen_locker.h" | 48 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 48 #include "chrome/browser/chromeos/login/user_manager.h" | 49 #include "chrome/browser/chromeos/login/user_manager.h" |
| 49 #include "chrome/browser/chromeos/settings/cros_settings.h" | 50 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 50 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 51 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 51 #include "chrome/browser/extensions/extension_service.h" | 52 #include "chrome/browser/extensions/extension_service.h" |
| 52 #include "chrome/browser/first_run/first_run.h" | 53 #include "chrome/browser/first_run/first_run.h" |
| 53 #include "chrome/browser/google/google_util_chromeos.h" | 54 #include "chrome/browser/google/google_util_chromeos.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 #include "chrome/common/pref_names.h" | 76 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 77 #include "chrome/common/url_constants.h" |
| 77 #include "chromeos/chromeos_switches.h" | 78 #include "chromeos/chromeos_switches.h" |
| 78 #include "chromeos/dbus/dbus_thread_manager.h" | 79 #include "chromeos/dbus/dbus_thread_manager.h" |
| 79 #include "chromeos/dbus/session_manager_client.h" | 80 #include "chromeos/dbus/session_manager_client.h" |
| 80 #include "content/public/browser/browser_thread.h" | 81 #include "content/public/browser/browser_thread.h" |
| 81 #include "content/public/browser/notification_observer.h" | 82 #include "content/public/browser/notification_observer.h" |
| 82 #include "content/public/browser/notification_service.h" | 83 #include "content/public/browser/notification_service.h" |
| 83 #include "content/public/common/content_switches.h" | 84 #include "content/public/common/content_switches.h" |
| 84 #include "google_apis/gaia/gaia_auth_consumer.h" | 85 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 86 #include "google_apis/gaia/gaia_constants.h" |
| 85 #include "google_apis/gaia/gaia_urls.h" | 87 #include "google_apis/gaia/gaia_urls.h" |
| 86 #include "googleurl/src/gurl.h" | 88 #include "googleurl/src/gurl.h" |
| 87 #include "media/base/media_switches.h" | 89 #include "media/base/media_switches.h" |
| 88 #include "net/base/network_change_notifier.h" | 90 #include "net/base/network_change_notifier.h" |
| 89 #include "net/url_request/url_request_context.h" | 91 #include "net/url_request/url_request_context.h" |
| 90 #include "net/url_request/url_request_context_getter.h" | 92 #include "net/url_request/url_request_context_getter.h" |
| 91 #include "ui/base/ui_base_switches.h" | 93 #include "ui/base/ui_base_switches.h" |
| 92 #include "ui/compositor/compositor_switches.h" | 94 #include "ui/compositor/compositor_switches.h" |
| 93 #include "ui/gfx/switches.h" | 95 #include "ui/gfx/switches.h" |
| 94 #include "ui/gl/gl_switches.h" | 96 #include "ui/gl/gl_switches.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 175 |
| 174 int pid_; | 176 int pid_; |
| 175 std::string command_line_; | 177 std::string command_line_; |
| 176 PrefService* local_state_; | 178 PrefService* local_state_; |
| 177 base::OneShotTimer<JobRestartRequest> timer_; | 179 base::OneShotTimer<JobRestartRequest> timer_; |
| 178 }; | 180 }; |
| 179 | 181 |
| 180 class LoginUtilsImpl | 182 class LoginUtilsImpl |
| 181 : public LoginUtils, | 183 : public LoginUtils, |
| 182 public OAuth1TokenFetcher::Delegate, | 184 public OAuth1TokenFetcher::Delegate, |
| 183 public OAuthLoginVerifier::Delegate, | 185 public OAuth1LoginVerifier::Delegate, |
| 186 public OAuthLoginManager::Delegate, |
| 184 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 187 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 185 public content::NotificationObserver, | 188 public content::NotificationObserver, |
| 186 public base::SupportsWeakPtr<LoginUtilsImpl> { | 189 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 187 public: | 190 public: |
| 188 LoginUtilsImpl() | 191 LoginUtilsImpl() |
| 189 : pending_requests_(false), | 192 : pending_requests_(false), |
| 190 using_oauth_(false), | 193 using_oauth_(false), |
| 194 force_oauth2_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 195 ::switches::kForceOAuth2)), |
| 191 has_web_auth_cookies_(false), | 196 has_web_auth_cookies_(false), |
| 192 delegate_(NULL), | 197 delegate_(NULL), |
| 193 job_restart_request_(NULL), | 198 job_restart_request_(NULL), |
| 194 should_restore_auth_session_(false), | 199 should_restore_auth_session_(false), |
| 195 url_request_context_getter_(NULL) { | 200 url_request_context_getter_(NULL) { |
| 196 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 201 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 197 // During tests, the browser_process may not be initialized yet causing | 202 // During tests, the browser_process may not be initialized yet causing |
| 198 // this to fail. | 203 // this to fail. |
| 199 if (g_browser_process) { | 204 if (g_browser_process) { |
| 200 registrar_.Add( | 205 registrar_.Add( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 220 bool has_cookies, | 225 bool has_cookies, |
| 221 LoginUtils::Delegate* delegate) OVERRIDE; | 226 LoginUtils::Delegate* delegate) OVERRIDE; |
| 222 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 227 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
| 223 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 228 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
| 224 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 229 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
| 225 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 230 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
| 226 LoginStatusConsumer* consumer) OVERRIDE; | 231 LoginStatusConsumer* consumer) OVERRIDE; |
| 227 virtual void PrewarmAuthentication() OVERRIDE; | 232 virtual void PrewarmAuthentication() OVERRIDE; |
| 228 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; | 233 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
| 229 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 234 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; | 235 virtual void StopBackgroundFetchers() OVERRIDE; |
| 234 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; | 236 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
| 235 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; | 237 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; |
| 236 | 238 |
| 237 // OAuth1TokenFetcher::Delegate overrides. | 239 // OAuth1TokenFetcher::Delegate overrides. |
| 238 void OnOAuth1AccessTokenAvailable(const std::string& token, | 240 void OnOAuth1AccessTokenAvailable(const std::string& token, |
| 239 const std::string& secret) OVERRIDE; | 241 const std::string& secret) OVERRIDE; |
| 240 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; | 242 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; |
| 241 | 243 |
| 242 // OAuthLoginVerifier::Delegate overrides. | 244 // OAuth1LoginVerifier::Delegate overrides. |
| 243 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 245 virtual void OnOAuth1VerificationSucceeded(const std::string& user_name, |
| 244 const std::string& sid, | 246 const std::string& sid, |
| 245 const std::string& lsid, | 247 const std::string& lsid, |
| 246 const std::string& auth) OVERRIDE; | 248 const std::string& auth) OVERRIDE; |
| 247 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | 249 virtual void OnOAuth1VerificationFailed( |
| 250 const std::string& user_name) OVERRIDE; |
| 251 |
| 252 // OAuthLoginManager::Delegate overrides. |
| 253 virtual void OnCompletedAuthentication(Profile* user_profile) OVERRIDE; |
| 248 | 254 |
| 249 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 255 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 250 virtual void OnConnectionTypeChanged( | 256 virtual void OnConnectionTypeChanged( |
| 251 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 257 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 252 | 258 |
| 253 // content::NotificationObserver overrides. | 259 // content::NotificationObserver overrides. |
| 254 virtual void Observe(int type, | 260 virtual void Observe(int type, |
| 255 const content::NotificationSource& source, | 261 const content::NotificationSource& source, |
| 256 const content::NotificationDetails& details) OVERRIDE; | 262 const content::NotificationDetails& details) OVERRIDE; |
| 257 | 263 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 280 const std::string& token, | 286 const std::string& token, |
| 281 const std::string& secret); | 287 const std::string& secret); |
| 282 | 288 |
| 283 // Fetch all secondary (OAuth2) tokens given OAuth1 access |token| and | 289 // Fetch all secondary (OAuth2) tokens given OAuth1 access |token| and |
| 284 // |secret|. | 290 // |secret|. |
| 285 void FetchSecondaryTokens(Profile* offrecord_profile, | 291 void FetchSecondaryTokens(Profile* offrecord_profile, |
| 286 const std::string& token, | 292 const std::string& token, |
| 287 const std::string& secret); | 293 const std::string& secret); |
| 288 | 294 |
| 289 // Fetch user credentials (sid/lsid) given OAuth1 access |token| and |secret|. | 295 // Fetch user credentials (sid/lsid) given OAuth1 access |token| and |secret|. |
| 290 void FetchCredentials(Profile* user_profile, | 296 void FetchCredentialsWithOAuth1(Profile* user_profile, |
| 291 const std::string& token, | 297 const std::string& token, |
| 292 const std::string& secret); | 298 const std::string& secret); |
| 293 | 299 |
| 294 // Fetch enterprise policy OAuth2 given OAuth1 access |token| and |secret|. | 300 // Fetch enterprise policy OAuth2 given OAuth1 access |token| and |secret|. |
| 295 void FetchPolicyToken(Profile* offrecord_profile, | 301 void FetchPolicyToken(Profile* offrecord_profile, |
| 296 const std::string& token, | 302 const std::string& token, |
| 297 const std::string& secret); | 303 const std::string& secret); |
| 298 | 304 |
| 299 // Check user's profile for kApplicationLocale setting. | 305 // Check user's profile for kApplicationLocale setting. |
| 300 void RespectLocalePreference(Profile* pref); | 306 void RespectLocalePreference(Profile* pref); |
| 301 | 307 |
| 308 // Returns true if the OAuth2 refresh token and its previously checked value |
| 309 // (during token-to-cookies exchange) is known to be valid. |
| 310 bool IsOAuth2RefreshTokenValid(Profile* user_profile, |
| 311 const std::string& oauth2_refresh_token); |
| 312 |
| 302 // Initializes basic preferences for newly created profile. | 313 // Initializes basic preferences for newly created profile. |
| 303 void InitProfilePreferences(Profile* user_profile); | 314 void InitProfilePreferences(Profile* user_profile); |
| 304 | 315 |
| 305 // Callback for asynchronous profile creation. | 316 // Callback for asynchronous profile creation. |
| 306 void OnProfileCreated(Profile* profile, | 317 void OnProfileCreated(Profile* profile, |
| 307 Profile::CreateStatus status); | 318 Profile::CreateStatus status); |
| 308 | 319 |
| 309 // Finalized profile preparation. | 320 // Finalized profile preparation. |
| 310 void FinalizePrepareProfile(Profile* user_profile); | 321 void FinalizePrepareProfile(Profile* user_profile); |
| 311 | 322 |
| 312 // Restores GAIA auth cookies for the created profile. | 323 // Restores GAIA auth cookies for the created user profile from OAuth1 token. |
| 313 void RestoreAuthCookies(Profile* user_profile); | 324 void RestoreCookiesFromOAuth1Token(Profile* user_profile); |
| 325 |
| 326 // Restores GAIA auth cookies for the created user profile from OAuth2 token. |
| 327 void RestoreAuthSession(Profile* user_profile); |
| 328 |
| 329 // Removed deprecated OAuth1 token and secret form preference store. |
| 330 void RemoveOAuth1Tokens(Profile* user_profile); |
| 314 | 331 |
| 315 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 332 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 316 void InitRlz(Profile* user_profile, bool disabled); | 333 void InitRlz(Profile* user_profile, bool disabled); |
| 317 | 334 |
| 335 // Initializes and starts TokenSerivice credentials with GAIA credentials. |
| 336 void PrepareTokenService( |
| 337 Profile* profile, |
| 338 const GaiaAuthConsumer::ClientLoginResult& credentials); |
| 339 |
| 340 // Starts signing related services. Initiates TokenService token retreival. |
| 341 void StartSignedInServices(Profile* profile); |
| 342 |
| 318 std::string password_; | 343 std::string password_; |
| 319 bool pending_requests_; | 344 bool pending_requests_; |
| 320 bool using_oauth_; | 345 bool using_oauth_; |
| 346 bool force_oauth2_; |
| 321 // True if the authenrication profile's cookie jar should contain | 347 // True if the authenrication profile's cookie jar should contain |
| 322 // authentication cookies from the authentication extension log in flow. | 348 // authentication cookies from the authentication extension log in flow. |
| 323 bool has_web_auth_cookies_; | 349 bool has_web_auth_cookies_; |
| 324 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 350 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 325 scoped_refptr<Authenticator> authenticator_; | 351 scoped_refptr<Authenticator> authenticator_; |
| 326 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 352 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; |
| 327 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; | 353 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; |
| 328 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | 354 scoped_ptr<OAuth1LoginVerifier> oauth1_login_verifier_; |
| 355 |
| 356 scoped_ptr<OAuthLoginManager> login_manager_; |
| 329 | 357 |
| 330 // Delegate to be fired when the profile will be prepared. | 358 // Delegate to be fired when the profile will be prepared. |
| 331 LoginUtils::Delegate* delegate_; | 359 LoginUtils::Delegate* delegate_; |
| 332 | 360 |
| 333 // Used to restart Chrome to switch to the guest mode. | 361 // Used to restart Chrome to switch to the guest mode. |
| 334 JobRestartRequest* job_restart_request_; | 362 JobRestartRequest* job_restart_request_; |
| 335 | 363 |
| 336 // True if should restore authentication session when notified about | 364 // True if should restore authentication session when notified about |
| 337 // online state change. | 365 // online state change. |
| 338 bool should_restore_auth_session_; | 366 bool should_restore_auth_session_; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 new PolicyOAuthFetcher(authenticator_->authentication_profile())); | 513 new PolicyOAuthFetcher(authenticator_->authentication_profile())); |
| 486 policy_oauth_fetcher_->Start(); | 514 policy_oauth_fetcher_->Start(); |
| 487 } | 515 } |
| 488 } | 516 } |
| 489 | 517 |
| 490 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { | 518 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { |
| 491 if (delegate_ == delegate) | 519 if (delegate_ == delegate) |
| 492 delegate_ = NULL; | 520 delegate_ = NULL; |
| 493 } | 521 } |
| 494 | 522 |
| 523 bool LoginUtilsImpl::IsOAuth2RefreshTokenValid( |
| 524 Profile* user_profile, |
| 525 const std::string& oauth2_refresh_token) { |
| 526 // Do we have a token? |
| 527 if (oauth2_refresh_token.empty()) |
| 528 return false; |
| 529 |
| 530 // Did previous token-to-cookie exchange fail? |
| 531 if (UserManager::Get()->IsUserLoggedIn() && |
| 532 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != |
| 533 User::OAUTH2_TOKEN_STATUS_VALID) { |
| 534 return false; |
| 535 } |
| 536 |
| 537 return true; |
| 538 } |
| 539 |
| 495 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { | 540 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { |
| 496 if (UserManager::Get()->IsCurrentUserNew()) | 541 if (UserManager::Get()->IsCurrentUserNew()) |
| 497 SetFirstLoginPrefs(user_profile->GetPrefs()); | 542 SetFirstLoginPrefs(user_profile->GetPrefs()); |
| 498 // Make sure that the google service username is properly set (we do this | 543 // Make sure that the google service username is properly set (we do this |
| 499 // on every sign in, not just the first login, to deal with existing | 544 // on every sign in, not just the first login, to deal with existing |
| 500 // profiles that might not have it set yet). | 545 // profiles that might not have it set yet). |
| 501 StringPrefMember google_services_username; | 546 StringPrefMember google_services_username; |
| 502 google_services_username.Init(prefs::kGoogleServicesUsername, | 547 google_services_username.Init(prefs::kGoogleServicesUsername, |
| 503 user_profile->GetPrefs()); | 548 user_profile->GetPrefs()); |
| 504 google_services_username.SetValue( | 549 google_services_username.SetValue( |
| 505 UserManager::Get()->GetLoggedInUser()->display_email()); | 550 UserManager::Get()->GetLoggedInUser()->display_email()); |
| 506 // Make sure we flip every profile to not share proxies if the user hasn't | 551 // Make sure we flip every profile to not share proxies if the user hasn't |
| 507 // specified so explicitly. | 552 // specified so explicitly. |
| 508 const PrefService::Preference* use_shared_proxies_pref = | 553 const PrefService::Preference* use_shared_proxies_pref = |
| 509 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies); | 554 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies); |
| 510 if (use_shared_proxies_pref->IsDefaultValue()) | 555 if (use_shared_proxies_pref->IsDefaultValue()) |
| 511 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); | 556 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); |
| 512 policy::NetworkConfigurationUpdater* network_configuration_updater = | 557 policy::NetworkConfigurationUpdater* network_configuration_updater = |
| 513 g_browser_process->browser_policy_connector()-> | 558 g_browser_process->browser_policy_connector()-> |
| 514 GetNetworkConfigurationUpdater(); | 559 GetNetworkConfigurationUpdater(); |
| 515 if (network_configuration_updater) | 560 if (network_configuration_updater) |
| 516 network_configuration_updater->OnUserPolicyInitialized(); | 561 network_configuration_updater->OnUserPolicyInitialized(); |
| 517 RespectLocalePreference(user_profile); | 562 RespectLocalePreference(user_profile); |
| 518 } | 563 } |
| 519 | 564 |
| 520 void LoginUtilsImpl::OnProfileCreated( | 565 void LoginUtilsImpl::OnProfileCreated( |
| 521 Profile* user_profile, | 566 Profile* user_profile, |
| 522 Profile::CreateStatus status) { | 567 Profile::CreateStatus status) { |
| 523 CHECK(user_profile); | 568 CHECK(user_profile); |
| 524 | |
| 525 if (delegate_) | 569 if (delegate_) |
| 526 delegate_->OnProfileCreated(user_profile); | 570 delegate_->OnProfileCreated(user_profile); |
| 527 | 571 |
| 528 switch (status) { | 572 switch (status) { |
| 529 case Profile::CREATE_STATUS_INITIALIZED: | 573 case Profile::CREATE_STATUS_INITIALIZED: |
| 530 break; | 574 break; |
| 531 case Profile::CREATE_STATUS_CREATED: { | 575 case Profile::CREATE_STATUS_CREATED: { |
| 532 InitProfilePreferences(user_profile); | 576 InitProfilePreferences(user_profile); |
| 533 return; | 577 return; |
| 534 } | 578 } |
| 535 case Profile::CREATE_STATUS_FAIL: | 579 case Profile::CREATE_STATUS_FAIL: |
| 536 default: | 580 default: |
| 537 NOTREACHED(); | 581 NOTREACHED(); |
| 538 return; | 582 return; |
| 539 } | 583 } |
| 540 | 584 |
| 541 BootTimesLoader* btl = BootTimesLoader::Get(); | 585 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 542 btl->AddLoginTimeMarker("UserProfileGotten", false); | 586 btl->AddLoginTimeMarker("UserProfileGotten", false); |
| 543 | 587 |
| 544 if (using_oauth_) { | 588 if (using_oauth_) { |
| 545 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was | 589 if (!force_oauth2_) { |
| 546 // used to fetch policies before Profile creation. | 590 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was |
| 547 if (policy_oauth_fetcher_.get() && | 591 // used to fetch policies before Profile creation. |
| 548 !policy_oauth_fetcher_->oauth1_token().empty()) { | 592 if (policy_oauth_fetcher_.get() && |
| 549 VLOG(1) << "Resuming profile creation after fetching policy token"; | 593 !policy_oauth_fetcher_->oauth1_token().empty()) { |
| 550 StoreOAuth1AccessToken(user_profile, | 594 VLOG(1) << "Resuming profile creation after fetching policy token"; |
| 551 policy_oauth_fetcher_->oauth1_token(), | 595 StoreOAuth1AccessToken(user_profile, |
| 552 policy_oauth_fetcher_->oauth1_secret()); | 596 policy_oauth_fetcher_->oauth1_token(), |
| 597 policy_oauth_fetcher_->oauth1_secret()); |
| 598 } |
| 599 } else { |
| 600 // TODO(mnissler): Figure out what to do here in OAuth2 case. |
| 553 } | 601 } |
| 554 | 602 |
| 555 // Transfer proxy authentication cache, cookies (optionally) and server | 603 // Transfer proxy authentication cache, cookies (optionally) and server |
| 556 // bound certs from the profile that was used for authentication. This | 604 // bound certs from the profile that was used for authentication. This |
| 557 // profile contains cookies that auth extension should have already put in | 605 // profile contains cookies that auth extension should have already put in |
| 558 // place that will ensure that the newly created session is authenticated | 606 // place that will ensure that the newly created session is authenticated |
| 559 // for the websites that work with the used authentication schema. | 607 // for the websites that work with the used authentication schema. |
| 560 ProfileAuthData::Transfer(authenticator_->authentication_profile(), | 608 ProfileAuthData::Transfer(authenticator_->authentication_profile(), |
| 561 user_profile, | 609 user_profile, |
| 562 has_web_auth_cookies_, // transfer_cookies | 610 has_web_auth_cookies_, // transfer_cookies |
| 563 base::Bind( | 611 base::Bind( |
| 564 &LoginUtilsImpl::CompleteProfileCreate, | 612 &LoginUtilsImpl::CompleteProfileCreate, |
| 565 AsWeakPtr(), | 613 AsWeakPtr(), |
| 566 user_profile)); | 614 user_profile)); |
| 567 return; | 615 return; |
| 568 } | 616 } |
| 569 | 617 |
| 570 FinalizePrepareProfile(user_profile); | 618 FinalizePrepareProfile(user_profile); |
| 571 } | 619 } |
| 572 | 620 |
| 573 void LoginUtilsImpl::RestoreAuthCookies(Profile* user_profile) { | 621 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { |
| 622 if (force_oauth2_) |
| 623 RestoreAuthSession(user_profile); |
| 624 else |
| 625 RestoreCookiesFromOAuth1Token(user_profile); |
| 626 |
| 627 FinalizePrepareProfile(user_profile); |
| 628 } |
| 629 |
| 630 void LoginUtilsImpl::RestoreCookiesFromOAuth1Token(Profile* user_profile) { |
| 574 std::string oauth1_token; | 631 std::string oauth1_token; |
| 575 std::string oauth1_secret; | 632 std::string oauth1_secret; |
| 576 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || | 633 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || |
| 577 !has_web_auth_cookies_) { | 634 !has_web_auth_cookies_) { |
| 578 // Verify OAuth access token when we find it in the profile and always if | 635 // Verify OAuth access token when we find it in the profile and always if |
| 579 // if we don't have cookies. | 636 // if we don't have cookies. |
| 580 // TODO(xiyuan): Change back to use authenticator to verify token when | 637 // TODO(xiyuan): Change back to use authenticator to verify token when |
| 581 // we support Gaia in lock screen. | 638 // we support Gaia in lock screen. |
| 582 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 639 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
| 583 } else { | 640 } else { |
| 584 // If we don't have it, fetch OAuth1 access token. | 641 // If we don't have it, fetch OAuth1 access token. |
| 585 // Once we get that, we will kick off individual requests for OAuth2 | 642 // Once we get that, we will kick off individual requests for OAuth2 |
| 586 // tokens for all our services. | 643 // tokens for all our services. |
| 587 // Use off-the-record profile that was used for this step. It should | 644 // 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 | 645 // already contain all needed cookies that will let us skip GAIA's user |
| 589 // authentication UI. | 646 // authentication UI. |
| 590 // | 647 // |
| 591 // TODO(rickcam) We should use an isolated App here. | 648 // TODO(rickcam) We should use an isolated App here. |
| 592 oauth1_token_fetcher_.reset( | 649 oauth1_token_fetcher_.reset( |
| 593 new OAuth1TokenFetcher(this, | 650 new OAuth1TokenFetcher(this, |
| 594 authenticator_->authentication_profile())); | 651 authenticator_->authentication_profile())); |
| 595 oauth1_token_fetcher_->Start(); | 652 oauth1_token_fetcher_->Start(); |
| 596 } | 653 } |
| 597 } | 654 } |
| 598 | 655 |
| 599 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { | 656 void LoginUtilsImpl::RemoveOAuth1Tokens(Profile* user_profile) { |
| 600 RestoreAuthCookies(user_profile); | 657 PrefServiceSyncable* prefs = user_profile->GetPrefs(); |
| 601 FinalizePrepareProfile(user_profile); | 658 prefs->RegisterStringPref(prefs::kOAuth1Token, |
| 659 "", |
| 660 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 661 prefs->RegisterStringPref(prefs::kOAuth1Secret, |
| 662 "", |
| 663 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 664 prefs->ClearPref(prefs::kOAuth1Token); |
| 665 prefs->ClearPref(prefs::kOAuth1Secret); |
| 666 prefs->UnregisterPreference(prefs::kOAuth1Token); |
| 667 prefs->UnregisterPreference(prefs::kOAuth1Secret); |
| 668 } |
| 669 |
| 670 void LoginUtilsImpl::RestoreAuthSession(Profile* user_profile) { |
| 671 // Remove legacy OAuth1 token if we have one. If it's valid, we should already |
| 672 // have OAuth2 refresh token in TokenService that could be used to retreive |
| 673 // all other tokens and credentials. |
| 674 RemoveOAuth1Tokens(user_profile); |
| 675 login_manager_.reset( |
| 676 new OAuthLoginManager(this, |
| 677 user_profile, |
| 678 authenticator_->authentication_profile(), |
| 679 has_web_auth_cookies_)); |
| 680 login_manager_->RestoreOAuth2Tokens(); |
| 602 } | 681 } |
| 603 | 682 |
| 604 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { | 683 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { |
| 605 BootTimesLoader* btl = BootTimesLoader::Get(); | 684 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 606 // Own TPM device if, for any reason, it has not been done in EULA | 685 // Own TPM device if, for any reason, it has not been done in EULA |
| 607 // wizard screen. | 686 // wizard screen. |
| 608 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); | 687 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 609 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 688 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
| 610 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | 689 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { |
| 611 if (cryptohome->TpmIsOwned()) { | 690 if (cryptohome->TpmIsOwned()) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 760 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
| 682 std::string oauth1_token; | 761 std::string oauth1_token; |
| 683 std::string oauth1_secret; | 762 std::string oauth1_secret; |
| 684 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 763 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 685 return; | 764 return; |
| 686 | 765 |
| 687 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), | 766 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), |
| 688 oauth1_token, oauth1_secret); | 767 oauth1_token, oauth1_secret); |
| 689 } | 768 } |
| 690 | 769 |
| 691 void LoginUtilsImpl::StartSignedInServices( | 770 void LoginUtilsImpl::PrepareTokenService( |
| 692 Profile* user_profile, | 771 Profile* user_profile, |
| 693 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 772 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 773 TokenService* token_service = |
| 774 TokenServiceFactory::GetForProfile(user_profile); |
| 775 token_service->UpdateCredentials(credentials); |
| 776 StartSignedInServices(user_profile); |
| 777 } |
| 778 |
| 779 void LoginUtilsImpl::StartSignedInServices(Profile* user_profile) { |
| 694 // Fetch/Create the SigninManager - this will cause the TokenService to load | 780 // 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 | 781 // tokens for the currently signed-in user if the SigninManager hasn't already |
| 696 // been initialized. | 782 // been initialized. |
| 697 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); | 783 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); |
| 698 DCHECK(signin); | 784 DCHECK(signin); |
| 699 // Make sure SigninManager is connected to our current user (this should | 785 // Make sure SigninManager is connected to our current user (this should |
| 700 // happen automatically because we set kGoogleServicesUsername in | 786 // happen automatically because we set kGoogleServicesUsername in |
| 701 // OnProfileCreated()). | 787 // OnProfileCreated()). |
| 702 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), | 788 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), |
| 703 signin->GetAuthenticatedUsername()); | 789 signin->GetAuthenticatedUsername()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 717 password_); | 803 password_); |
| 718 content::NotificationService::current()->Notify( | 804 content::NotificationService::current()->Notify( |
| 719 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 805 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 720 content::Source<Profile>(user_profile), | 806 content::Source<Profile>(user_profile), |
| 721 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 807 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 722 } | 808 } |
| 723 } | 809 } |
| 724 password_.clear(); | 810 password_.clear(); |
| 725 TokenService* token_service = | 811 TokenService* token_service = |
| 726 TokenServiceFactory::GetForProfile(user_profile); | 812 TokenServiceFactory::GetForProfile(user_profile); |
| 727 token_service->UpdateCredentials(credentials); | |
| 728 if (token_service->AreCredentialsValid()) | 813 if (token_service->AreCredentialsValid()) |
| 729 token_service->StartFetchingTokens(); | 814 token_service->StartFetchingTokens(); |
| 730 } | 815 } |
| 731 | 816 |
| 732 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { | 817 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { |
| 733 DCHECK(profile != NULL); | 818 DCHECK(profile != NULL); |
| 734 PrefService* prefs = profile->GetPrefs(); | 819 PrefService* prefs = profile->GetPrefs(); |
| 735 DCHECK(prefs != NULL); | 820 DCHECK(prefs != NULL); |
| 736 if (g_browser_process == NULL) | 821 if (g_browser_process == NULL) |
| 737 return; | 822 return; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 1125 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { |
| 1041 std::string oauth1_token; | 1126 std::string oauth1_token; |
| 1042 std::string oauth1_secret; | 1127 std::string oauth1_secret; |
| 1043 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1128 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 1044 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 1129 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
| 1045 } | 1130 } |
| 1046 | 1131 |
| 1047 void LoginUtilsImpl::StopBackgroundFetchers() { | 1132 void LoginUtilsImpl::StopBackgroundFetchers() { |
| 1048 policy_oauth_fetcher_.reset(); | 1133 policy_oauth_fetcher_.reset(); |
| 1049 oauth1_token_fetcher_.reset(); | 1134 oauth1_token_fetcher_.reset(); |
| 1050 oauth_login_verifier_.reset(); | 1135 oauth1_login_verifier_.reset(); |
| 1051 } | 1136 } |
| 1052 | 1137 |
| 1053 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, | 1138 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, |
| 1054 const std::string& token, | 1139 const std::string& token, |
| 1055 const std::string& secret) { | 1140 const std::string& secret) { |
| 1056 FetchPolicyToken(offrecord_profile, token, secret); | 1141 FetchPolicyToken(offrecord_profile, token, secret); |
| 1057 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 1142 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
| 1058 // capable of handling OAuth1 tokens directly. | 1143 // capable of handling OAuth1 tokens directly. |
| 1059 } | 1144 } |
| 1060 | 1145 |
| 1061 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 1146 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
| 1062 std::string* token, | 1147 std::string* token, |
| 1063 std::string* secret) { | 1148 std::string* secret) { |
| 1064 // Skip reading oauth token if user does not have a valid status. | 1149 // Skip reading oauth token if user does not have a valid status. |
| 1065 if (UserManager::Get()->IsUserLoggedIn() && | 1150 if (UserManager::Get()->IsUserLoggedIn() && |
| 1066 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != | 1151 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != |
| 1067 User::OAUTH_TOKEN_STATUS_VALID) { | 1152 User::OAUTH1_TOKEN_STATUS_VALID) { |
| 1068 return false; | 1153 return false; |
| 1069 } | 1154 } |
| 1070 | 1155 |
| 1071 PrefService* pref_service = user_profile->GetPrefs(); | 1156 PrefService* pref_service = user_profile->GetPrefs(); |
| 1072 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); | 1157 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); |
| 1073 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); | 1158 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); |
| 1074 if (!encoded_token.length() || !encoded_secret.length()) | 1159 if (!encoded_token.length() || !encoded_secret.length()) |
| 1075 return false; | 1160 return false; |
| 1076 | 1161 |
| 1077 std::string decoded_token = | 1162 std::string decoded_token = |
| 1078 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); | 1163 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); |
| 1079 std::string decoded_secret = | 1164 std::string decoded_secret = |
| 1080 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); | 1165 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); |
| 1166 |
| 1081 if (!decoded_token.length() || !decoded_secret.length()) | 1167 if (!decoded_token.length() || !decoded_secret.length()) |
| 1082 return false; | 1168 return false; |
| 1083 | 1169 |
| 1084 *token = decoded_token; | 1170 *token = decoded_token; |
| 1085 *secret = decoded_secret; | 1171 *secret = decoded_secret; |
| 1086 return true; | 1172 return true; |
| 1087 } | 1173 } |
| 1088 | 1174 |
| 1089 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, | 1175 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, |
| 1090 const std::string& token, | 1176 const std::string& token, |
| 1091 const std::string& secret) { | 1177 const std::string& secret) { |
| 1092 // First store OAuth1 token + service for the current user profile... | 1178 // First store OAuth1 token + service for the current user profile... |
| 1093 std::string encrypted_token = | 1179 std::string encrypted_token = |
| 1094 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token); | 1180 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token); |
| 1095 std::string encrypted_secret = | 1181 std::string encrypted_secret = |
| 1096 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret); | 1182 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret); |
| 1183 |
| 1097 PrefService* pref_service = user_profile->GetPrefs(); | 1184 PrefService* pref_service = user_profile->GetPrefs(); |
| 1098 User* user = UserManager::Get()->GetLoggedInUser(); | 1185 User* user = UserManager::Get()->GetLoggedInUser(); |
| 1099 if (!encrypted_token.empty() && !encrypted_secret.empty()) { | 1186 if (!encrypted_token.empty() && !encrypted_secret.empty()) { |
| 1100 pref_service->SetString(prefs::kOAuth1Token, encrypted_token); | 1187 pref_service->SetString(prefs::kOAuth1Token, encrypted_token); |
| 1101 pref_service->SetString(prefs::kOAuth1Secret, encrypted_secret); | 1188 pref_service->SetString(prefs::kOAuth1Secret, encrypted_secret); |
| 1102 | 1189 |
| 1103 // ...then record the presence of valid OAuth token for this account in | 1190 // ...then record the presence of valid OAuth token for this account in |
| 1104 // local state as well. | 1191 // local state as well. |
| 1105 UserManager::Get()->SaveUserOAuthStatus( | 1192 UserManager::Get()->SaveUserOAuthStatus( |
| 1106 user->email(), User::OAUTH_TOKEN_STATUS_VALID); | 1193 user->email(), User::OAUTH1_TOKEN_STATUS_VALID); |
| 1107 } else { | 1194 } else { |
| 1108 LOG(WARNING) << "Failed to get OAuth1 token/secret encrypted."; | 1195 LOG(WARNING) << "Failed to get OAuth1 token/secret encrypted."; |
| 1109 // Set the OAuth status invalid so that the user will go through full | 1196 // Set the OAuth status invalid so that the user will go through full |
| 1110 // GAIA login next time. | 1197 // GAIA login next time. |
| 1111 UserManager::Get()->SaveUserOAuthStatus( | 1198 UserManager::Get()->SaveUserOAuthStatus( |
| 1112 user->email(), User::OAUTH_TOKEN_STATUS_INVALID); | 1199 user->email(), User::OAUTH1_TOKEN_STATUS_INVALID); |
| 1113 } | 1200 } |
| 1114 } | 1201 } |
| 1115 | 1202 |
| 1116 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, | 1203 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, |
| 1117 const std::string& token, | 1204 const std::string& token, |
| 1118 const std::string& secret) { | 1205 const std::string& secret) { |
| 1119 // Kick off verification of OAuth1 access token (via OAuthLogin), this should | 1206 // Kick off verification of OAuth1 access token (via OAuthLogin), this should |
| 1120 // let us fetch credentials that will be used to initialize sync engine. | 1207 // let us fetch credentials that will be used to initialize sync engine. |
| 1121 FetchCredentials(user_profile, token, secret); | 1208 FetchCredentialsWithOAuth1(user_profile, token, secret); |
| 1122 | 1209 |
| 1123 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); | 1210 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); |
| 1124 } | 1211 } |
| 1125 | 1212 |
| 1126 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | 1213 void LoginUtilsImpl::FetchCredentialsWithOAuth1(Profile* user_profile, |
| 1127 const std::string& token, | 1214 const std::string& token, |
| 1128 const std::string& secret) { | 1215 const std::string& secret) { |
| 1129 oauth_login_verifier_.reset(new OAuthLoginVerifier( | 1216 oauth1_login_verifier_.reset(new OAuth1LoginVerifier( |
| 1130 this, user_profile, token, secret, | 1217 this, user_profile, token, secret, |
| 1131 UserManager::Get()->GetLoggedInUser()->email())); | 1218 UserManager::Get()->GetLoggedInUser()->email())); |
| 1132 oauth_login_verifier_->StartOAuthVerification(); | 1219 oauth1_login_verifier_->StartOAuthVerification(); |
| 1133 } | 1220 } |
| 1134 | 1221 |
| 1135 | 1222 |
| 1136 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | 1223 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, |
| 1137 const std::string& token, | 1224 const std::string& token, |
| 1138 const std::string& secret) { | 1225 const std::string& secret) { |
| 1139 // Fetch dm service token now, if it hasn't been fetched yet. | 1226 // Fetch dm service token now, if it hasn't been fetched yet. |
| 1140 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { | 1227 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { |
| 1141 // Get the default system profile to use with the policy fetching. If there | 1228 // Get the default system profile to use with the policy fetching. If there |
| 1142 // is no |authenticator_| profile, manually load default system profile. | 1229 // is no |authenticator_| profile, manually load default system profile. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1164 // here as well. This could be handled with TokenService class once it is | 1251 // here as well. This could be handled with TokenService class once it is |
| 1165 // ready to handle OAuth tokens. | 1252 // ready to handle OAuth tokens. |
| 1166 | 1253 |
| 1167 // We don't need authenticator instance any more, reset it so that | 1254 // We don't need authenticator instance any more, reset it so that |
| 1168 // ScreenLocker would create a separate instance. | 1255 // ScreenLocker would create a separate instance. |
| 1169 // TODO(nkostylev): There's a potential race if SL would be created before | 1256 // TODO(nkostylev): There's a potential race if SL would be created before |
| 1170 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | 1257 // OAuth tokens are fetched. It would use incorrect Authenticator instance. |
| 1171 authenticator_ = NULL; | 1258 authenticator_ = NULL; |
| 1172 } | 1259 } |
| 1173 | 1260 |
| 1174 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { | 1261 void LoginUtilsImpl::OnOAuth1VerificationFailed(const std::string& user_name) { |
| 1175 UserManager::Get()->SaveUserOAuthStatus(user_name, | 1262 UserManager::Get()->SaveUserOAuthStatus(user_name, |
| 1176 User::OAUTH_TOKEN_STATUS_INVALID); | 1263 User::OAUTH1_TOKEN_STATUS_INVALID); |
| 1177 } | 1264 } |
| 1178 | 1265 |
| 1179 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, | 1266 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, |
| 1180 const std::string& secret) { | 1267 const std::string& secret) { |
| 1181 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1268 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1182 StoreOAuth1AccessToken(user_profile, token, secret); | 1269 StoreOAuth1AccessToken(user_profile, token, secret); |
| 1183 | 1270 |
| 1184 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. If we | 1271 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. If we |
| 1185 // have just transfered auth cookies out of authenticated cookie jar, there | 1272 // have just transfered auth cookies out of authenticated cookie jar, there |
| 1186 // is no need to try to mint them from OAuth token again. | 1273 // is no need to try to mint them from OAuth token again. |
| 1187 VerifyOAuth1AccessToken(user_profile, token, secret); | 1274 VerifyOAuth1AccessToken(user_profile, token, secret); |
| 1188 } | 1275 } |
| 1189 | 1276 |
| 1190 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { | 1277 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { |
| 1191 // TODO(kochi): Show failure notification UI here? | 1278 // TODO(kochi): Show failure notification UI here? |
| 1192 LOG(ERROR) << "Failed to fetch OAuth1 access token."; | 1279 LOG(ERROR) << "Failed to fetch OAuth1 access token."; |
| 1193 g_browser_process->browser_policy_connector()->RegisterForUserPolicy( | 1280 g_browser_process->browser_policy_connector()->RegisterForUserPolicy( |
| 1194 EmptyString()); | 1281 EmptyString()); |
| 1195 } | 1282 } |
| 1196 | 1283 |
| 1197 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | 1284 void LoginUtilsImpl::OnOAuth1VerificationSucceeded( |
| 1198 const std::string& user_name, const std::string& sid, | 1285 const std::string& user_name, const std::string& sid, |
| 1199 const std::string& lsid, const std::string& auth) { | 1286 const std::string& lsid, const std::string& auth) { |
| 1200 // Kick off sync engine. | 1287 // Kick off sync engine. |
| 1201 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | 1288 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, |
| 1202 std::string()); | 1289 std::string()); |
| 1203 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); | 1290 PrepareTokenService(ProfileManager::GetDefaultProfile(), credentials); |
| 1204 } | 1291 } |
| 1205 | 1292 |
| 1293 void LoginUtilsImpl::OnCompletedAuthentication(Profile* user_profile) { |
| 1294 StartSignedInServices(user_profile); |
| 1295 } |
| 1206 | 1296 |
| 1207 void LoginUtilsImpl::OnConnectionTypeChanged( | 1297 void LoginUtilsImpl::OnConnectionTypeChanged( |
| 1208 net::NetworkChangeNotifier::ConnectionType type) { | 1298 net::NetworkChangeNotifier::ConnectionType type) { |
| 1209 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && | 1299 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && |
| 1210 UserManager::Get()->IsUserLoggedIn()) { | 1300 UserManager::Get()->IsUserLoggedIn()) { |
| 1211 if (oauth_login_verifier_.get() && | 1301 if (oauth1_login_verifier_.get() && |
| 1212 !oauth_login_verifier_->is_done()) { | 1302 !oauth1_login_verifier_->is_done()) { |
| 1213 // If we come online for the first time after successful offline login, | 1303 // If we come online for the first time after successful offline login, |
| 1214 // we need to kick off OAuth token verification process again. | 1304 // we need to kick off OAuth token verification process again. |
| 1215 oauth_login_verifier_->ContinueVerification(); | 1305 oauth1_login_verifier_->ContinueVerification(); |
| 1216 } else if (should_restore_auth_session_) { | 1306 } else if (should_restore_auth_session_) { |
| 1217 should_restore_auth_session_ = false; | 1307 should_restore_auth_session_ = false; |
| 1218 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1308 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1219 KickStartAuthentication(user_profile); | 1309 KickStartAuthentication(user_profile); |
| 1220 } | 1310 } |
| 1221 } | 1311 } |
| 1222 } | 1312 } |
| 1223 | 1313 |
| 1224 void LoginUtilsImpl::Observe(int type, | 1314 void LoginUtilsImpl::Observe(int type, |
| 1225 const content::NotificationSource& source, | 1315 const content::NotificationSource& source, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1253 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1343 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 1254 CrosSettings* cros_settings = CrosSettings::Get(); | 1344 CrosSettings* cros_settings = CrosSettings::Get(); |
| 1255 bool allow_new_user = false; | 1345 bool allow_new_user = false; |
| 1256 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1346 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 1257 if (allow_new_user) | 1347 if (allow_new_user) |
| 1258 return true; | 1348 return true; |
| 1259 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1349 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 1260 } | 1350 } |
| 1261 | 1351 |
| 1262 } // namespace chromeos | 1352 } // namespace chromeos |
| OLD | NEW |