Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 const char kServiceScopeChromeOS[] = | 96 const char kServiceScopeChromeOS[] = |
| 97 "https://www.googleapis.com/auth/chromesync"; | 97 "https://www.googleapis.com/auth/chromesync"; |
| 98 | 98 |
| 99 const char kServiceScopeChromeOSDeviceManagement[] = | 99 const char kServiceScopeChromeOSDeviceManagement[] = |
| 100 "https://www.googleapis.com/auth/chromeosdevicemanagement"; | 100 "https://www.googleapis.com/auth/chromeosdevicemanagement"; |
| 101 } // namespace | 101 } // namespace |
| 102 | 102 |
| 103 // Task for fetching tokens from UI thread. | 103 // Task for fetching tokens from UI thread. |
| 104 class StartSyncOnUIThreadTask : public Task { | 104 class StartSyncOnUIThreadTask : public Task { |
| 105 public: | 105 public: |
| 106 StartSyncOnUIThreadTask( | 106 explicit StartSyncOnUIThreadTask( |
| 107 const GaiaAuthConsumer::ClientLoginResult& credentials) | 107 const GaiaAuthConsumer::ClientLoginResult& credentials) |
| 108 : credentials_(credentials) {} | 108 : credentials_(credentials) {} |
| 109 virtual ~StartSyncOnUIThreadTask() {} | 109 virtual ~StartSyncOnUIThreadTask() {} |
| 110 | 110 |
| 111 // Task override. | 111 // Task override. |
| 112 virtual void Run() { | 112 virtual void Run() OVERRIDE { |
| 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 114 LoginUtils::Get()->FetchCookies(ProfileManager::GetDefaultProfile(), | 114 LoginUtils::Get()->FetchCookies(ProfileManager::GetDefaultProfile(), |
| 115 credentials_); | 115 credentials_); |
| 116 LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(), | 116 LoginUtils::Get()->StartSync(ProfileManager::GetDefaultProfile(), |
| 117 credentials_); | 117 credentials_); |
| 118 } | 118 } |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 GaiaAuthConsumer::ClientLoginResult credentials_; | 121 GaiaAuthConsumer::ClientLoginResult credentials_; |
| 122 | |
| 123 DISALLOW_COPY_AND_ASSIGN(StartSyncOnUIThreadTask); | |
| 122 }; | 124 }; |
| 123 | 125 |
| 124 // Transfers initial set of Profile cookies from the default profile. | 126 // Transfers initial set of Profile cookies from the default profile. |
| 125 class TransferDefaultCookiesOnIOThreadTask : public Task { | 127 class TransferDefaultCookiesOnIOThreadTask : public Task { |
| 126 public: | 128 public: |
| 127 TransferDefaultCookiesOnIOThreadTask( | 129 TransferDefaultCookiesOnIOThreadTask( |
| 128 net::URLRequestContextGetter* auth_context, | 130 net::URLRequestContextGetter* auth_context, |
| 129 net::URLRequestContextGetter* new_context) | 131 net::URLRequestContextGetter* new_context) |
| 130 : auth_context_(auth_context), | 132 : auth_context_(auth_context), |
| 131 new_context_(new_context) {} | 133 new_context_(new_context) {} |
| 132 virtual ~TransferDefaultCookiesOnIOThreadTask() {} | 134 virtual ~TransferDefaultCookiesOnIOThreadTask() {} |
| 133 | 135 |
| 134 // Task override. | 136 // Task override. |
| 135 virtual void Run() { | 137 virtual void Run() OVERRIDE { |
| 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 137 net::CookieStore* default_store = | 139 net::CookieStore* default_store = |
| 138 auth_context_->GetURLRequestContext()->cookie_store(); | 140 auth_context_->GetURLRequestContext()->cookie_store(); |
| 139 net::CookieMonster* default_monster = default_store->GetCookieMonster(); | 141 net::CookieMonster* default_monster = default_store->GetCookieMonster(); |
| 140 default_monster->SetKeepExpiredCookies(); | 142 default_monster->SetKeepExpiredCookies(); |
| 141 default_monster->GetAllCookiesAsync( | 143 default_monster->GetAllCookiesAsync( |
| 142 base::Bind( | 144 base::Bind( |
| 143 &TransferDefaultCookiesOnIOThreadTask::InitializeCookieMonster, | 145 &TransferDefaultCookiesOnIOThreadTask::InitializeCookieMonster, |
| 144 base::Unretained(this))); | 146 base::Unretained(this))); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void InitializeCookieMonster(const net::CookieList& cookies) { | 149 void InitializeCookieMonster(const net::CookieList& cookies) { |
| 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 149 net::CookieStore* new_store = | 151 net::CookieStore* new_store = |
| 150 new_context_->GetURLRequestContext()->cookie_store(); | 152 new_context_->GetURLRequestContext()->cookie_store(); |
| 151 net::CookieMonster* new_monster = new_store->GetCookieMonster(); | 153 net::CookieMonster* new_monster = new_store->GetCookieMonster(); |
| 152 | 154 |
| 153 if (!new_monster->InitializeFrom(cookies)) { | 155 if (!new_monster->InitializeFrom(cookies)) { |
| 154 LOG(WARNING) << "Failed initial cookie transfer."; | 156 LOG(WARNING) << "Failed initial cookie transfer."; |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 | 159 |
| 158 private: | 160 private: |
| 159 net::URLRequestContextGetter* auth_context_; | 161 net::URLRequestContextGetter* auth_context_; |
| 160 net::URLRequestContextGetter* new_context_; | 162 net::URLRequestContextGetter* new_context_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 GaiaConstants::kPicasaService, | 219 GaiaConstants::kPicasaService, |
| 218 oauth1_token_, | 220 oauth1_token_, |
| 219 oauth1_secret_); | 221 oauth1_secret_); |
| 220 } | 222 } |
| 221 } | 223 } |
| 222 | 224 |
| 223 // GaiaOAuthConsumer implementation: | 225 // GaiaOAuthConsumer implementation: |
| 224 virtual void OnOAuthLoginSuccess(const std::string& sid, | 226 virtual void OnOAuthLoginSuccess(const std::string& sid, |
| 225 const std::string& lsid, | 227 const std::string& lsid, |
| 226 const std::string& auth) OVERRIDE { | 228 const std::string& auth) OVERRIDE { |
| 227 GaiaAuthConsumer::ClientLoginResult credentials(sid, | 229 GaiaAuthConsumer::ClientLoginResult credentials( |
| 228 lsid, auth, std::string()); | 230 sid, lsid, auth, std::string()); |
| 229 UserManager::Get()->set_offline_login(false); | 231 UserManager::Get()->set_offline_login(false); |
| 230 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 232 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 231 new StartSyncOnUIThreadTask(credentials)); | 233 new StartSyncOnUIThreadTask(credentials)); |
| 232 } | 234 } |
| 233 | 235 |
| 234 virtual void OnOAuthLoginFailure( | 236 virtual void OnOAuthLoginFailure( |
| 235 const GoogleServiceAuthError& error) OVERRIDE { | 237 const GoogleServiceAuthError& error) OVERRIDE { |
| 236 LOG(WARNING) << "Failed to verify OAuth1 access tokens," | 238 LOG(WARNING) << "Failed to verify OAuth1 access tokens," |
| 237 << " error.state=" << error.state(); | 239 << " error.state=" << error.state(); |
| 238 | 240 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 // error. That will make us verify user OAuth token and try to fetch session | 305 // error. That will make us verify user OAuth token and try to fetch session |
| 304 // cookies again once we detect that the machine comes online. | 306 // cookies again once we detect that the machine comes online. |
| 305 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) | 307 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) |
| 306 UserManager::Get()->set_offline_login(true); | 308 UserManager::Get()->set_offline_login(true); |
| 307 } | 309 } |
| 308 | 310 |
| 309 GaiaAuthFetcher gaia_fetcher_; | 311 GaiaAuthFetcher gaia_fetcher_; |
| 310 DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher); | 312 DISALLOW_COPY_AND_ASSIGN(UserSessionCookieFetcher); |
| 311 }; | 313 }; |
| 312 | 314 |
| 313 | 315 // Fetches the oauth token for the device management service. Since Profile |
| 314 // Fetches an OAuth token and initializes user policy with it. | 316 // creation might be blocking on a user policy fetch, this fetcher must always |
| 317 // send a (possibly empty) token to the BrowserPolicyConnector, which will then | |
| 318 // let the policy subsystem proceed and resume Profile creation. | |
| 319 // Sending the token even when no Profile is pending is also OK. | |
| 315 class PolicyOAuthFetcher : public GaiaOAuthConsumer { | 320 class PolicyOAuthFetcher : public GaiaOAuthConsumer { |
| 316 public: | 321 public: |
| 322 // Fetches the device management service's oauth token using |oauth1_token| | |
| 323 // and |oauth1_secret| as access tokens. | |
| 317 PolicyOAuthFetcher(Profile* profile, | 324 PolicyOAuthFetcher(Profile* profile, |
| 318 const std::string& oauth1_token, | 325 const std::string& oauth1_token, |
| 319 const std::string& oauth1_secret) | 326 const std::string& oauth1_secret) |
| 320 : oauth_fetcher_(this, | 327 : oauth_fetcher_(this, |
| 321 profile->GetRequestContext(), | 328 profile->GetRequestContext(), |
| 322 profile, | 329 profile, |
| 323 kServiceScopeChromeOSDeviceManagement), | 330 kServiceScopeChromeOSDeviceManagement), |
| 324 oauth1_token_(oauth1_token), | 331 oauth1_token_(oauth1_token), |
| 325 oauth1_secret_(oauth1_secret) { | 332 oauth1_secret_(oauth1_secret) { |
| 326 oauth_fetcher_.SetAutoFetchLimit( | |
| 327 GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); | |
| 328 } | 333 } |
| 334 | |
| 335 // Fetches the device management service's oauth token, after also retrieving | |
| 336 // the access tokens. | |
| 337 explicit PolicyOAuthFetcher(Profile* profile) | |
| 338 : oauth_fetcher_(this, | |
| 339 profile->GetRequestContext(), | |
| 340 profile, | |
| 341 kServiceScopeChromeOSDeviceManagement) { | |
| 342 } | |
| 343 | |
| 329 virtual ~PolicyOAuthFetcher() {} | 344 virtual ~PolicyOAuthFetcher() {} |
| 330 | 345 |
| 331 void Start() { | 346 void Start() { |
| 332 oauth_fetcher_.StartOAuthWrapBridge( | 347 oauth_fetcher_.SetAutoFetchLimit( |
| 333 oauth1_token_, oauth1_secret_, GaiaConstants::kGaiaOAuthDuration, | 348 GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); |
| 334 std::string(kServiceScopeChromeOSDeviceManagement)); | 349 |
| 350 if (oauth1_token_.empty()) { | |
| 351 oauth_fetcher_.StartGetOAuthTokenRequest(); | |
| 352 } else { | |
| 353 oauth_fetcher_.StartOAuthWrapBridge( | |
| 354 oauth1_token_, oauth1_secret_, GaiaConstants::kGaiaOAuthDuration, | |
| 355 std::string(kServiceScopeChromeOSDeviceManagement)); | |
| 356 } | |
| 335 } | 357 } |
| 336 | 358 |
| 337 // GaiaOAuthConsumer implementation: | 359 const std::string& oauth1_token() const { return oauth1_token_; } |
| 360 const std::string& oauth1_secret() const { return oauth1_secret_; } | |
| 361 | |
| 362 private: | |
| 363 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE { | |
| 364 VLOG(1) << "Got OAuth request token"; | |
| 365 } | |
| 366 | |
| 367 virtual void OnGetOAuthTokenFailure( | |
| 368 const GoogleServiceAuthError& error) OVERRIDE { | |
| 369 LOG(WARNING) << "Failed to get OAuth request token"; | |
| 370 SetPolicyToken(""); | |
| 371 } | |
| 372 | |
| 373 virtual void OnOAuthGetAccessTokenSuccess( | |
| 374 const std::string& token, | |
| 375 const std::string& secret) OVERRIDE { | |
| 376 VLOG(1) << "Got OAuth access token"; | |
| 377 oauth1_token_ = token; | |
| 378 oauth1_secret_ = secret; | |
| 379 } | |
| 380 | |
| 381 virtual void OnOAuthGetAccessTokenFailure( | |
| 382 const GoogleServiceAuthError& error) OVERRIDE { | |
| 383 LOG(WARNING) << "Failed to get OAuth access token"; | |
| 384 SetPolicyToken(""); | |
| 385 } | |
| 386 | |
| 338 virtual void OnOAuthWrapBridgeSuccess( | 387 virtual void OnOAuthWrapBridgeSuccess( |
| 339 const std::string& service_name, | 388 const std::string& service_name, |
| 340 const std::string& token, | 389 const std::string& token, |
| 341 const std::string& expires_in) OVERRIDE { | 390 const std::string& expires_in) OVERRIDE { |
| 342 policy::BrowserPolicyConnector* browser_policy_connector = | 391 VLOG(1) << "Got OAuth access token for " << service_name; |
| 343 g_browser_process->browser_policy_connector(); | 392 SetPolicyToken(token); |
| 344 browser_policy_connector->RegisterForUserPolicy(token); | |
| 345 } | 393 } |
| 346 | 394 |
| 347 virtual void OnOAuthWrapBridgeFailure( | 395 virtual void OnOAuthWrapBridgeFailure( |
| 348 const std::string& service_name, | 396 const std::string& service_name, |
| 349 const GoogleServiceAuthError& error) OVERRIDE { | 397 const GoogleServiceAuthError& error) OVERRIDE { |
| 350 LOG(WARNING) << "Failed to get OAuth access token for " << service_name; | 398 LOG(WARNING) << "Failed to get OAuth access token for " << service_name; |
| 399 SetPolicyToken(""); | |
| 351 } | 400 } |
| 352 | 401 |
| 353 private: | 402 void SetPolicyToken(const std::string& token) { |
| 403 g_browser_process->browser_policy_connector()->RegisterForUserPolicy(token); | |
| 404 } | |
| 405 | |
| 354 GaiaOAuthFetcher oauth_fetcher_; | 406 GaiaOAuthFetcher oauth_fetcher_; |
| 355 std::string oauth1_token_; | 407 std::string oauth1_token_; |
| 356 std::string oauth1_secret_; | 408 std::string oauth1_secret_; |
| 357 | 409 |
| 358 DISALLOW_COPY_AND_ASSIGN(PolicyOAuthFetcher); | 410 DISALLOW_COPY_AND_ASSIGN(PolicyOAuthFetcher); |
| 359 }; | 411 }; |
| 360 | 412 |
| 361 // Used to request a restart to switch to the guest mode. | 413 // Used to request a restart to switch to the guest mode. |
| 362 class JobRestartRequest | 414 class JobRestartRequest |
| 363 : public base::RefCountedThreadSafe<JobRestartRequest> { | 415 : public base::RefCountedThreadSafe<JobRestartRequest> { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 Profile* new_profile) OVERRIDE; | 505 Profile* new_profile) OVERRIDE; |
| 454 virtual void TransferDefaultAuthCache(Profile* default_profile, | 506 virtual void TransferDefaultAuthCache(Profile* default_profile, |
| 455 Profile* new_profile) OVERRIDE; | 507 Profile* new_profile) OVERRIDE; |
| 456 | 508 |
| 457 // ProfileManagerObserver implementation: | 509 // ProfileManagerObserver implementation: |
| 458 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE; | 510 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE; |
| 459 | 511 |
| 460 // GaiaOAuthConsumer overrides. | 512 // GaiaOAuthConsumer overrides. |
| 461 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 513 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; |
| 462 virtual void OnGetOAuthTokenFailure( | 514 virtual void OnGetOAuthTokenFailure( |
| 463 const GoogleServiceAuthError& error) OVERRIDE; | 515 const GoogleServiceAuthError& error) OVERRIDE; |
| 464 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, | 516 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, |
| 465 const std::string& secret) OVERRIDE; | 517 const std::string& secret) OVERRIDE; |
| 466 virtual void OnOAuthGetAccessTokenFailure( | 518 virtual void OnOAuthGetAccessTokenFailure( |
| 467 const GoogleServiceAuthError& error) OVERRIDE; | 519 const GoogleServiceAuthError& error) OVERRIDE; |
| 468 | 520 |
| 469 // net::NetworkChangeNotifier::OnlineStateObserver overrides. | 521 // net::NetworkChangeNotifier::OnlineStateObserver overrides. |
| 470 virtual void OnOnlineStateChanged(bool online) OVERRIDE; | 522 virtual void OnOnlineStateChanged(bool online) OVERRIDE; |
| 471 | 523 |
| 472 // Given the authenticated credentials from the cookie jar, try to exchange | 524 // Given the authenticated credentials from the cookie jar, try to exchange |
| 473 // fetch OAuth request, v1 and v2 tokens. | 525 // fetch OAuth request, v1 and v2 tokens. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 std::string username_; | 572 std::string username_; |
| 521 std::string password_; | 573 std::string password_; |
| 522 GaiaAuthConsumer::ClientLoginResult credentials_; | 574 GaiaAuthConsumer::ClientLoginResult credentials_; |
| 523 bool pending_requests_; | 575 bool pending_requests_; |
| 524 bool using_oauth_; | 576 bool using_oauth_; |
| 525 bool has_cookies_; | 577 bool has_cookies_; |
| 526 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). | 578 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). |
| 527 scoped_refptr<Authenticator> authenticator_; | 579 scoped_refptr<Authenticator> authenticator_; |
| 528 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; | 580 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; |
| 529 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; | 581 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; |
| 582 scoped_ptr<PolicyOAuthFetcher> policy_oauth_early_fetcher_; | |
|
Mattias Nissler (ping if slow)
2011/11/11 11:41:23
I don't see why we need two pointers here, wouldn'
Joao da Silva
2011/11/11 12:55:14
The 2nd pointer was used to distinguish early poli
| |
| 530 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; | 583 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; |
| 531 | 584 |
| 532 // Delegate to be fired when the profile will be prepared. | 585 // Delegate to be fired when the profile will be prepared. |
| 533 LoginUtils::Delegate* delegate_; | 586 LoginUtils::Delegate* delegate_; |
| 534 | 587 |
| 535 // Used to restart Chrome to switch to the guest mode. | 588 // Used to restart Chrome to switch to the guest mode. |
| 536 JobRestartRequest* job_restart_request_; | 589 JobRestartRequest* job_restart_request_; |
| 537 | 590 |
| 538 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); | 591 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
| 539 }; | 592 }; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 username_ = username; | 648 username_ = username; |
| 596 password_ = password; | 649 password_ = password; |
| 597 | 650 |
| 598 credentials_ = credentials; | 651 credentials_ = credentials; |
| 599 pending_requests_ = pending_requests; | 652 pending_requests_ = pending_requests; |
| 600 using_oauth_ = using_oauth; | 653 using_oauth_ = using_oauth; |
| 601 has_cookies_ = has_cookies; | 654 has_cookies_ = has_cookies; |
| 602 delegate_ = delegate; | 655 delegate_ = delegate; |
| 603 | 656 |
| 604 // Initialize user policy before the profile is created so the profile | 657 // Initialize user policy before the profile is created so the profile |
| 605 // initialization code sees the policy settings. | 658 // initialization code sees the cached policy settings. |
| 606 g_browser_process->browser_policy_connector()->InitializeUserPolicy(username); | 659 policy::BrowserPolicyConnector* connector = |
| 660 g_browser_process->browser_policy_connector(); | |
| 661 bool user_policy_needs_fetch = connector->InitializeUserPolicy(username); | |
| 662 if (user_policy_needs_fetch) { | |
| 663 if (using_oauth_ && authenticator_.get()) { | |
| 664 // Profile creation will block until user policy is fetched, which | |
| 665 // requires the DeviceManagement token. Try to fetch it now. | |
| 666 VLOG(1) << "Profile creation requires policy token, fetching now"; | |
| 667 policy_oauth_early_fetcher_.reset( | |
| 668 new PolicyOAuthFetcher(authenticator_->authentication_profile())); | |
| 669 policy_oauth_early_fetcher_->Start(); | |
| 670 } else { | |
| 671 // Tell the policy subsystem to resume without a policy fetch. | |
| 672 connector->RegisterForUserPolicy(""); | |
| 673 } | |
| 674 } | |
| 607 | 675 |
| 608 // The default profile will have been changed because the ProfileManager | 676 // The default profile will have been changed because the ProfileManager |
| 609 // will process the notification that the UserManager sends out. | 677 // will process the notification that the UserManager sends out. |
| 610 ProfileManager::CreateDefaultProfileAsync(this); | 678 ProfileManager::CreateDefaultProfileAsync(this); |
| 611 } | 679 } |
| 612 | 680 |
| 613 void LoginUtilsImpl::DelegateDeleted(Delegate* delegate) { | 681 void LoginUtilsImpl::DelegateDeleted(Delegate* delegate) { |
| 614 if (delegate_ == delegate) | 682 if (delegate_ == delegate) |
| 615 delegate_ = NULL; | 683 delegate_ = NULL; |
| 616 } | 684 } |
| 617 | 685 |
| 618 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { | 686 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { |
| 619 CHECK(user_profile); | 687 CHECK(user_profile); |
| 620 switch (status) { | 688 switch (status) { |
| 621 case STATUS_INITIALIZED: | 689 case STATUS_INITIALIZED: |
| 622 break; | 690 break; |
| 623 case STATUS_CREATED: | 691 case STATUS_CREATED: |
| 624 if (UserManager::Get()->current_user_is_new()) | 692 if (UserManager::Get()->current_user_is_new()) |
| 625 SetFirstLoginPrefs(user_profile->GetPrefs()); | 693 SetFirstLoginPrefs(user_profile->GetPrefs()); |
| 626 RespectLocalePreference(user_profile); | 694 RespectLocalePreference(user_profile); |
| 627 return; | 695 return; |
| 628 case STATUS_FAIL: | 696 case STATUS_FAIL: |
| 629 default: | 697 default: |
| 630 NOTREACHED(); | 698 NOTREACHED(); |
| 631 return; | 699 return; |
| 632 } | 700 } |
| 633 | 701 |
| 634 // Initialize the user-policy backend. | 702 // Initialize the user-policy backend. |
| 635 policy::BrowserPolicyConnector* browser_policy_connector = | |
| 636 g_browser_process->browser_policy_connector(); | |
| 637 | |
| 638 if (!using_oauth_) { | 703 if (!using_oauth_) { |
| 639 browser_policy_connector->SetUserPolicyTokenService( | 704 g_browser_process->browser_policy_connector()-> |
| 640 user_profile->GetTokenService()); | 705 SetUserPolicyTokenService(user_profile->GetTokenService()); |
| 641 } | 706 } |
| 642 | 707 |
| 643 // We suck. This is a hack since we do not have the enterprise feature | 708 // We suck. This is a hack since we do not have the enterprise feature |
| 644 // done yet to pull down policies from the domain admin. We'll take this | 709 // done yet to pull down policies from the domain admin. We'll take this |
| 645 // out when we get that done properly. | 710 // out when we get that done properly. |
| 646 // TODO(xiyuan): Remove this once enterprise feature is ready. | 711 // TODO(xiyuan): Remove this once enterprise feature is ready. |
| 647 if (EndsWith(username_, "@google.com", true)) { | 712 if (EndsWith(username_, "@google.com", true)) { |
| 648 PrefService* pref_service = user_profile->GetPrefs(); | 713 PrefService* pref_service = user_profile->GetPrefs(); |
| 649 pref_service->SetBoolean(prefs::kEnableScreenLock, true); | 714 pref_service->SetBoolean(prefs::kEnableScreenLock, true); |
| 650 } | 715 } |
| 651 | 716 |
| 652 BootTimesLoader* btl = BootTimesLoader::Get(); | 717 BootTimesLoader* btl = BootTimesLoader::Get(); |
| 653 btl->AddLoginTimeMarker("UserProfileGotten", false); | 718 btl->AddLoginTimeMarker("UserProfileGotten", false); |
| 654 | 719 |
| 655 if (using_oauth_) { | 720 if (using_oauth_) { |
| 721 // Reuse the access token fetched by the PolicyOAuthFetcher, if it was | |
| 722 // used to fetch policies before Profile creation. | |
| 723 if (policy_oauth_early_fetcher_.get()) { | |
| 724 VLOG(1) << "Resuming profile creation after fetching policy token"; | |
| 725 StoreOAuth1AccessToken(user_profile, | |
| 726 policy_oauth_early_fetcher_->oauth1_token(), | |
| 727 policy_oauth_early_fetcher_->oauth1_secret()); | |
| 728 } | |
| 729 | |
| 656 // Transfer cookies when user signs in using extension. | 730 // Transfer cookies when user signs in using extension. |
| 657 if (has_cookies_) { | 731 if (has_cookies_) { |
| 658 // Transfer cookies from the profile that was used for authentication. | 732 // Transfer cookies from the profile that was used for authentication. |
| 659 // This profile contains cookies that auth extension should have already | 733 // This profile contains cookies that auth extension should have already |
| 660 // put in place that will ensure that the newly created session is | 734 // put in place that will ensure that the newly created session is |
| 661 // authenticated for the websites that work with the used authentication | 735 // authenticated for the websites that work with the used authentication |
| 662 // schema. | 736 // schema. |
| 663 TransferDefaultCookies(authenticator_->authentication_profile(), | 737 TransferDefaultCookies(authenticator_->authentication_profile(), |
| 664 user_profile); | 738 user_profile); |
| 665 } | 739 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 // TODO(altimofeev): Need to sanitize memory used to store password. | 813 // TODO(altimofeev): Need to sanitize memory used to store password. |
| 740 credentials_ = GaiaAuthConsumer::ClientLoginResult(); | 814 credentials_ = GaiaAuthConsumer::ClientLoginResult(); |
| 741 } | 815 } |
| 742 | 816 |
| 743 void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) { | 817 void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) { |
| 744 oauth_fetcher_.reset(new GaiaOAuthFetcher(this, | 818 oauth_fetcher_.reset(new GaiaOAuthFetcher(this, |
| 745 auth_profile->GetRequestContext(), | 819 auth_profile->GetRequestContext(), |
| 746 auth_profile, | 820 auth_profile, |
| 747 kServiceScopeChromeOS)); | 821 kServiceScopeChromeOS)); |
| 748 // Let's first get the Oauth request token and OAuth1 token+secret. | 822 // Let's first get the Oauth request token and OAuth1 token+secret. |
| 749 // One we get that, we will kick off individial requests for OAuth2 tokens for | 823 // Once we get that, we will kick off individual requests for OAuth2 tokens |
| 750 // all our services. | 824 // for all our services. |
| 751 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); | 825 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); |
| 752 oauth_fetcher_->StartGetOAuthTokenRequest(); | 826 oauth_fetcher_->StartGetOAuthTokenRequest(); |
| 753 } | 827 } |
| 754 | 828 |
| 755 void LoginUtilsImpl::FetchCookies(Profile* user_profile, | 829 void LoginUtilsImpl::FetchCookies(Profile* user_profile, |
| 756 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 830 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 757 if (!using_oauth_) { | 831 if (!using_oauth_) { |
| 758 // Take the credentials passed in and try to exchange them for | 832 // Take the credentials passed in and try to exchange them for |
| 759 // full-fledged Google authentication cookies. This is | 833 // full-fledged Google authentication cookies. This is |
| 760 // best-effort; it's possible that we'll fail due to network | 834 // best-effort; it's possible that we'll fail due to network |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 password_, false); | 867 password_, false); |
| 794 username_ = ""; | 868 username_ = ""; |
| 795 password_ = ""; | 869 password_ = ""; |
| 796 | 870 |
| 797 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile); | 871 token_service->Initialize(GaiaConstants::kChromeOSSource, user_profile); |
| 798 token_service->LoadTokensFromDB(); | 872 token_service->LoadTokensFromDB(); |
| 799 } | 873 } |
| 800 token_service->UpdateCredentials(credentials); | 874 token_service->UpdateCredentials(credentials); |
| 801 if (token_service->AreCredentialsValid()) | 875 if (token_service->AreCredentialsValid()) |
| 802 token_service->StartFetchingTokens(); | 876 token_service->StartFetchingTokens(); |
| 803 | |
| 804 } | 877 } |
| 805 | 878 |
| 806 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { | 879 void LoginUtilsImpl::RespectLocalePreference(Profile* profile) { |
| 807 DCHECK(profile != NULL); | 880 DCHECK(profile != NULL); |
| 808 PrefService* prefs = profile->GetPrefs(); | 881 PrefService* prefs = profile->GetPrefs(); |
| 809 DCHECK(prefs != NULL); | 882 DCHECK(prefs != NULL); |
| 810 if (g_browser_process == NULL) | 883 if (g_browser_process == NULL) |
| 811 return; | 884 return; |
| 812 | 885 |
| 813 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); | 886 std::string pref_locale = prefs->GetString(prefs::kApplicationLocale); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token, | 1134 void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token, |
| 1062 const std::string& secret) { | 1135 const std::string& secret) { |
| 1063 VLOG(1) << "Got OAuth v1 token!"; | 1136 VLOG(1) << "Got OAuth v1 token!"; |
| 1064 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1137 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| 1065 StoreOAuth1AccessToken(user_profile, token, secret); | 1138 StoreOAuth1AccessToken(user_profile, token, secret); |
| 1066 | 1139 |
| 1067 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. | 1140 // Verify OAuth1 token by doing OAuthLogin and fetching credentials. |
| 1068 VerifyOAuth1AccessToken(user_profile, token, secret); | 1141 VerifyOAuth1AccessToken(user_profile, token, secret); |
| 1069 } | 1142 } |
| 1070 | 1143 |
| 1144 void LoginUtilsImpl::OnOAuthGetAccessTokenFailure( | |
| 1145 const GoogleServiceAuthError& error) { | |
| 1146 // TODO(zelidrag): Pop up sync setup UI here? | |
| 1147 LOG(WARNING) << "Failed fetching OAuth request token"; | |
|
Mattias Nissler (ping if slow)
2011/11/11 11:41:23
This logged error.state() before, why did you drop
Joao da Silva
2011/11/11 12:55:14
Done.
| |
| 1148 } | |
| 1149 | |
| 1071 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, | 1150 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, |
| 1072 const std::string& token, | 1151 const std::string& token, |
| 1073 const std::string& secret) { | 1152 const std::string& secret) { |
| 1074 FetchPolicyToken(offrecord_profile, token, secret); | 1153 FetchPolicyToken(offrecord_profile, token, secret); |
| 1075 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 1154 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
| 1076 // capable of handling OAuth1 tokens directly. | 1155 // capable of handling OAuth1 tokens directly. |
| 1077 } | 1156 } |
| 1078 | 1157 |
| 1079 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 1158 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
| 1080 std::string* token, | 1159 std::string* token, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 token, | 1214 token, |
| 1136 secret, | 1215 secret, |
| 1137 username_)); | 1216 username_)); |
| 1138 oauth_login_verifier_->Start(); | 1217 oauth_login_verifier_->Start(); |
| 1139 } | 1218 } |
| 1140 | 1219 |
| 1141 | 1220 |
| 1142 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, | 1221 void LoginUtilsImpl::FetchPolicyToken(Profile* offrecord_profile, |
| 1143 const std::string& token, | 1222 const std::string& token, |
| 1144 const std::string& secret) { | 1223 const std::string& secret) { |
| 1145 // Trigger oauth token fetch for user policy. | 1224 if (policy_oauth_early_fetcher_.get()) { |
| 1146 policy_oauth_fetcher_.reset(new PolicyOAuthFetcher(offrecord_profile, | 1225 // User policy has already been fetched. Reset the early policy fetcher |
| 1147 token, | 1226 // now, so that subsequent calls of FetchSecondaryTokens fetch the policy |
| 1148 secret)); | 1227 // token again. |
| 1149 policy_oauth_fetcher_->Start(); | 1228 policy_oauth_early_fetcher_.reset(); |
| 1229 } else { | |
| 1230 // Trigger oauth token fetch for user policy. | |
| 1231 policy_oauth_fetcher_.reset(new PolicyOAuthFetcher(offrecord_profile, | |
| 1232 token, | |
| 1233 secret)); | |
| 1234 policy_oauth_fetcher_->Start(); | |
| 1235 } | |
| 1150 | 1236 |
| 1151 // TODO(zelidrag): We should add initialization of other services somewhere | 1237 // TODO(zelidrag): We should add initialization of other services somewhere |
| 1152 // here as well. This could be handled with TokenService class once it is | 1238 // here as well. This could be handled with TokenService class once it is |
| 1153 // ready to handle OAuth tokens. | 1239 // ready to handle OAuth tokens. |
| 1154 | 1240 |
| 1155 // We don't need authenticator instance any more, reset it so that | 1241 // We don't need authenticator instance any more, reset it so that |
| 1156 // ScreenLocker would create a separate instance. | 1242 // ScreenLocker would create a separate instance. |
| 1157 // TODO(nkostylev): There's a potential race if SL would be created before | 1243 // TODO(nkostylev): There's a potential race if SL would be created before |
| 1158 // OAuth tokens are fetched. It would use incorrect Authenticator instance. | 1244 // OAuth tokens are fetched. It would use incorrect Authenticator instance. |
| 1159 authenticator_ = NULL; | 1245 authenticator_ = NULL; |
| 1160 } | 1246 } |
| 1161 | 1247 |
| 1162 void LoginUtilsImpl::OnOAuthGetAccessTokenFailure( | |
| 1163 const GoogleServiceAuthError& error) { | |
| 1164 // TODO(zelidrag): Pop up sync setup UI here? | |
| 1165 LOG(WARNING) << "Failed fetching OAuth v1 token, error: " << error.state(); | |
| 1166 } | |
| 1167 | |
| 1168 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { | 1248 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { |
| 1169 // If we come online for the first time after successful offline login, | 1249 // If we come online for the first time after successful offline login, |
| 1170 // we need to kick of OAuth token verification process again. | 1250 // we need to kick of OAuth token verification process again. |
| 1171 if (UserManager::Get()->user_is_logged_in() && | 1251 if (UserManager::Get()->user_is_logged_in() && |
| 1172 UserManager::Get()->offline_login() && online) { | 1252 UserManager::Get()->offline_login() && online) { |
| 1173 if (!authenticator_.get()) | 1253 if (!authenticator_.get()) |
| 1174 CreateAuthenticator(NULL); | 1254 CreateAuthenticator(NULL); |
| 1175 std::string oauth1_token; | 1255 std::string oauth1_token; |
| 1176 std::string oauth1_secret; | 1256 std::string oauth1_secret; |
| 1177 Profile* user_profile = ProfileManager::GetDefaultProfile(); | 1257 Profile* user_profile = ProfileManager::GetDefaultProfile(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1211 // Mark login host for deletion after browser starts. This | 1291 // Mark login host for deletion after browser starts. This |
| 1212 // guarantees that the message loop will be referenced by the | 1292 // guarantees that the message loop will be referenced by the |
| 1213 // browser before it is dereferenced by the login host. | 1293 // browser before it is dereferenced by the login host. |
| 1214 if (login_host) { | 1294 if (login_host) { |
| 1215 login_host->OnSessionStart(); | 1295 login_host->OnSessionStart(); |
| 1216 login_host = NULL; | 1296 login_host = NULL; |
| 1217 } | 1297 } |
| 1218 } | 1298 } |
| 1219 | 1299 |
| 1220 } // namespace chromeos | 1300 } // namespace chromeos |
| OLD | NEW |