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

Side by Side Diff: chrome/browser/signin/oauth2_token_service.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "chrome/browser/signin/oauth2_token_service.h" 5 #include "chrome/browser/signin/oauth2_token_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // This is intentional -- some consumers may need the token for cleanup 206 // This is intentional -- some consumers may need the token for cleanup
207 // tasks. https://chromiumcodereview.appspot.com/11312124/ 207 // tasks. https://chromiumcodereview.appspot.com/11312124/
208 oauth2_token_service_->RegisterCacheEntry(refresh_token_, 208 oauth2_token_service_->RegisterCacheEntry(refresh_token_,
209 scopes_, 209 scopes_,
210 access_token_, 210 access_token_,
211 expiration_date_); 211 expiration_date_);
212 // Deregisters itself from the service to prevent more waiting requests to 212 // Deregisters itself from the service to prevent more waiting requests to
213 // be added when it calls back the waiting requests. 213 // be added when it calls back the waiting requests.
214 oauth2_token_service_->OnFetchComplete(this); 214 oauth2_token_service_->OnFetchComplete(this);
215 InformWaitingRequests(); 215 InformWaitingRequests();
216 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 216 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
217 } 217 }
218 218
219 void OAuth2TokenService::Fetcher::OnGetTokenFailure( 219 void OAuth2TokenService::Fetcher::OnGetTokenFailure(
220 const GoogleServiceAuthError& error) { 220 const GoogleServiceAuthError& error) {
221 fetcher_.reset(); 221 fetcher_.reset();
222 222
223 if (ShouldRetry(error) && retry_number_ < kMaxFetchRetryNum) { 223 if (ShouldRetry(error) && retry_number_ < kMaxFetchRetryNum) {
224 int64 backoff = ComputeExponentialBackOffMilliseconds(retry_number_); 224 int64 backoff = ComputeExponentialBackOffMilliseconds(retry_number_);
225 ++retry_number_; 225 ++retry_number_;
226 retry_timer_.Stop(); 226 retry_timer_.Stop();
227 retry_timer_.Start(FROM_HERE, 227 retry_timer_.Start(FROM_HERE,
228 base::TimeDelta::FromMilliseconds(backoff), 228 base::TimeDelta::FromMilliseconds(backoff),
229 this, 229 this,
230 &OAuth2TokenService::Fetcher::Start); 230 &OAuth2TokenService::Fetcher::Start);
231 return; 231 return;
232 } 232 }
233 233
234 // Fetch completes. 234 // Fetch completes.
235 error_ = error; 235 error_ = error;
236 236
237 // Deregisters itself from the service to prevent more waiting requests to be 237 // Deregisters itself from the service to prevent more waiting requests to be
238 // added when it calls back the waiting requests. 238 // added when it calls back the waiting requests.
239 oauth2_token_service_->OnFetchComplete(this); 239 oauth2_token_service_->OnFetchComplete(this);
240 InformWaitingRequests(); 240 InformWaitingRequests();
241 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 241 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
242 } 242 }
243 243
244 // static 244 // static
245 bool OAuth2TokenService::Fetcher::ShouldRetry( 245 bool OAuth2TokenService::Fetcher::ShouldRetry(
246 const GoogleServiceAuthError& error) { 246 const GoogleServiceAuthError& error) {
247 GoogleServiceAuthError::State error_state = error.state(); 247 GoogleServiceAuthError::State error_state = error.state();
248 return error_state == GoogleServiceAuthError::CONNECTION_FAILED || 248 return error_state == GoogleServiceAuthError::CONNECTION_FAILED ||
249 error_state == GoogleServiceAuthError::REQUEST_CANCELED || 249 error_state == GoogleServiceAuthError::REQUEST_CANCELED ||
250 error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE; 250 error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE;
251 } 251 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 317
318 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( 318 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest(
319 const OAuth2TokenService::ScopeSet& scopes, 319 const OAuth2TokenService::ScopeSet& scopes,
320 OAuth2TokenService::Consumer* consumer) { 320 OAuth2TokenService::Consumer* consumer) {
321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
322 322
323 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); 323 scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
324 324
325 std::string refresh_token = GetRefreshToken(); 325 std::string refresh_token = GetRefreshToken();
326 if (refresh_token.empty()) { 326 if (refresh_token.empty()) {
327 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 327 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
328 &OAuth2TokenService::InformConsumer, 328 &OAuth2TokenService::InformConsumer,
329 request->AsWeakPtr(), 329 request->AsWeakPtr(),
330 GoogleServiceAuthError( 330 GoogleServiceAuthError(
331 GoogleServiceAuthError::USER_NOT_SIGNED_UP), 331 GoogleServiceAuthError::USER_NOT_SIGNED_UP),
332 std::string(), 332 std::string(),
333 base::Time())); 333 base::Time()));
334 return request.PassAs<Request>(); 334 return request.PassAs<Request>();
335 } 335 }
336 336
337 if (HasCacheEntry(scopes)) 337 if (HasCacheEntry(scopes))
(...skipping 15 matching lines...) Expand all
353 return request.PassAs<Request>(); 353 return request.PassAs<Request>();
354 } 354 }
355 355
356 scoped_ptr<OAuth2TokenService::Request> 356 scoped_ptr<OAuth2TokenService::Request>
357 OAuth2TokenService::StartCacheLookupRequest( 357 OAuth2TokenService::StartCacheLookupRequest(
358 const OAuth2TokenService::ScopeSet& scopes, 358 const OAuth2TokenService::ScopeSet& scopes,
359 OAuth2TokenService::Consumer* consumer) { 359 OAuth2TokenService::Consumer* consumer) {
360 CHECK(HasCacheEntry(scopes)); 360 CHECK(HasCacheEntry(scopes));
361 const CacheEntry* cache_entry = GetCacheEntry(scopes); 361 const CacheEntry* cache_entry = GetCacheEntry(scopes);
362 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); 362 scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
363 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 363 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
364 &OAuth2TokenService::InformConsumer, 364 &OAuth2TokenService::InformConsumer,
365 request->AsWeakPtr(), 365 request->AsWeakPtr(),
366 GoogleServiceAuthError(GoogleServiceAuthError::NONE), 366 GoogleServiceAuthError(GoogleServiceAuthError::NONE),
367 cache_entry->access_token, 367 cache_entry->access_token,
368 cache_entry->expiration_date)); 368 cache_entry->expiration_date));
369 return request.PassAs<Request>(); 369 return request.PassAs<Request>();
370 } 370 }
371 371
372 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes, 372 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes,
373 const std::string& invalid_token) { 373 const std::string& invalid_token) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 465 }
466 466
467 void OAuth2TokenService::ClearCache() { 467 void OAuth2TokenService::ClearCache() {
468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
469 token_cache_.clear(); 469 token_cache_.clear();
470 } 470 }
471 471
472 int OAuth2TokenService::cache_size_for_testing() const { 472 int OAuth2TokenService::cache_size_for_testing() const {
473 return token_cache_.size(); 473 return token_cache_.size();
474 } 474 }
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_unittest.cc ('k') | chrome/browser/signin/profile_oauth2_token_service_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698