| 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" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/signin/core/browser/account_tracker_service.h" |
| 17 #include "components/signin/core/browser/signin_metrics.h" | 18 #include "components/signin/core/browser/signin_metrics.h" |
| 18 #include "google_apis/gaia/gaia_auth_fetcher.h" | 19 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 19 #include "google_apis/gaia/gaia_auth_util.h" | |
| 20 #include "google_apis/gaia/gaia_constants.h" | 20 #include "google_apis/gaia/gaia_constants.h" |
| 21 #include "google_apis/gaia/gaia_urls.h" | 21 #include "google_apis/gaia/gaia_urls.h" |
| 22 #include "google_apis/gaia/oauth2_token_service.h" | 22 #include "google_apis/gaia/oauth2_token_service.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 25 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_fetcher_delegate.h" | 26 #include "net/url_request/url_fetcher_delegate.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 const std::string& account_id, | 331 const std::string& account_id, |
| 332 const std::string& access_token) { | 332 const std::string& access_token) { |
| 333 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookieWithToken: " | 333 VLOG(1) << "GaiaCookieManagerService::AddAccountToCookieWithToken: " |
| 334 << account_id; | 334 << account_id; |
| 335 DCHECK(!access_token.empty()); | 335 DCHECK(!access_token.empty()); |
| 336 access_token_ = access_token; | 336 access_token_ = access_token; |
| 337 AddAccountToCookieInternal(account_id); | 337 AddAccountToCookieInternal(account_id); |
| 338 } | 338 } |
| 339 | 339 |
| 340 bool GaiaCookieManagerService::ListAccounts( | 340 bool GaiaCookieManagerService::ListAccounts( |
| 341 std::vector<std::pair<std::string,bool> >* accounts) { | 341 std::vector<gaia::ListedAccount>* accounts) { |
| 342 DCHECK(accounts); | 342 DCHECK(accounts); |
| 343 accounts->clear(); | 343 accounts->clear(); |
| 344 | 344 |
| 345 // There is a fetch currently executing (the results being provided in the | 345 // There is a fetch currently executing (the results being provided in the |
| 346 // parameter don't align with the fetches that have been started), or the list | 346 // parameter don't align with the fetches that have been started), or the list |
| 347 // of accounts haven't been fetched even once. | 347 // of accounts haven't been fetched even once. |
| 348 if (!requests_.empty()) | 348 if (!requests_.empty()) |
| 349 return false; | 349 return false; |
| 350 | 350 |
| 351 if (!list_accounts_fetched_once_) { | 351 if (!list_accounts_fetched_once_) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 GaiaCookieRequestType::LIST_ACCOUNTS); | 553 GaiaCookieRequestType::LIST_ACCOUNTS); |
| 554 fetcher_backoff_.InformOfRequest(true); | 554 fetcher_backoff_.InformOfRequest(true); |
| 555 | 555 |
| 556 if (!gaia::ParseListAccountsData(data, &listed_accounts_)) { | 556 if (!gaia::ParseListAccountsData(data, &listed_accounts_)) { |
| 557 listed_accounts_.clear(); | 557 listed_accounts_.clear(); |
| 558 OnListAccountsFailure(GoogleServiceAuthError( | 558 OnListAccountsFailure(GoogleServiceAuthError( |
| 559 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); | 559 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)); |
| 560 return; | 560 return; |
| 561 } | 561 } |
| 562 | 562 |
| 563 for (gaia::ListedAccount account : listed_accounts_) { |
| 564 account.id = AccountTrackerService::PickAccountIdForAccount( |
| 565 signin_client_->GetPrefs(), account.gaia_id, account.email); |
| 566 } |
| 567 |
| 563 list_accounts_fetched_once_ = true; | 568 list_accounts_fetched_once_ = true; |
| 564 HandleNextRequest(); | 569 HandleNextRequest(); |
| 565 // HandleNextRequest before sending out the notification because some | 570 // HandleNextRequest before sending out the notification because some |
| 566 // services, in response to OnGaiaAccountsInCookieUpdated, may try in return | 571 // services, in response to OnGaiaAccountsInCookieUpdated, may try in return |
| 567 // to call ListAccounts, which would immediately return false if the | 572 // to call ListAccounts, which would immediately return false if the |
| 568 // ListAccounts request is still sitting in queue. | 573 // ListAccounts request is still sitting in queue. |
| 569 FOR_EACH_OBSERVER(Observer, observer_list_, | 574 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 570 OnGaiaAccountsInCookieUpdated( | 575 OnGaiaAccountsInCookieUpdated( |
| 571 listed_accounts_, | 576 listed_accounts_, |
| 572 GoogleServiceAuthError(GoogleServiceAuthError::NONE))); | 577 GoogleServiceAuthError(GoogleServiceAuthError::NONE))); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 break; | 704 break; |
| 700 case GaiaCookieRequestType::LIST_ACCOUNTS: | 705 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 701 uber_token_fetcher_.reset(); | 706 uber_token_fetcher_.reset(); |
| 702 signin_client_->DelayNetworkCall( | 707 signin_client_->DelayNetworkCall( |
| 703 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 708 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
| 704 base::Unretained(this))); | 709 base::Unretained(this))); |
| 705 break; | 710 break; |
| 706 }; | 711 }; |
| 707 } | 712 } |
| 708 } | 713 } |
| OLD | NEW |