Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: google_apis/gaia/ubertoken_fetcher.cc

Issue 1148283005: Add histograms to entire MergeSession flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: jwd comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_apis/gaia/oauth2_token_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "google_apis/gaia/ubertoken_fetcher.h" 5 #include "google_apis/gaia/ubertoken_fetcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/rand_util.h" 11 #include "base/rand_util.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "google_apis/gaia/gaia_auth_fetcher.h" 13 #include "google_apis/gaia/gaia_auth_fetcher.h"
13 #include "google_apis/gaia/gaia_constants.h" 14 #include "google_apis/gaia/gaia_constants.h"
14 #include "google_apis/gaia/google_service_auth_error.h" 15 #include "google_apis/gaia/google_service_auth_error.h"
15 #include "google_apis/gaia/oauth2_token_service.h" 16 #include "google_apis/gaia/oauth2_token_service.h"
16 17
17 const int UbertokenFetcher::kMaxRetries = 3; 18 const int UbertokenFetcher::kMaxRetries = 3;
18 19
19 UbertokenFetcher::UbertokenFetcher( 20 UbertokenFetcher::UbertokenFetcher(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const GoogleServiceAuthError& error) { 52 const GoogleServiceAuthError& error) {
52 // Retry only transient errors. 53 // Retry only transient errors.
53 bool should_retry = 54 bool should_retry =
54 error.state() == GoogleServiceAuthError::CONNECTION_FAILED || 55 error.state() == GoogleServiceAuthError::CONNECTION_FAILED ||
55 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE; 56 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE;
56 if (should_retry) { 57 if (should_retry) {
57 if (retry_number_ < kMaxRetries) { 58 if (retry_number_ < kMaxRetries) {
58 // Calculate an exponential backoff with randomness of less than 1 sec. 59 // Calculate an exponential backoff with randomness of less than 1 sec.
59 double backoff = base::RandDouble() + (1 << retry_number_); 60 double backoff = base::RandDouble() + (1 << retry_number_);
60 ++retry_number_; 61 ++retry_number_;
62 UMA_HISTOGRAM_ENUMERATION("Signin.UberTokenRetry",
63 error.state(), GoogleServiceAuthError::NUM_STATES);
61 retry_timer_.Stop(); 64 retry_timer_.Stop();
62 retry_timer_.Start(FROM_HERE, 65 retry_timer_.Start(FROM_HERE,
63 base::TimeDelta::FromSecondsD(backoff), 66 base::TimeDelta::FromSecondsD(backoff),
64 this, 67 this,
65 &UbertokenFetcher::ExchangeTokens); 68 &UbertokenFetcher::ExchangeTokens);
66 return; 69 return;
67 } 70 }
68 } else { 71 } else {
69 // The access token is invalid. Tell the token service. 72 // The access token is invalid. Tell the token service.
70 OAuth2TokenService::ScopeSet scopes; 73 OAuth2TokenService::ScopeSet scopes;
71 scopes.insert(GaiaConstants::kOAuth1LoginScope); 74 scopes.insert(GaiaConstants::kOAuth1LoginScope);
72 token_service_->InvalidateToken(account_id_, scopes, access_token_); 75 token_service_->InvalidateToken(account_id_, scopes, access_token_);
73 76
74 // In case the access was just stale, try one more time. 77 // In case the access was just stale, try one more time.
75 if (!second_access_token_request_) { 78 if (!second_access_token_request_) {
76 second_access_token_request_ = true; 79 second_access_token_request_ = true;
77 RequestAccessToken(); 80 RequestAccessToken();
78 return; 81 return;
79 } 82 }
80 } 83 }
81 84
85 UMA_HISTOGRAM_ENUMERATION("Signin.UberTokenFailure",
86 error.state(), GoogleServiceAuthError::NUM_STATES);
82 consumer_->OnUbertokenFailure(error); 87 consumer_->OnUbertokenFailure(error);
83 } 88 }
84 89
85 void UbertokenFetcher::OnGetTokenSuccess( 90 void UbertokenFetcher::OnGetTokenSuccess(
86 const OAuth2TokenService::Request* request, 91 const OAuth2TokenService::Request* request,
87 const std::string& access_token, 92 const std::string& access_token,
88 const base::Time& expiration_time) { 93 const base::Time& expiration_time) {
89 DCHECK(!access_token.empty()); 94 DCHECK(!access_token.empty());
90 access_token_ = access_token; 95 access_token_ = access_token;
91 access_token_request_.reset(); 96 access_token_request_.reset();
(...skipping 17 matching lines...) Expand all
109 access_token_request_ = 114 access_token_request_ =
110 token_service_->StartRequest(account_id_, scopes, this); 115 token_service_->StartRequest(account_id_, scopes, this);
111 } 116 }
112 117
113 void UbertokenFetcher::ExchangeTokens() { 118 void UbertokenFetcher::ExchangeTokens() {
114 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this, 119 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this,
115 source_, 120 source_,
116 request_context_)); 121 request_context_));
117 gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token_); 122 gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token_);
118 } 123 }
OLDNEW
« no previous file with comments | « google_apis/gaia/oauth2_token_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698