| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| 11 #include "base/format_macros.h" |
| 11 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "components/data_use_measurement/core/data_use_user_data.h" | 19 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 19 #include "components/signin/core/browser/account_tracker_service.h" | 20 #include "components/signin/core/browser/account_tracker_service.h" |
| 20 #include "components/signin/core/browser/signin_metrics.h" | 21 #include "components/signin/core/browser/signin_metrics.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 OAuth2TokenService* token_service, | 292 OAuth2TokenService* token_service, |
| 292 const std::string& source, | 293 const std::string& source, |
| 293 SigninClient* signin_client) | 294 SigninClient* signin_client) |
| 294 : token_service_(token_service), | 295 : token_service_(token_service), |
| 295 signin_client_(signin_client), | 296 signin_client_(signin_client), |
| 296 external_cc_result_fetcher_(this), | 297 external_cc_result_fetcher_(this), |
| 297 fetcher_backoff_(&kBackoffPolicy), | 298 fetcher_backoff_(&kBackoffPolicy), |
| 298 fetcher_retries_(0), | 299 fetcher_retries_(0), |
| 299 source_(source), | 300 source_(source), |
| 300 external_cc_result_fetched_(false), | 301 external_cc_result_fetched_(false), |
| 301 list_accounts_stale_(true) { | 302 list_accounts_stale_(true), |
| 303 // |GaiaCookieManagerService| is created as soon as the profle is |
| 304 // initialized so it is acceptable to use of this |
| 305 // |GaiaCookieManagerService| as the time when the profile is loaded. |
| 306 profile_load_time_(base::Time::Now()), |
| 307 list_accounts_request_counter_(0) { |
| 302 DCHECK(!source_.empty()); | 308 DCHECK(!source_.empty()); |
| 303 } | 309 } |
| 304 | 310 |
| 305 GaiaCookieManagerService::~GaiaCookieManagerService() { | 311 GaiaCookieManagerService::~GaiaCookieManagerService() { |
| 306 CancelAll(); | 312 CancelAll(); |
| 307 DCHECK(requests_.empty()); | 313 DCHECK(requests_.empty()); |
| 308 } | 314 } |
| 309 | 315 |
| 310 void GaiaCookieManagerService::Init() { | 316 void GaiaCookieManagerService::Init() { |
| 311 cookie_changed_subscription_ = signin_client_->AddCookieChangedCallback( | 317 cookie_changed_subscription_ = signin_client_->AddCookieChangedCallback( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 void GaiaCookieManagerService::CancelAll() { | 467 void GaiaCookieManagerService::CancelAll() { |
| 462 VLOG(1) << "GaiaCookieManagerService::CancelAll"; | 468 VLOG(1) << "GaiaCookieManagerService::CancelAll"; |
| 463 gaia_auth_fetcher_.reset(); | 469 gaia_auth_fetcher_.reset(); |
| 464 uber_token_fetcher_.reset(); | 470 uber_token_fetcher_.reset(); |
| 465 requests_.clear(); | 471 requests_.clear(); |
| 466 fetcher_timer_.Stop(); | 472 fetcher_timer_.Stop(); |
| 467 } | 473 } |
| 468 | 474 |
| 469 std::string GaiaCookieManagerService::GetSourceForRequest( | 475 std::string GaiaCookieManagerService::GetSourceForRequest( |
| 470 const GaiaCookieManagerService::GaiaCookieRequest& request) { | 476 const GaiaCookieManagerService::GaiaCookieRequest& request) { |
| 471 return request.source().empty() ? GetDefaultSourceForRequest() : | 477 std::string source = request.source().empty() ? GetDefaultSourceForRequest() |
| 472 request.source(); | 478 : request.source(); |
| 479 if (request.request_type() != LIST_ACCOUNTS) |
| 480 return source; |
| 481 |
| 482 // For list accounts requests, the source also includes the time since the |
| 483 // profile was loaded and the number of the request in order to debug channel |
| 484 // ID issues observed on Gaia. |
| 485 // TODO(msarda): Remove this debug code once the investigations on Gaia side |
| 486 // are over. |
| 487 std::string source_with_debug_info = base::StringPrintf( |
| 488 "%s,counter:%" PRId32 ",load_time_ms:%" PRId64, source.c_str(), |
| 489 list_accounts_request_counter_++, |
| 490 (base::Time::Now() - profile_load_time_).InMilliseconds()); |
| 491 return source_with_debug_info; |
| 473 } | 492 } |
| 474 | 493 |
| 475 std::string GaiaCookieManagerService::GetDefaultSourceForRequest() { | 494 std::string GaiaCookieManagerService::GetDefaultSourceForRequest() { |
| 476 return source_; | 495 return source_; |
| 477 } | 496 } |
| 478 | 497 |
| 479 void GaiaCookieManagerService::OnCookieChanged( | 498 void GaiaCookieManagerService::OnCookieChanged( |
| 480 const net::CanonicalCookie& cookie, | 499 const net::CanonicalCookie& cookie, |
| 481 net::CookieStore::ChangeCause cause) { | 500 net::CookieStore::ChangeCause cause) { |
| 482 DCHECK_EQ(kGaiaCookieName, cookie.Name()); | 501 DCHECK_EQ(kGaiaCookieName, cookie.Name()); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); | 766 DCHECK(requests_.front().request_type() == GaiaCookieRequestType::LOG_OUT); |
| 748 VLOG(1) << "GaiaCookieManagerService::StartFetchingLogOut"; | 767 VLOG(1) << "GaiaCookieManagerService::StartFetchingLogOut"; |
| 749 gaia_auth_fetcher_.reset(signin_client_->CreateGaiaAuthFetcher( | 768 gaia_auth_fetcher_.reset(signin_client_->CreateGaiaAuthFetcher( |
| 750 this, GetSourceForRequest(requests_.front()), | 769 this, GetSourceForRequest(requests_.front()), |
| 751 signin_client_->GetURLRequestContext())); | 770 signin_client_->GetURLRequestContext())); |
| 752 gaia_auth_fetcher_->StartLogOut(); | 771 gaia_auth_fetcher_->StartLogOut(); |
| 753 } | 772 } |
| 754 | 773 |
| 755 void GaiaCookieManagerService::StartFetchingListAccounts() { | 774 void GaiaCookieManagerService::StartFetchingListAccounts() { |
| 756 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; | 775 VLOG(1) << "GaiaCookieManagerService::ListAccounts"; |
| 776 |
| 757 gaia_auth_fetcher_.reset(signin_client_->CreateGaiaAuthFetcher( | 777 gaia_auth_fetcher_.reset(signin_client_->CreateGaiaAuthFetcher( |
| 758 this, GetSourceForRequest(requests_.front()), | 778 this, GetSourceForRequest(requests_.front()), |
| 759 signin_client_->GetURLRequestContext())); | 779 signin_client_->GetURLRequestContext())); |
| 760 gaia_auth_fetcher_->StartListAccounts(); | 780 gaia_auth_fetcher_->StartListAccounts(); |
| 761 } | 781 } |
| 762 | 782 |
| 763 void GaiaCookieManagerService::HandleNextRequest() { | 783 void GaiaCookieManagerService::HandleNextRequest() { |
| 764 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; | 784 VLOG(1) << "GaiaCookieManagerService::HandleNextRequest"; |
| 765 if (requests_.front().request_type() == | 785 if (requests_.front().request_type() == |
| 766 GaiaCookieRequestType::LIST_ACCOUNTS) { | 786 GaiaCookieRequestType::LIST_ACCOUNTS) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 794 break; | 814 break; |
| 795 case GaiaCookieRequestType::LIST_ACCOUNTS: | 815 case GaiaCookieRequestType::LIST_ACCOUNTS: |
| 796 uber_token_fetcher_.reset(); | 816 uber_token_fetcher_.reset(); |
| 797 signin_client_->DelayNetworkCall( | 817 signin_client_->DelayNetworkCall( |
| 798 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, | 818 base::Bind(&GaiaCookieManagerService::StartFetchingListAccounts, |
| 799 base::Unretained(this))); | 819 base::Unretained(this))); |
| 800 break; | 820 break; |
| 801 } | 821 } |
| 802 } | 822 } |
| 803 } | 823 } |
| OLD | NEW |