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 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/login_manager.h" | |
| 43 #include "chrome/browser/chromeos/login/oauth1_login_verifier.h" | |
| 42 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" | 44 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" |
| 43 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" | 45 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h" |
| 46 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h" | |
| 44 #include "chrome/browser/chromeos/login/parallel_authenticator.h" | 47 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 45 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" | 48 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" |
| 46 #include "chrome/browser/chromeos/login/profile_auth_data.h" | 49 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 47 #include "chrome/browser/chromeos/login/screen_locker.h" | 50 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 48 #include "chrome/browser/chromeos/login/user_manager.h" | 51 #include "chrome/browser/chromeos/login/user_manager.h" |
| 49 #include "chrome/browser/chromeos/settings/cros_settings.h" | 52 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 50 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 53 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 51 #include "chrome/browser/extensions/extension_service.h" | 54 #include "chrome/browser/extensions/extension_service.h" |
| 52 #include "chrome/browser/first_run/first_run.h" | 55 #include "chrome/browser/first_run/first_run.h" |
| 53 #include "chrome/browser/google/google_util_chromeos.h" | 56 #include "chrome/browser/google/google_util_chromeos.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 75 #include "chrome/common/pref_names.h" | 78 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 79 #include "chrome/common/url_constants.h" |
| 77 #include "chromeos/chromeos_switches.h" | 80 #include "chromeos/chromeos_switches.h" |
| 78 #include "chromeos/dbus/dbus_thread_manager.h" | 81 #include "chromeos/dbus/dbus_thread_manager.h" |
| 79 #include "chromeos/dbus/session_manager_client.h" | 82 #include "chromeos/dbus/session_manager_client.h" |
| 80 #include "content/public/browser/browser_thread.h" | 83 #include "content/public/browser/browser_thread.h" |
| 81 #include "content/public/browser/notification_observer.h" | 84 #include "content/public/browser/notification_observer.h" |
| 82 #include "content/public/browser/notification_service.h" | 85 #include "content/public/browser/notification_service.h" |
| 83 #include "content/public/common/content_switches.h" | 86 #include "content/public/common/content_switches.h" |
| 84 #include "google_apis/gaia/gaia_auth_consumer.h" | 87 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 88 #include "google_apis/gaia/gaia_constants.h" | |
| 85 #include "google_apis/gaia/gaia_urls.h" | 89 #include "google_apis/gaia/gaia_urls.h" |
| 86 #include "googleurl/src/gurl.h" | 90 #include "googleurl/src/gurl.h" |
| 87 #include "media/base/media_switches.h" | 91 #include "media/base/media_switches.h" |
| 88 #include "net/base/network_change_notifier.h" | 92 #include "net/base/network_change_notifier.h" |
| 89 #include "net/url_request/url_request_context.h" | 93 #include "net/url_request/url_request_context.h" |
| 90 #include "net/url_request/url_request_context_getter.h" | 94 #include "net/url_request/url_request_context_getter.h" |
| 91 #include "ui/base/ui_base_switches.h" | 95 #include "ui/base/ui_base_switches.h" |
| 92 #include "ui/compositor/compositor_switches.h" | 96 #include "ui/compositor/compositor_switches.h" |
| 93 #include "ui/gfx/switches.h" | 97 #include "ui/gfx/switches.h" |
| 94 #include "ui/gl/gl_switches.h" | 98 #include "ui/gl/gl_switches.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 177 |
| 174 int pid_; | 178 int pid_; |
| 175 std::string command_line_; | 179 std::string command_line_; |
| 176 PrefService* local_state_; | 180 PrefService* local_state_; |
| 177 base::OneShotTimer<JobRestartRequest> timer_; | 181 base::OneShotTimer<JobRestartRequest> timer_; |
| 178 }; | 182 }; |
| 179 | 183 |
| 180 class LoginUtilsImpl | 184 class LoginUtilsImpl |
| 181 : public LoginUtils, | 185 : public LoginUtils, |
| 182 public OAuth1TokenFetcher::Delegate, | 186 public OAuth1TokenFetcher::Delegate, |
| 183 public OAuthLoginVerifier::Delegate, | 187 public OAuth1LoginVerifier::Delegate, |
| 188 public LoginManager::Delegate, | |
| 189 public OAuth2TokenFetcher::Delegate, | |
| 184 public net::NetworkChangeNotifier::ConnectionTypeObserver, | 190 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 185 public content::NotificationObserver, | 191 public content::NotificationObserver, |
| 186 public base::SupportsWeakPtr<LoginUtilsImpl> { | 192 public base::SupportsWeakPtr<LoginUtilsImpl> { |
| 187 public: | 193 public: |
| 188 LoginUtilsImpl() | 194 LoginUtilsImpl() |
| 189 : pending_requests_(false), | 195 : pending_requests_(false), |
| 190 using_oauth_(false), | 196 using_oauth_(false), |
| 197 force_oauth2_(CommandLine::ForCurrentProcess()->HasSwitch( | |
| 198 ::switches::kForceOAuth2)), | |
| 191 has_web_auth_cookies_(false), | 199 has_web_auth_cookies_(false), |
| 192 delegate_(NULL), | 200 delegate_(NULL), |
| 193 job_restart_request_(NULL), | 201 job_restart_request_(NULL), |
| 194 should_restore_auth_session_(false), | 202 should_restore_auth_session_(false), |
| 195 url_request_context_getter_(NULL) { | 203 url_request_context_getter_(NULL) { |
| 196 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 204 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 197 // During tests, the browser_process may not be initialized yet causing | 205 // During tests, the browser_process may not be initialized yet causing |
| 198 // this to fail. | 206 // this to fail. |
| 199 if (g_browser_process) { | 207 if (g_browser_process) { |
| 200 registrar_.Add( | 208 registrar_.Add( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 220 bool has_cookies, | 228 bool has_cookies, |
| 221 LoginUtils::Delegate* delegate) OVERRIDE; | 229 LoginUtils::Delegate* delegate) OVERRIDE; |
| 222 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; | 230 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; |
| 223 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; | 231 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; |
| 224 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; | 232 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; |
| 225 virtual scoped_refptr<Authenticator> CreateAuthenticator( | 233 virtual scoped_refptr<Authenticator> CreateAuthenticator( |
| 226 LoginStatusConsumer* consumer) OVERRIDE; | 234 LoginStatusConsumer* consumer) OVERRIDE; |
| 227 virtual void PrewarmAuthentication() OVERRIDE; | 235 virtual void PrewarmAuthentication() OVERRIDE; |
| 228 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; | 236 virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE; |
| 229 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 237 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; | 238 virtual void StopBackgroundFetchers() OVERRIDE; |
| 234 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; | 239 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; |
| 235 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; | 240 virtual void CompleteProfileCreate(Profile* user_profile) OVERRIDE; |
| 236 | 241 |
| 237 // OAuth1TokenFetcher::Delegate overrides. | 242 // OAuth1TokenFetcher::Delegate overrides. |
| 238 void OnOAuth1AccessTokenAvailable(const std::string& token, | 243 void OnOAuth1AccessTokenAvailable(const std::string& token, |
| 239 const std::string& secret) OVERRIDE; | 244 const std::string& secret) OVERRIDE; |
| 240 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; | 245 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; |
| 241 | 246 |
| 242 // OAuthLoginVerifier::Delegate overrides. | 247 // OAuth1LoginVerifier::Delegate overrides. |
| 243 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 248 virtual void OnOAuth1VerificationSucceeded(const std::string& user_name, |
| 244 const std::string& sid, | 249 const std::string& sid, |
| 245 const std::string& lsid, | 250 const std::string& lsid, |
| 246 const std::string& auth) OVERRIDE; | 251 const std::string& auth) OVERRIDE; |
| 247 virtual void OnOAuthVerificationFailed(const std::string& user_name) OVERRIDE; | 252 virtual void OnOAuth1VerificationFailed( |
| 253 const std::string& user_name) OVERRIDE; | |
| 254 | |
| 255 // LoginManager::Delegate overrides. | |
| 256 virtual void OnOAuth2RefreshTokenLoaded(Profile* profile, | |
| 257 const std::string& refresh_token) OVERRIDE; | |
| 258 virtual void OnOAuth2RefreshTokenFetchFailed(Profile* profile, | |
| 259 const std::string& service) OVERRIDE; | |
| 260 virtual void OnCookiesRestoreSuccess(Profile* profile) OVERRIDE; | |
| 261 virtual void OnCookiesRestoreFailure(Profile* profile) OVERRIDE; | |
| 262 | |
| 263 // OAuth2TokenFetcher::Delegate overrides. | |
| 264 virtual void OnOAuth2TokenAvailable( | |
| 265 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials, | |
| 266 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE; | |
| 267 virtual void OnOAuth2TokenFetchFailed() OVERRIDE; | |
| 248 | 268 |
| 249 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. | 269 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides. |
| 250 virtual void OnConnectionTypeChanged( | 270 virtual void OnConnectionTypeChanged( |
| 251 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 271 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 252 | 272 |
| 253 // content::NotificationObserver overrides. | 273 // content::NotificationObserver overrides. |
| 254 virtual void Observe(int type, | 274 virtual void Observe(int type, |
| 255 const content::NotificationSource& source, | 275 const content::NotificationSource& source, |
| 256 const content::NotificationDetails& details) OVERRIDE; | 276 const content::NotificationDetails& details) OVERRIDE; |
| 257 | 277 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 280 const std::string& token, | 300 const std::string& token, |
| 281 const std::string& secret); | 301 const std::string& secret); |
| 282 | 302 |
| 283 // Fetch all secondary (OAuth2) tokens given OAuth1 access |token| and | 303 // Fetch all secondary (OAuth2) tokens given OAuth1 access |token| and |
| 284 // |secret|. | 304 // |secret|. |
| 285 void FetchSecondaryTokens(Profile* offrecord_profile, | 305 void FetchSecondaryTokens(Profile* offrecord_profile, |
| 286 const std::string& token, | 306 const std::string& token, |
| 287 const std::string& secret); | 307 const std::string& secret); |
| 288 | 308 |
| 289 // Fetch user credentials (sid/lsid) given OAuth1 access |token| and |secret|. | 309 // Fetch user credentials (sid/lsid) given OAuth1 access |token| and |secret|. |
| 290 void FetchCredentials(Profile* user_profile, | 310 void FetchCredentialsWithOAuth1(Profile* user_profile, |
| 291 const std::string& token, | 311 const std::string& token, |
| 292 const std::string& secret); | 312 const std::string& secret); |
| 293 | 313 |
| 294 // Fetch enterprise policy OAuth2 given OAuth1 access |token| and |secret|. | 314 // Fetch enterprise policy OAuth2 given OAuth1 access |token| and |secret|. |
| 295 void FetchPolicyToken(Profile* offrecord_profile, | 315 void FetchPolicyToken(Profile* offrecord_profile, |
| 296 const std::string& token, | 316 const std::string& token, |
| 297 const std::string& secret); | 317 const std::string& secret); |
| 298 | 318 |
| 299 // Check user's profile for kApplicationLocale setting. | 319 // Check user's profile for kApplicationLocale setting. |
| 300 void RespectLocalePreference(Profile* pref); | 320 void RespectLocalePreference(Profile* pref); |
| 301 | 321 |
| 322 // Returns true if the OAuth2 refresh token and its previously checked value | |
| 323 // (during token-to-cookies exchange) is known to be valid. | |
| 324 bool IsOAuth2RefreshTokenValid(Profile* user_profile, | |
| 325 const std::string& oauth2_refresh_token); | |
| 326 | |
| 302 // Initializes basic preferences for newly created profile. | 327 // Initializes basic preferences for newly created profile. |
| 303 void InitProfilePreferences(Profile* user_profile); | 328 void InitProfilePreferences(Profile* user_profile); |
| 304 | 329 |
| 305 // Callback for asynchronous profile creation. | 330 // Callback for asynchronous profile creation. |
| 306 void OnProfileCreated(Profile* profile, | 331 void OnProfileCreated(Profile* profile, |
| 307 Profile::CreateStatus status); | 332 Profile::CreateStatus status); |
| 308 | 333 |
| 309 // Finalized profile preparation. | 334 // Finalized profile preparation. |
| 310 void FinalizePrepareProfile(Profile* user_profile); | 335 void FinalizePrepareProfile(Profile* user_profile); |
| 311 | 336 |
| 312 // Restores GAIA auth cookies for the created profile. | 337 // Restores GAIA auth cookies for the created user profile from OAuth1 token. |
| 313 void RestoreAuthCookies(Profile* user_profile); | 338 void RestoreCookiesFromOAuth1Token(Profile* user_profile); |
| 339 | |
| 340 // Restores GAIA auth cookies for the created user profile from OAuth2 token. | |
| 341 void RestoreCookiesFromTokenService(Profile* user_profile); | |
| 342 | |
| 343 // Removed deprecated OAuth1 token and secret form preference store. | |
| 344 void RemoveOAuth1Tokens(Profile* user_profile); | |
| 314 | 345 |
| 315 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | 346 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. |
| 316 void InitRlz(Profile* user_profile, bool disabled); | 347 void InitRlz(Profile* user_profile, bool disabled); |
| 317 | 348 |
| 349 // Initializes and starts TokenSerivice credentials with OAuth2 tokens. | |
| 350 void PrepareTokenServiceWithOAuth2( | |
| 351 Profile* profile, | |
| 352 const GaiaAuthConsumer::ClientLoginResult& credentials, | |
| 353 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens); | |
| 354 | |
| 355 // Initializes and starts TokenSerivice credentials with GAIA credentials. | |
| 356 void PrepareTokenService( | |
| 357 Profile* profile, | |
| 358 const GaiaAuthConsumer::ClientLoginResult& credentials); | |
| 359 | |
| 360 // Starts signing related services. Initiates TokenService token retreival. | |
| 361 void StartSignedInServices(Profile* profile); | |
| 362 | |
| 318 std::string password_; | 363 std::string password_; |
| 319 bool pending_requests_; | 364 bool pending_requests_; |
| 320 bool using_oauth_; | 365 bool using_oauth_; |
| 366 bool force_oauth2_; | |
| 321 // True if the authenrication profile's cookie jar should contain | 367 // True if the authenrication profile's cookie jar should contain |
| 322 // authentication cookies from the authentication extension log in flow. | 368 // authentication cookies from the authentication extension log in flow. |
| 323 bool has_web_auth_cookies_; | 369 bool has_web_auth_cookies_; |
| 324 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 370 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 325 scoped_refptr<Authenticator> authenticator_; | 371 scoped_refptr<Authenticator> authenticator_; |
| 326 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 372 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; |
| 327 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; | 373 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; |
| 328 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | 374 scoped_ptr<OAuth1LoginVerifier> oauth1_login_verifier_; |
| 375 | |
| 376 scoped_ptr<LoginManager> login_manager_; | |
| 377 scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_; | |
| 329 | 378 |
| 330 // Delegate to be fired when the profile will be prepared. | 379 // Delegate to be fired when the profile will be prepared. |
| 331 LoginUtils::Delegate* delegate_; | 380 LoginUtils::Delegate* delegate_; |
| 332 | 381 |
| 333 // Used to restart Chrome to switch to the guest mode. | 382 // Used to restart Chrome to switch to the guest mode. |
| 334 JobRestartRequest* job_restart_request_; | 383 JobRestartRequest* job_restart_request_; |
| 335 | 384 |
| 336 // True if should restore authentication session when notified about | 385 // True if should restore authentication session when notified about |
| 337 // online state change. | 386 // online state change. |
| 338 bool should_restore_auth_session_; | 387 bool should_restore_auth_session_; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 new PolicyOAuthFetcher(authenticator_->authentication_profile())); | 534 new PolicyOAuthFetcher(authenticator_->authentication_profile())); |
| 486 policy_oauth_fetcher_->Start(); | 535 policy_oauth_fetcher_->Start(); |
| 487 } | 536 } |
| 488 } | 537 } |
| 489 | 538 |
| 490 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { | 539 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { |
| 491 if (delegate_ == delegate) | 540 if (delegate_ == delegate) |
| 492 delegate_ = NULL; | 541 delegate_ = NULL; |
| 493 } | 542 } |
| 494 | 543 |
| 544 bool LoginUtilsImpl::IsOAuth2RefreshTokenValid( | |
| 545 Profile* user_profile, | |
| 546 const std::string& oauth2_refresh_token) { | |
| 547 // Do we have a token? | |
| 548 if (oauth2_refresh_token.empty()) | |
| 549 return false; | |
| 550 | |
| 551 // Did previous token-to-cookie exchange fail? | |
| 552 if (UserManager::Get()->IsUserLoggedIn() && | |
| 553 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != | |
| 554 User::OAUTH2_TOKEN_STATUS_VALID) { | |
| 555 return false; | |
| 556 } | |
| 557 | |
| 558 return true; | |
| 559 } | |
| 560 | |
| 495 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { | 561 void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile) { |
| 562 if (force_oauth2_) { | |
| 563 } | |
|
xiyuan
2013/01/07 23:07:55
nuke it?
zel
2013/01/08 02:05:41
Done.
| |
| 564 | |
| 496 if (UserManager::Get()->IsCurrentUserNew()) | 565 if (UserManager::Get()->IsCurrentUserNew()) |
| 497 SetFirstLoginPrefs(user_profile->GetPrefs()); | 566 SetFirstLoginPrefs(user_profile->GetPrefs()); |
| 498 // Make sure that the google service username is properly set (we do this | 567 // 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 | 568 // on every sign in, not just the first login, to deal with existing |
| 500 // profiles that might not have it set yet). | 569 // profiles that might not have it set yet). |
| 501 StringPrefMember google_services_username; | 570 StringPrefMember google_services_username; |
| 502 google_services_username.Init(prefs::kGoogleServicesUsername, | 571 google_services_username.Init(prefs::kGoogleServicesUsername, |
| 503 user_profile->GetPrefs()); | 572 user_profile->GetPrefs()); |
| 504 google_services_username.SetValue( | 573 google_services_username.SetValue( |
| 505 UserManager::Get()->GetLoggedInUser()->display_email()); | 574 UserManager::Get()->GetLoggedInUser()->display_email()); |
| 506 // Make sure we flip every profile to not share proxies if the user hasn't | 575 // Make sure we flip every profile to not share proxies if the user hasn't |
| 507 // specified so explicitly. | 576 // specified so explicitly. |
| 508 const PrefService::Preference* use_shared_proxies_pref = | 577 const PrefService::Preference* use_shared_proxies_pref = |
| 509 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies); | 578 user_profile->GetPrefs()->FindPreference(prefs::kUseSharedProxies); |
| 510 if (use_shared_proxies_pref->IsDefaultValue()) | 579 if (use_shared_proxies_pref->IsDefaultValue()) |
| 511 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); | 580 user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); |
| 512 policy::NetworkConfigurationUpdater* network_configuration_updater = | 581 policy::NetworkConfigurationUpdater* network_configuration_updater = |
| 513 g_browser_process->browser_policy_connector()-> | 582 g_browser_process->browser_policy_connector()-> |
| 514 GetNetworkConfigurationUpdater(); | 583 GetNetworkConfigurationUpdater(); |
| 515 if (network_configuration_updater) | 584 if (network_configuration_updater) |
| 516 network_configuration_updater->OnUserPolicyInitialized(); | 585 network_configuration_updater->OnUserPolicyInitialized(); |
| 517 RespectLocalePreference(user_profile); | 586 RespectLocalePreference(user_profile); |
| 518 } | 587 } |
| 519 | 588 |
| 520 void LoginUtilsImpl::OnProfileCreated( | 589 void LoginUtilsImpl::OnProfileCreated( |
| 521 Profile* user_profile, | 590 Profile* user_profile, |
| 522 Profile::CreateStatus status) { | 591 Profile::CreateStatus status) { |
| 523 CHECK(user_profile); | 592 CHECK(user_profile); |
| 524 | |
| 525 if (delegate_) | 593 if (delegate_) |
| 526 delegate_->OnProfileCreated(user_profile); | 594 delegate_->OnProfileCreated(user_profile); |
| 527 | 595 |
| 528 switch (status) { | 596 switch (status) { |
| 529 case Profile::CREATE_STATUS_INITIALIZED: | 597 case Profile::CREATE_STATUS_INITIALIZED: |
| 530 break; | 598 break; |
| 531 case Profile::CREATE_STATUS_CREATED: { | 599 case Profile::CREATE_STATUS_CREATED: { |
| 532 InitProfilePreferences(user_profile); | 600 InitProfilePreferences(user_profile); |
| 533 return; | 601 return; |
| 534 } | 602 } |
| 535 case Profile::CREATE_STATUS_FAIL: | 603 case Profile::CREATE_STATUS_FAIL: |
| 536 default: | 604 default: |
| 537 NOTREACHED(); | 605 NOTREACHED(); |
| 538 return; | 606 return; |
| 539 } | 607 } |
| 540 | 608 |
| 541 BootTimesLoader* btl = BootTimesLoader::Get(); | 609 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 542 btl->AddLoginTimeMarker("UserProfileGotten", false); | 610 btl->AddLoginTimeMarker("UserProfileGotten", false); |
| 543 | 611 |
| 544 if (using_oauth_) { | 612 if (using_oauth_) { |
| 545 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was | 613 if (!force_oauth2_) { |
| 546 // used to fetch policies before Profile creation. | 614 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was |
| 547 if (policy_oauth_fetcher_.get() && | 615 // used to fetch policies before Profile creation. |
| 548 !policy_oauth_fetcher_->oauth1_token().empty()) { | 616 if (policy_oauth_fetcher_.get() && |
| 549 VLOG(1) << "Resuming profile creation after fetching policy token"; | 617 !policy_oauth_fetcher_->oauth1_token().empty()) { |
| 550 StoreOAuth1AccessToken(user_profile, | 618 VLOG(1) << "Resuming profile creation after fetching policy token"; |
| 551 policy_oauth_fetcher_->oauth1_token(), | 619 StoreOAuth1AccessToken(user_profile, |
| 552 policy_oauth_fetcher_->oauth1_secret()); | 620 policy_oauth_fetcher_->oauth1_token(), |
| 621 policy_oauth_fetcher_->oauth1_secret()); | |
| 622 } | |
| 623 } else { | |
| 624 // TODO(mnissler): Figure out what to do here in OAuth2 case. | |
| 553 } | 625 } |
| 554 | 626 |
| 555 // Transfer proxy authentication cache, cookies (optionally) and server | 627 // Transfer proxy authentication cache, cookies (optionally) and server |
| 556 // bound certs from the profile that was used for authentication. This | 628 // bound certs from the profile that was used for authentication. This |
| 557 // profile contains cookies that auth extension should have already put in | 629 // profile contains cookies that auth extension should have already put in |
| 558 // place that will ensure that the newly created session is authenticated | 630 // place that will ensure that the newly created session is authenticated |
| 559 // for the websites that work with the used authentication schema. | 631 // for the websites that work with the used authentication schema. |
| 560 ProfileAuthData::Transfer(authenticator_->authentication_profile(), | 632 ProfileAuthData::Transfer(authenticator_->authentication_profile(), |
| 561 user_profile, | 633 user_profile, |
| 562 has_web_auth_cookies_, // transfer_cookies | 634 has_web_auth_cookies_, // transfer_cookies |
| 563 base::Bind( | 635 base::Bind( |
| 564 &LoginUtilsImpl::CompleteProfileCreate, | 636 &LoginUtilsImpl::CompleteProfileCreate, |
| 565 AsWeakPtr(), | 637 AsWeakPtr(), |
| 566 user_profile)); | 638 user_profile)); |
| 567 return; | 639 return; |
| 568 } | 640 } |
| 569 | 641 |
| 570 FinalizePrepareProfile(user_profile); | 642 FinalizePrepareProfile(user_profile); |
| 571 } | 643 } |
| 572 | 644 |
| 573 void LoginUtilsImpl::RestoreAuthCookies(Profile* user_profile) { | 645 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { |
| 646 if (force_oauth2_) | |
| 647 RestoreCookiesFromTokenService(user_profile); | |
| 648 else | |
| 649 RestoreCookiesFromOAuth1Token(user_profile); | |
| 650 | |
| 651 FinalizePrepareProfile(user_profile); | |
| 652 } | |
| 653 | |
| 654 void LoginUtilsImpl::RestoreCookiesFromOAuth1Token(Profile* user_profile) { | |
| 574 std::string oauth1_token; | 655 std::string oauth1_token; |
| 575 std::string oauth1_secret; | 656 std::string oauth1_secret; |
| 576 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || | 657 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || |
| 577 !has_web_auth_cookies_) { | 658 !has_web_auth_cookies_) { |
| 578 // Verify OAuth access token when we find it in the profile and always if | 659 // Verify OAuth access token when we find it in the profile and always if |
| 579 // if we don't have cookies. | 660 // if we don't have cookies. |
| 580 // TODO(xiyuan): Change back to use authenticator to verify token when | 661 // TODO(xiyuan): Change back to use authenticator to verify token when |
| 581 // we support Gaia in lock screen. | 662 // we support Gaia in lock screen. |
| 582 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 663 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
| 583 } else { | 664 } else { |
| 584 // If we don't have it, fetch OAuth1 access token. | 665 // If we don't have it, fetch OAuth1 access token. |
| 585 // Once we get that, we will kick off individual requests for OAuth2 | 666 // Once we get that, we will kick off individual requests for OAuth2 |
| 586 // tokens for all our services. | 667 // tokens for all our services. |
| 587 // Use off-the-record profile that was used for this step. It should | 668 // 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 | 669 // already contain all needed cookies that will let us skip GAIA's user |
| 589 // authentication UI. | 670 // authentication UI. |
| 590 // | 671 // |
| 591 // TODO(rickcam) We should use an isolated App here. | 672 // TODO(rickcam) We should use an isolated App here. |
| 592 oauth1_token_fetcher_.reset( | 673 oauth1_token_fetcher_.reset( |
| 593 new OAuth1TokenFetcher(this, | 674 new OAuth1TokenFetcher(this, |
| 594 authenticator_->authentication_profile())); | 675 authenticator_->authentication_profile())); |
| 595 oauth1_token_fetcher_->Start(); | 676 oauth1_token_fetcher_->Start(); |
| 596 } | 677 } |
| 597 } | 678 } |
| 598 | 679 |
| 599 void LoginUtilsImpl::CompleteProfileCreate(Profile* user_profile) { | 680 void LoginUtilsImpl::RemoveOAuth1Tokens(Profile* user_profile) { |
| 600 RestoreAuthCookies(user_profile); | 681 PrefServiceSyncable* prefs = user_profile->GetPrefs(); |
| 601 FinalizePrepareProfile(user_profile); | 682 prefs->RegisterStringPref(prefs::kOAuth1Token, |
| 683 "", | |
| 684 PrefServiceSyncable::UNSYNCABLE_PREF); | |
| 685 prefs->RegisterStringPref(prefs::kOAuth1Secret, | |
| 686 "", | |
| 687 PrefServiceSyncable::UNSYNCABLE_PREF); | |
| 688 prefs->ClearPref(prefs::kOAuth1Token); | |
| 689 prefs->ClearPref(prefs::kOAuth1Secret); | |
| 690 prefs->UnregisterPreference(prefs::kOAuth1Token); | |
| 691 prefs->UnregisterPreference(prefs::kOAuth1Secret); | |
| 692 } | |
| 693 | |
| 694 void LoginUtilsImpl::RestoreCookiesFromTokenService(Profile* user_profile) { | |
| 695 // Remove legacy OAuth1 token if we have one. If it's valid, we should already | |
| 696 // have OAuth2 refresh token in TokenService that could be used to retreive | |
| 697 // all other tokens and credentials. | |
| 698 RemoveOAuth1Tokens(user_profile); | |
| 699 | |
| 700 if (has_web_auth_cookies_) { | |
| 701 // If we have authenticated cookie jar, get OAuth1 token first, then fetch | |
| 702 // SID/LSID cookies through OAuthLogin call. | |
| 703 oauth2_token_fetcher_.reset( | |
| 704 new OAuth2TokenFetcher(this, | |
| 705 authenticator_->authentication_profile())); | |
| 706 oauth2_token_fetcher_->Start(); | |
| 707 return; | |
| 708 } | |
| 709 | |
| 710 // If we have no cookies, try to load saved OAuth2 token from TokenService. | |
| 711 TokenService* token_service = | |
| 712 TokenServiceFactory::GetForProfile(user_profile); | |
| 713 token_service->Initialize(GaiaConstants::kChromeSource, user_profile); | |
| 714 | |
| 715 login_manager_.reset(new LoginManager(this, user_profile)); | |
| 716 token_service->LoadTokensFromDB(); | |
| 602 } | 717 } |
| 603 | 718 |
| 604 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { | 719 void LoginUtilsImpl::FinalizePrepareProfile(Profile* user_profile) { |
| 605 BootTimesLoader* btl = BootTimesLoader::Get(); | 720 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 606 // Own TPM device if, for any reason, it has not been done in EULA | 721 // Own TPM device if, for any reason, it has not been done in EULA |
| 607 // wizard screen. | 722 // wizard screen. |
| 608 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); | 723 CryptohomeLibrary* cryptohome = CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 609 btl->AddLoginTimeMarker("TPMOwn-Start", false); | 724 btl->AddLoginTimeMarker("TPMOwn-Start", false); |
| 610 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { | 725 if (cryptohome->TpmIsEnabled() && !cryptohome->TpmIsBeingOwned()) { |
| 611 if (cryptohome->TpmIsOwned()) { | 726 if (cryptohome->TpmIsOwned()) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 796 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
| 682 std::string oauth1_token; | 797 std::string oauth1_token; |
| 683 std::string oauth1_secret; | 798 std::string oauth1_secret; |
| 684 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 799 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 685 return; | 800 return; |
| 686 | 801 |
| 687 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), | 802 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), |
| 688 oauth1_token, oauth1_secret); | 803 oauth1_token, oauth1_secret); |
| 689 } | 804 } |
| 690 | 805 |
| 691 void LoginUtilsImpl::StartSignedInServices( | 806 void LoginUtilsImpl::PrepareTokenService( |
| 692 Profile* user_profile, | 807 Profile* user_profile, |
| 693 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 808 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 809 TokenService* token_service = | |
| 810 TokenServiceFactory::GetForProfile(user_profile); | |
| 811 token_service->UpdateCredentials(credentials); | |
| 812 StartSignedInServices(user_profile); | |
| 813 } | |
| 814 | |
| 815 void LoginUtilsImpl::PrepareTokenServiceWithOAuth2( | |
| 816 Profile* user_profile, | |
| 817 const GaiaAuthConsumer::ClientLoginResult& credentials, | |
| 818 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { | |
| 819 login_manager_.reset(new LoginManager(this, user_profile)); | |
| 820 TokenService* token_service = | |
| 821 TokenServiceFactory::GetForProfile(user_profile); | |
| 822 token_service->UpdateCredentialsWithOAuth2(oauth2_tokens); | |
| 823 token_service->UpdateCredentials(credentials); | |
| 824 StartSignedInServices(user_profile); | |
| 825 } | |
| 826 | |
| 827 void LoginUtilsImpl::StartSignedInServices(Profile* user_profile) { | |
| 694 // Fetch/Create the SigninManager - this will cause the TokenService to load | 828 // 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 | 829 // tokens for the currently signed-in user if the SigninManager hasn't already |
| 696 // been initialized. | 830 // been initialized. |
| 697 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); | 831 SigninManager* signin = SigninManagerFactory::GetForProfile(user_profile); |
| 698 DCHECK(signin); | 832 DCHECK(signin); |
| 699 // Make sure SigninManager is connected to our current user (this should | 833 // Make sure SigninManager is connected to our current user (this should |
| 700 // happen automatically because we set kGoogleServicesUsername in | 834 // happen automatically because we set kGoogleServicesUsername in |
| 701 // OnProfileCreated()). | 835 // OnProfileCreated()). |
| 702 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), | 836 DCHECK_EQ(UserManager::Get()->GetLoggedInUser()->display_email(), |
| 703 signin->GetAuthenticatedUsername()); | 837 signin->GetAuthenticatedUsername()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 717 password_); | 851 password_); |
| 718 content::NotificationService::current()->Notify( | 852 content::NotificationService::current()->Notify( |
| 719 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 853 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
| 720 content::Source<Profile>(user_profile), | 854 content::Source<Profile>(user_profile), |
| 721 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 855 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
| 722 } | 856 } |
| 723 } | 857 } |
| 724 password_.clear(); | 858 password_.clear(); |
| 725 TokenService* token_service = | 859 TokenService* token_service = |
| 726 TokenServiceFactory::GetForProfile(user_profile); | 860 TokenServiceFactory::GetForProfile(user_profile); |
| 727 token_service->UpdateCredentials(credentials); | |
| 728 if (token_service->AreCredentialsValid()) | 861 if (token_service->AreCredentialsValid()) |
| 729 token_service->StartFetchingTokens(); | 862 token_service->StartFetchingTokens(); |
| 730 } | 863 } |
| 731 | 864 |
| 732 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { | 865 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { |
| 733 DCHECK(profile != NULL); | 866 DCHECK(profile != NULL); |
| 734 PrefService* prefs = profile->GetPrefs(); | 867 PrefService* prefs = profile->GetPrefs(); |
| 735 DCHECK(prefs != NULL); | 868 DCHECK(prefs != NULL); |
| 736 if (g_browser_process == NULL) | 869 if (g_browser_process == NULL) |
| 737 return; | 870 return; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { | 1173 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) { |
| 1041 std::string oauth1_token; | 1174 std::string oauth1_token; |
| 1042 std::string oauth1_secret; | 1175 std::string oauth1_secret; |
| 1043 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 1176 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 1044 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); | 1177 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret); |
| 1045 } | 1178 } |
| 1046 | 1179 |
| 1047 void LoginUtilsImpl::StopBackgroundFetchers() { | 1180 void LoginUtilsImpl::StopBackgroundFetchers() { |
| 1048 policy_oauth_fetcher_.reset(); | 1181 policy_oauth_fetcher_.reset(); |
| 1049 oauth1_token_fetcher_.reset(); | 1182 oauth1_token_fetcher_.reset(); |
| 1050 oauth_login_verifier_.reset(); | 1183 oauth1_login_verifier_.reset(); |
| 1051 } | 1184 } |
| 1052 | 1185 |
| 1053 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, | 1186 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, |
| 1054 const std::string& token, | 1187 const std::string& token, |
| 1055 const std::string& secret) { | 1188 const std::string& secret) { |
| 1056 FetchPolicyToken(offrecord_profile, token, secret); | 1189 FetchPolicyToken(offrecord_profile, token, secret); |
| 1057 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 1190 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
| 1058 // capable of handling OAuth1 tokens directly. | 1191 // capable of handling OAuth1 tokens directly. |
| 1059 } | 1192 } |
| 1060 | 1193 |
| 1061 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 1194 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
| 1062 std::string* token, | 1195 std::string* token, |
| 1063 std::string* secret) { | 1196 std::string* secret) { |
| 1064 // Skip reading oauth token if user does not have a valid status. | 1197 // Skip reading oauth token if user does not have a valid status. |
| 1065 if (UserManager::Get()->IsUserLoggedIn() && | 1198 if (UserManager::Get()->IsUserLoggedIn() && |
| 1066 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != | 1199 UserManager::Get()->GetLoggedInUser()->oauth_token_status() != |
| 1067 User::OAUTH_TOKEN_STATUS_VALID) { | 1200 User::OAUTH1_TOKEN_STATUS_VALID) { |
| 1068 return false; | 1201 return false; |
| 1069 } | 1202 } |
| 1070 | 1203 |
| 1071 PrefService* pref_service = user_profile->GetPrefs(); | 1204 PrefService* pref_service = user_profile->GetPrefs(); |
| 1072 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); | 1205 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); |
| 1073 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); | 1206 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); |
| 1074 if (!encoded_token.length() || !encoded_secret.length()) | 1207 if (!encoded_token.length() || !encoded_secret.length()) |
| 1075 return false; | 1208 return false; |
| 1076 | 1209 |
| 1210 #ifdef NDEBUG | |
| 1077 std::string decoded_token = | 1211 std::string decoded_token = |
| 1078 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); | 1212 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_token); |
| 1079 std::string decoded_secret = | 1213 std::string decoded_secret = |
| 1080 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); | 1214 CrosLibrary::Get()->GetCertLibrary()->DecryptToken(encoded_secret); |
| 1215 #else | |
| 1216 std::string decoded_token = encoded_token; | |
| 1217 std::string decoded_secret = encoded_secret; | |
|
xiyuan
2013/01/07 23:07:55
We probably should do this in CertLibrary::Decrypt
zel
2013/01/08 02:05:41
Done.
| |
| 1218 #endif | |
| 1219 | |
| 1081 if (!decoded_token.length() || !decoded_secret.length()) | 1220 if (!decoded_token.length() || !decoded_secret.length()) |
| 1082 return false; | 1221 return false; |
| 1083 | 1222 |
| 1084 *token = decoded_token; | 1223 *token = decoded_token; |
| 1085 *secret = decoded_secret; | 1224 *secret = decoded_secret; |
| 1086 return true; | 1225 return true; |
| 1087 } | 1226 } |
| 1088 | 1227 |
| 1089 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, | 1228 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, |
| 1090 const std::string& token, | 1229 const std::string& token, |
| 1091 const std::string& secret) { | 1230 const std::string& secret) { |
| 1092 // First store OAuth1 token + service for the current user profile... | 1231 // First store OAuth1 token + service for the current user profile... |
| 1232 #ifdef NDEBUG | |
| 1093 std::string encrypted_token = | 1233 std::string encrypted_token = |
| 1094 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token); | 1234 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(token); |
| 1095 std::string encrypted_secret = | 1235 std::string encrypted_secret = |
| 1096 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret); | 1236 CrosLibrary::Get()->GetCertLibrary()->EncryptToken(secret); |
| 1237 #else | |
| 1238 std::string encrypted_token = token; | |
| 1239 std::string encrypted_secret = secret; | |
| 1240 #endif | |
| 1241 | |
| 1097 PrefService* pref_service = user_profile->GetPrefs(); | 1242 PrefService* pref_service = user_profile->GetPrefs(); |
| 1098 User* user = UserManager::Get()->GetLoggedInUser(); | 1243 User* user = UserManager::Get()->GetLoggedInUser(); |
| 1099 if (!encrypted_token.empty() && !encrypted_secret.empty()) { | 1244 if (!encrypted_token.empty() && !encrypted_secret.empty()) { |
| 1100 pref_service->SetString(prefs::kOAuth1Token, encrypted_token); | 1245 pref_service->SetString(prefs::kOAuth1Token, encrypted_token); |
| 1101 pref_service->SetString(prefs::kOAuth1Secret, encrypted_secret); | 1246 pref_service->SetString(prefs::kOAuth1Secret, encrypted_secret); |
| 1102 | 1247 |
| 1103 // ...then record the presence of valid OAuth token for this account in | 1248 // ...then record the presence of valid OAuth token for this account in |
| 1104 // local state as well. | 1249 // local state as well. |
| 1105 UserManager::Get()->SaveUserOAuthStatus( | 1250 UserManager::Get()->SaveUserOAuthStatus( |
| 1106 user->email(), User::OAUTH_TOKEN_STATUS_VALID); | 1251 user->email(), User::OAUTH1_TOKEN_STATUS_VALID); |
| 1107 } else { | 1252 } else { |
| 1108 LOG(WARNING) << "Failed to get OAuth1 token/secret encrypted."; | 1253 LOG(WARNING) << "Failed to get OAuth1 token/secret encrypted."; |
| 1109 // Set the OAuth status invalid so that the user will go through full | 1254 // Set the OAuth status invalid so that the user will go through full |
| 1110 // GAIA login next time. | 1255 // GAIA login next time. |
| 1111 UserManager::Get()->SaveUserOAuthStatus( | 1256 UserManager::Get()->SaveUserOAuthStatus( |
| 1112 user->email(), User::OAUTH_TOKEN_STATUS_INVALID); | 1257 user->email(), User::OAUTH1_TOKEN_STATUS_INVALID); |
| 1113 } | 1258 } |
| 1114 } | 1259 } |
| 1115 | 1260 |
| 1116 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, | 1261 void LoginUtilsImpl::VerifyOAuth1AccessToken(Profile* user_profile, |
| 1117 const std::string& token, | 1262 const std::string& token, |
| 1118 const std::string& secret) { | 1263 const std::string& secret) { |
| 1119 // Kick off verification of OAuth1 access token (via OAuthLogin), this should | 1264 // Kick off verification of OAuth1 access token (via OAuthLogin), this should |
| 1120 // let us fetch credentials that will be used to initialize sync engine. | 1265 // let us fetch credentials that will be used to initialize sync engine. |
| 1121 FetchCredentials(user_profile, token, secret); | 1266 FetchCredentialsWithOAuth1(user_profile, token, secret); |
| 1122 | 1267 |
| 1123 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); | 1268 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), token, secret); |
| 1124 } | 1269 } |
| 1125 | 1270 |
| 1126 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | 1271 void LoginUtilsImpl::FetchCredentialsWithOAuth1(Profile* user_profile, |
| 1127 const std::string& token, | 1272 const std::string& token, |
| 1128 const std::string& secret) { | 1273 const std::string& secret) { |
| 1129 oauth_login_verifier_.reset(new OAuthLoginVerifier( | 1274 oauth1_login_verifier_.reset(new OAuth1LoginVerifier( |
| 1130 this, user_profile, token, secret, | 1275 this, user_profile, token, secret, |
| 1131 UserManager::Get()->GetLoggedInUser()->email())); | 1276 UserManager::Get()->GetLoggedInUser()->email())); |
| 1132 oauth_login_verifier_->StartOAuthVerification(); | 1277 oauth1_login_verifier_->StartOAuthVerification(); |
| 1133 } | 1278 } |
| 1134 | 1279 |
| 1135 | 1280 |
| 1136 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | 1281 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, |
| 1137 const std::string& token, | 1282 const std::string& token, |
| 1138 const std::string& secret) { | 1283 const std::string& secret) { |
| 1139 // Fetch dm service token now, if it hasn't been fetched yet. | 1284 // Fetch dm service token now, if it hasn't been fetched yet. |
| 1140 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { | 1285 if (!policy_oauth_fetcher_.get() || policy_oauth_fetcher_->failed()) { |
| 1141 // Get the default system profile to use with the policy fetching. If there | 1286 // Get the default system profile to use with the policy fetching. If there |
| 1142 // is no |authenticator_| profile, manually load default system profile. | 1287 // 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 | 1309 // here as well. This could be handled with TokenService class once it is |
| 1165 // ready to handle OAuth tokens. | 1310 // ready to handle OAuth tokens. |
| 1166 | 1311 |
| 1167 // We don't need authenticator instance any more, reset it so that | 1312 // We don't need authenticator instance any more, reset it so that |
| 1168 // ScreenLocker would create a separate instance. | 1313 // ScreenLocker would create a separate instance. |
| 1169 // TODO(nkostylev): There's a potential race if SL would be created before | 1314 // TODO(nkostylev): There's a potential race if SL would be created before |
| 1170 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | 1315 // OAuth tokens are fetched. It would use incorrect Authenticator instance. |
| 1171 authenticator_ = NULL; | 1316 authenticator_ = NULL; |
| 1172 } | 1317 } |
| 1173 | 1318 |
| 1174 void LoginUtilsImpl::OnOAuthVerificationFailed(const std::string& user_name) { | 1319 void LoginUtilsImpl::OnOAuth1VerificationFailed(const std::string& user_name) { |
| 1175 UserManager::Get()->SaveUserOAuthStatus(user_name, | 1320 UserManager::Get()->SaveUserOAuthStatus(user_name, |
| 1176 User::OAUTH_TOKEN_STATUS_INVALID); | 1321 User::OAUTH1_TOKEN_STATUS_INVALID); |
| 1177 } | 1322 } |
| 1178 | 1323 |
| 1179 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, | 1324 void LoginUtilsImpl::OnOAuth1AccessTokenAvailable(const std::string& token, |
| 1180 const std::string& secret) { | 1325 const std::string& secret) { |
| 1181 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1326 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1182 StoreOAuth1AccessToken(user_profile, token, secret); | 1327 StoreOAuth1AccessToken(user_profile, token, secret); |
| 1183 | 1328 |
| 1184 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. If we | 1329 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. If we |
| 1185 // have just transfered auth cookies out of authenticated cookie jar, there | 1330 // have just transfered auth cookies out of authenticated cookie jar, there |
| 1186 // is no need to try to mint them from OAuth token again. | 1331 // is no need to try to mint them from OAuth token again. |
| 1187 VerifyOAuth1AccessToken(user_profile, token, secret); | 1332 VerifyOAuth1AccessToken(user_profile, token, secret); |
| 1188 } | 1333 } |
| 1189 | 1334 |
| 1190 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { | 1335 void LoginUtilsImpl::OnOAuth1AccessTokenFetchFailed() { |
| 1191 // TODO(kochi): Show failure notification UI here? | 1336 // TODO(kochi): Show failure notification UI here? |
| 1192 LOG(ERROR) << "Failed to fetch OAuth1 access token."; | 1337 LOG(ERROR) << "Failed to fetch OAuth1 access token."; |
| 1193 g_browser_process->browser_policy_connector()->RegisterForUserPolicy( | 1338 g_browser_process->browser_policy_connector()->RegisterForUserPolicy( |
| 1194 EmptyString()); | 1339 EmptyString()); |
| 1195 } | 1340 } |
| 1196 | 1341 |
| 1197 void LoginUtilsImpl::OnOAuthVerificationSucceeded( | 1342 void LoginUtilsImpl::OnOAuth1VerificationSucceeded( |
| 1198 const std::string& user_name, const std::string& sid, | 1343 const std::string& user_name, const std::string& sid, |
| 1199 const std::string& lsid, const std::string& auth) { | 1344 const std::string& lsid, const std::string& auth) { |
| 1200 // Kick off sync engine. | 1345 // Kick off sync engine. |
| 1201 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, | 1346 GaiaAuthConsumer::ClientLoginResult credentials(sid, lsid, auth, |
| 1202 std::string()); | 1347 std::string()); |
| 1203 StartSignedInServices(ProfileManager::GetDefaultProfile(), credentials); | 1348 PrepareTokenService(ProfileManager::GetDefaultProfile(), credentials); |
| 1204 } | 1349 } |
| 1205 | 1350 |
| 1351 void LoginUtilsImpl::OnOAuth2TokenAvailable( | |
| 1352 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials, | |
| 1353 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { | |
| 1354 PrepareTokenServiceWithOAuth2(ProfileManager::GetDefaultProfile(), | |
| 1355 gaia_credentials, oauth2_tokens); | |
| 1356 } | |
| 1357 | |
| 1358 void LoginUtilsImpl::OnOAuth2TokenFetchFailed() { | |
| 1359 UserManager::Get()->SaveUserOAuthStatus( | |
| 1360 UserManager::Get()->GetLoggedInUser()->email(), | |
| 1361 User::OAUTH2_TOKEN_STATUS_INVALID); | |
| 1362 } | |
| 1363 | |
| 1364 void LoginUtilsImpl::OnOAuth2RefreshTokenLoaded( | |
| 1365 Profile* profile, const std::string& oauth2_refresh_token) { | |
| 1366 // Loaded all tokens but no OAuth2 refresh token found? | |
| 1367 if (oauth2_refresh_token.empty()) { | |
| 1368 UserManager::Get()->SaveUserOAuthStatus( | |
| 1369 UserManager::Get()->GetLoggedInUser()->email(), | |
| 1370 User::OAUTH2_TOKEN_STATUS_INVALID); | |
| 1371 } | |
| 1372 } | |
| 1373 | |
| 1374 void LoginUtilsImpl::OnOAuth2RefreshTokenFetchFailed( | |
| 1375 Profile* profile, const std::string& service) { | |
| 1376 // Failed to fetch new refresh token through TokenService. | |
| 1377 UserManager::Get()->SaveUserOAuthStatus( | |
| 1378 UserManager::Get()->GetLoggedInUser()->email(), | |
| 1379 User::OAUTH2_TOKEN_STATUS_INVALID); | |
| 1380 } | |
| 1381 | |
| 1382 void LoginUtilsImpl::OnCookiesRestoreSuccess(Profile* profile) { | |
| 1383 // GAIA auth cookies successfully restored for the current session. | |
| 1384 UserManager::Get()->SaveUserOAuthStatus( | |
| 1385 UserManager::Get()->GetLoggedInUser()->email(), | |
| 1386 User::OAUTH2_TOKEN_STATUS_VALID); | |
| 1387 } | |
| 1388 | |
| 1389 void LoginUtilsImpl::OnCookiesRestoreFailure(Profile* profile) { | |
| 1390 UserManager::Get()->SaveUserOAuthStatus( | |
| 1391 UserManager::Get()->GetLoggedInUser()->email(), | |
| 1392 User::OAUTH2_TOKEN_STATUS_INVALID); | |
| 1393 } | |
| 1206 | 1394 |
| 1207 void LoginUtilsImpl::OnConnectionTypeChanged( | 1395 void LoginUtilsImpl::OnConnectionTypeChanged( |
| 1208 net::NetworkChangeNotifier::ConnectionType type) { | 1396 net::NetworkChangeNotifier::ConnectionType type) { |
| 1209 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && | 1397 if (type != net::NetworkChangeNotifier::CONNECTION_NONE && |
| 1210 UserManager::Get()->IsUserLoggedIn()) { | 1398 UserManager::Get()->IsUserLoggedIn()) { |
| 1211 if (oauth_login_verifier_.get() && | 1399 if (oauth1_login_verifier_.get() && |
| 1212 !oauth_login_verifier_->is_done()) { | 1400 !oauth1_login_verifier_->is_done()) { |
| 1213 // If we come online for the first time after successful offline login, | 1401 // If we come online for the first time after successful offline login, |
| 1214 // we need to kick off OAuth token verification process again. | 1402 // we need to kick off OAuth token verification process again. |
| 1215 oauth_login_verifier_->ContinueVerification(); | 1403 oauth1_login_verifier_->ContinueVerification(); |
| 1216 } else if (should_restore_auth_session_) { | 1404 } else if (should_restore_auth_session_) { |
| 1217 should_restore_auth_session_ = false; | 1405 should_restore_auth_session_ = false; |
| 1218 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1406 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1219 KickStartAuthentication(user_profile); | 1407 KickStartAuthentication(user_profile); |
| 1220 } | 1408 } |
| 1221 } | 1409 } |
| 1222 } | 1410 } |
| 1223 | 1411 |
| 1224 void LoginUtilsImpl::Observe(int type, | 1412 void LoginUtilsImpl::Observe(int type, |
| 1225 const content::NotificationSource& source, | 1413 const content::NotificationSource& source, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1253 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1441 bool LoginUtils::IsWhitelisted(const std::string& username) { |
| 1254 CrosSettings* cros_settings = CrosSettings::Get(); | 1442 CrosSettings* cros_settings = CrosSettings::Get(); |
| 1255 bool allow_new_user = false; | 1443 bool allow_new_user = false; |
| 1256 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1444 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 1257 if (allow_new_user) | 1445 if (allow_new_user) |
| 1258 return true; | 1446 return true; |
| 1259 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1447 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
| 1260 } | 1448 } |
| 1261 | 1449 |
| 1262 } // namespace chromeos | 1450 } // namespace chromeos |
| OLD | NEW |