OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/oauth2_token_service.h" | 5 #include "google_apis/gaia/oauth2_token_service.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <vector> | 9 #include <vector> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
13 #include "base/profiler/scoped_tracker.h" | 16 #include "base/profiler/scoped_tracker.h" |
14 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
15 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 21 #include "google_apis/gaia/gaia_urls.h" |
19 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const std::string& account_id, | 155 const std::string& account_id, |
153 net::URLRequestContextGetter* getter, | 156 net::URLRequestContextGetter* getter, |
154 const std::string& client_id, | 157 const std::string& client_id, |
155 const std::string& client_secret, | 158 const std::string& client_secret, |
156 const OAuth2TokenService::ScopeSet& scopes, | 159 const OAuth2TokenService::ScopeSet& scopes, |
157 base::WeakPtr<RequestImpl> waiting_request); | 160 base::WeakPtr<RequestImpl> waiting_request); |
158 void Start(); | 161 void Start(); |
159 void InformWaitingRequests(); | 162 void InformWaitingRequests(); |
160 void InformWaitingRequestsAndDelete(); | 163 void InformWaitingRequestsAndDelete(); |
161 static bool ShouldRetry(const GoogleServiceAuthError& error); | 164 static bool ShouldRetry(const GoogleServiceAuthError& error); |
162 int64 ComputeExponentialBackOffMilliseconds(int retry_num); | 165 int64_t ComputeExponentialBackOffMilliseconds(int retry_num); |
163 | 166 |
164 // |oauth2_token_service_| remains valid for the life of this Fetcher, since | 167 // |oauth2_token_service_| remains valid for the life of this Fetcher, since |
165 // this Fetcher is destructed in the dtor of the OAuth2TokenService or is | 168 // this Fetcher is destructed in the dtor of the OAuth2TokenService or is |
166 // scheduled for deletion at the end of OnGetTokenFailure/OnGetTokenSuccess | 169 // scheduled for deletion at the end of OnGetTokenFailure/OnGetTokenSuccess |
167 // (whichever comes first). | 170 // (whichever comes first). |
168 OAuth2TokenService* const oauth2_token_service_; | 171 OAuth2TokenService* const oauth2_token_service_; |
169 scoped_refptr<net::URLRequestContextGetter> getter_; | 172 scoped_refptr<net::URLRequestContextGetter> getter_; |
170 const std::string account_id_; | 173 const std::string account_id_; |
171 const ScopeSet scopes_; | 174 const ScopeSet scopes_; |
172 std::vector<base::WeakPtr<RequestImpl> > waiting_requests_; | 175 std::vector<base::WeakPtr<RequestImpl> > waiting_requests_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 300 } |
298 | 301 |
299 UMA_HISTOGRAM_ENUMERATION("Signin.OAuth2TokenGetFailure", | 302 UMA_HISTOGRAM_ENUMERATION("Signin.OAuth2TokenGetFailure", |
300 error.state(), GoogleServiceAuthError::NUM_STATES); | 303 error.state(), GoogleServiceAuthError::NUM_STATES); |
301 error_ = error; | 304 error_ = error; |
302 InformWaitingRequestsAndDelete(); | 305 InformWaitingRequestsAndDelete(); |
303 } | 306 } |
304 | 307 |
305 // Returns an exponential backoff in milliseconds including randomness less than | 308 // Returns an exponential backoff in milliseconds including randomness less than |
306 // 1000 ms when retrying fetching an OAuth2 access token. | 309 // 1000 ms when retrying fetching an OAuth2 access token. |
307 int64 OAuth2TokenService::Fetcher::ComputeExponentialBackOffMilliseconds( | 310 int64_t OAuth2TokenService::Fetcher::ComputeExponentialBackOffMilliseconds( |
308 int retry_num) { | 311 int retry_num) { |
309 DCHECK(retry_num < max_fetch_retry_num_); | 312 DCHECK(retry_num < max_fetch_retry_num_); |
310 int64 exponential_backoff_in_seconds = 1 << retry_num; | 313 int64_t exponential_backoff_in_seconds = 1 << retry_num; |
311 // Returns a backoff with randomness < 1000ms | 314 // Returns a backoff with randomness < 1000ms |
312 return (exponential_backoff_in_seconds + base::RandDouble()) * 1000; | 315 return (exponential_backoff_in_seconds + base::RandDouble()) * 1000; |
313 } | 316 } |
314 | 317 |
315 // static | 318 // static |
316 bool OAuth2TokenService::Fetcher::ShouldRetry( | 319 bool OAuth2TokenService::Fetcher::ShouldRetry( |
317 const GoogleServiceAuthError& error) { | 320 const GoogleServiceAuthError& error) { |
318 GoogleServiceAuthError::State error_state = error.state(); | 321 GoogleServiceAuthError::State error_state = error.state(); |
319 return error_state == GoogleServiceAuthError::CONNECTION_FAILED || | 322 return error_state == GoogleServiceAuthError::CONNECTION_FAILED || |
320 error_state == GoogleServiceAuthError::REQUEST_CANCELED || | 323 error_state == GoogleServiceAuthError::REQUEST_CANCELED || |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 const std::string& account_id, | 825 const std::string& account_id, |
823 const ScopeSet& scopes) const { | 826 const ScopeSet& scopes) const { |
824 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 827 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
825 OAuth2TokenService::RequestParameters( | 828 OAuth2TokenService::RequestParameters( |
826 client_id, | 829 client_id, |
827 account_id, | 830 account_id, |
828 scopes)); | 831 scopes)); |
829 return iter == pending_fetchers_.end() ? | 832 return iter == pending_fetchers_.end() ? |
830 0 : iter->second->GetWaitingRequestCount(); | 833 0 : iter->second->GetWaitingRequestCount(); |
831 } | 834 } |
OLD | NEW |