| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/signin/core/browser/gaia_cookie_manager_service.h" | 5 #include "components/signin/core/browser/gaia_cookie_manager_service.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 GaiaUrls::GetInstance()->google_url(), | 300 GaiaUrls::GetInstance()->google_url(), |
| 301 "APISID", | 301 "APISID", |
| 302 base::Bind(&GaiaCookieManagerService::OnCookieChanged, | 302 base::Bind(&GaiaCookieManagerService::OnCookieChanged, |
| 303 base::Unretained(this))); | 303 base::Unretained(this))); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void GaiaCookieManagerService::Shutdown() { | 306 void GaiaCookieManagerService::Shutdown() { |
| 307 cookie_changed_subscription_.reset(); | 307 cookie_changed_subscription_.reset(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void GaiaCookieManagerService::AddAccountToCookie( | 310 |
| 311 void GaiaCookieManagerService::AddAccountToCookieInternal( |
| 311 const std::string& account_id) { | 312 const std::string& account_id) { |
| 313 DCHECK(!account_id.empty()); |
| 312 if (!signin_client_->AreSigninCookiesAllowed()) { | 314 if (!signin_client_->AreSigninCookiesAllowed()) { |
| 313 SignalComplete(account_id, | 315 SignalComplete(account_id, |
| 314 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); | 316 GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED)); |
| 315 return; | 317 return; |
| 316 } | 318 } |
| 317 | 319 |
| 318 DCHECK(!account_id.empty()); | |
| 319 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id; | |
| 320 requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id)); | 320 requests_.push_back(GaiaCookieRequest::CreateAddAccountRequest(account_id)); |
| 321 if (requests_.size() == 1) { | 321 if (requests_.size() == 1) { |
| 322 signin_client_->DelayNetworkCall( | 322 signin_client_->DelayNetworkCall( |
| 323 base::Bind(&GaiaCookieManagerService::StartFetchingUbertoken, | 323 base::Bind(&GaiaCookieManagerService::StartFetchingUbertoken, |
| 324 base::Unretained(this))); | 324 base::Unretained(this))); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 void GaiaCookieManagerService::AddAccountToCookie( |
| 329 const std::string& account_id) { |
| 330 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookie: " << account_id; |
| 331 access_token_ = std::string(); |
| 332 AddAccountToCookieInternal(account_id); |
| 333 } |
| 334 |
| 335 void GaiaCookieManagerService::AddAccountToCookieWithToken( |
| 336 const std::string& account_id, |
| 337 const std::string& access_token) { |
| 338 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookieWithToken: " |
| 339 << account_id; |
| 340 DCHECK(!access_token.empty()); |
| 341 access_token_ = access_token; |
| 342 AddAccountToCookieInternal(account_id); |
| 343 } |
| 344 |
| 328 bool GaiaCookieManagerService::ListAccounts( | 345 bool GaiaCookieManagerService::ListAccounts( |
| 329 std::vector<std::pair<std::string,bool> >* accounts) { | 346 std::vector<std::pair<std::string,bool> >* accounts) { |
| 330 DCHECK(accounts); | 347 DCHECK(accounts); |
| 331 accounts->clear(); | 348 accounts->clear(); |
| 332 | 349 |
| 333 // There is a fetch currently executing (the results being provided in the | 350 // There is a fetch currently executing (the results being provided in the |
| 334 // parameter don't align with the fetches that have been started), or the list | 351 // parameter don't align with the fetches that have been started), or the list |
| 335 // of accounts haven't been fetched even once. | 352 // of accounts haven't been fetched even once. |
| 336 if (!requests_.empty()) | 353 if (!requests_.empty()) |
| 337 return false; | 354 return false; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 base::Unretained(this)))); | 600 base::Unretained(this)))); |
| 584 return; | 601 return; |
| 585 } | 602 } |
| 586 | 603 |
| 587 FOR_EACH_OBSERVER(Observer, observer_list_, | 604 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 588 OnGaiaAccountsInCookieUpdated(listed_accounts_, error)); | 605 OnGaiaAccountsInCookieUpdated(listed_accounts_, error)); |
| 589 HandleNextRequest(); | 606 HandleNextRequest(); |
| 590 } | 607 } |
| 591 | 608 |
| 592 void GaiaCookieManagerService::StartFetchingUbertoken() { | 609 void GaiaCookieManagerService::StartFetchingUbertoken() { |
| 593 VLOG(1) << "GaiaCookieManagerService::StartFetching account_id=" | 610 VLOG(1) << "GaiaCookieManagerService::StartFetchingUbertoken account_id=" |
| 594 << requests_.front().account_id(); | 611 << requests_.front().account_id(); |
| 595 uber_token_fetcher_.reset( | 612 uber_token_fetcher_.reset( |
| 596 new UbertokenFetcher(token_service_, this, source_, | 613 new UbertokenFetcher(token_service_, this, source_, |
| 597 signin_client_->GetURLRequestContext())); | 614 signin_client_->GetURLRequestContext())); |
| 598 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); | 615 if (access_token_.empty()) { |
| 616 uber_token_fetcher_->StartFetchingToken(requests_.front().account_id()); |
| 617 } else { |
| 618 uber_token_fetcher_->StartFetchingTokenWithAccessToken( |
| 619 requests_.front().account_id(), access_token_); |
| 620 } |
| 599 } | 621 } |
| 600 | 622 |
| 601 void GaiaCookieManagerService::StartFetchingMergeSession() { | 623 void GaiaCookieManagerService::StartFetchingMergeSession() { |
| 602 DCHECK(!uber_token_.empty()); | 624 DCHECK(!uber_token_.empty()); |
| 603 gaia_auth_fetcher_.reset( | 625 gaia_auth_fetcher_.reset( |
| 604 new GaiaAuthFetcher(this, source_, | 626 new GaiaAuthFetcher(this, source_, |
| 605 signin_client_->GetURLRequestContext())); | 627 signin_client_->GetURLRequestContext())); |
| 606 | 628 |
| 607 gaia_auth_fetcher_->StartMergeSession(uber_token_, | 629 gaia_auth_fetcher_->StartMergeSession(uber_token_, |
| 608 external_cc_result_fetcher_.GetExternalCcResult()); | 630 external_cc_result_fetcher_.GetExternalCcResult()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } else { | 674 } else { |
| 653 // Pop the completed request. | 675 // Pop the completed request. |
| 654 requests_.pop_front(); | 676 requests_.pop_front(); |
| 655 } | 677 } |
| 656 | 678 |
| 657 gaia_auth_fetcher_.reset(); | 679 gaia_auth_fetcher_.reset(); |
| 658 fetcher_retries_ = 0; | 680 fetcher_retries_ = 0; |
| 659 if (requests_.empty()) { | 681 if (requests_.empty()) { |
| 660 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; | 682 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest: no more"; |
| 661 uber_token_fetcher_.reset(); | 683 uber_token_fetcher_.reset(); |
| 684 access_token_ = std::string(); |
| 662 } else { | 685 } else { |
| 663 switch (requests_.front().request_type()) { | 686 switch (requests_.front().request_type()) { |
| 664 case GaiaCookieRequestType::ADD_ACCOUNT: | 687 case GaiaCookieRequestType::ADD_ACCOUNT: |
| 665 signin_client_->DelayNetworkCall( | 688 signin_client_->DelayNetworkCall( |
| 666 base::Bind(&GaiaCookieManagerService::StartFetchingUbertoken, | 689 base::Bind(&GaiaCookieManagerService::StartFetchingUbertoken, |
| 667 base::Unretained(this))); | 690 base::Unretained(this))); |
| 668 break; | 691 break; |
| 669 case GaiaCookieRequestType::LOG_OUT: | 692 case GaiaCookieRequestType::LOG_OUT: |
| 670 signin_client_->DelayNetworkCall( | 693 signin_client_->DelayNetworkCall( |
| 671 base::Bind(&GaiaCookieManagerService::StartLogOutUrlFetch, | 694 base::Bind(&GaiaCookieManagerService::StartLogOutUrlFetch, |
| 672 base::Unretained(this))); | 695 base::Unretained(this))); |
| 673 break; | 696 break; |
| 674 case GaiaCookieRequestType::LIST_ACCOUNTS: | 697 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 675 uber_token_fetcher_.reset(); | 698 uber_token_fetcher_.reset(); |
| 676 signin_client_->DelayNetworkCall( | 699 signin_client_->DelayNetworkCall( |
| 677 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 700 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
| 678 base::Unretained(this))); | 701 base::Unretained(this))); |
| 679 break; | 702 break; |
| 680 }; | 703 }; |
| 681 } | 704 } |
| 682 } | 705 } |
| OLD | NEW |