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

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

Issue 57103002: Make OAuth2TokenService::Request class multi-login aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 1 month 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 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 <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 29 matching lines...) Expand all
40 40
41 if (account_id < p.account_id) 41 if (account_id < p.account_id)
42 return true; 42 return true;
43 else if (p.account_id < account_id) 43 else if (p.account_id < account_id)
44 return false; 44 return false;
45 45
46 return scopes < p.scopes; 46 return scopes < p.scopes;
47 } 47 }
48 48
49 OAuth2TokenService::RequestImpl::RequestImpl( 49 OAuth2TokenService::RequestImpl::RequestImpl(
50 const std::string& account_id,
50 OAuth2TokenService::Consumer* consumer) 51 OAuth2TokenService::Consumer* consumer)
51 : consumer_(consumer) { 52 : account_id_(account_id),
53 consumer_(consumer) {
52 } 54 }
53 55
54 OAuth2TokenService::RequestImpl::~RequestImpl() { 56 OAuth2TokenService::RequestImpl::~RequestImpl() {
55 DCHECK(CalledOnValidThread()); 57 DCHECK(CalledOnValidThread());
56 } 58 }
57 59
60 std::string OAuth2TokenService::RequestImpl::GetAccountId() const {
61 return account_id_;
62 }
63
58 void OAuth2TokenService::RequestImpl::InformConsumer( 64 void OAuth2TokenService::RequestImpl::InformConsumer(
59 const GoogleServiceAuthError& error, 65 const GoogleServiceAuthError& error,
60 const std::string& access_token, 66 const std::string& access_token,
61 const base::Time& expiration_date) { 67 const base::Time& expiration_date) {
62 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
63 if (error.state() == GoogleServiceAuthError::NONE) 69 if (error.state() == GoogleServiceAuthError::NONE)
64 consumer_->OnGetTokenSuccess(this, access_token, expiration_date); 70 consumer_->OnGetTokenSuccess(this, access_token, expiration_date);
65 else 71 else
66 consumer_->OnGetTokenFailure(this, error); 72 consumer_->OnGetTokenFailure(this, error);
67 } 73 }
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 scoped_ptr<OAuth2TokenService::Request> 444 scoped_ptr<OAuth2TokenService::Request>
439 OAuth2TokenService::StartRequestForClientWithContext( 445 OAuth2TokenService::StartRequestForClientWithContext(
440 const std::string& account_id, 446 const std::string& account_id,
441 net::URLRequestContextGetter* getter, 447 net::URLRequestContextGetter* getter,
442 const std::string& client_id, 448 const std::string& client_id,
443 const std::string& client_secret, 449 const std::string& client_secret,
444 const ScopeSet& scopes, 450 const ScopeSet& scopes,
445 Consumer* consumer) { 451 Consumer* consumer) {
446 DCHECK(CalledOnValidThread()); 452 DCHECK(CalledOnValidThread());
447 453
448 scoped_ptr<RequestImpl> request = CreateRequest(consumer); 454 scoped_ptr<RequestImpl> request = CreateRequest(account_id, consumer);
449 455
450 if (!RefreshTokenIsAvailable(account_id)) { 456 if (!RefreshTokenIsAvailable(account_id)) {
451 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 457 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
452 &RequestImpl::InformConsumer, 458 &RequestImpl::InformConsumer,
453 request->AsWeakPtr(), 459 request->AsWeakPtr(),
454 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP), 460 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP),
455 std::string(), 461 std::string(),
456 base::Time())); 462 base::Time()));
457 return request.PassAs<Request>(); 463 return request.PassAs<Request>();
458 } 464 }
459 465
460 RequestParameters request_parameters(client_id, 466 RequestParameters request_parameters(client_id,
461 account_id, 467 account_id,
462 scopes); 468 scopes);
463 if (HasCacheEntry(request_parameters)) { 469 if (HasCacheEntry(request_parameters)) {
464 StartCacheLookupRequest(request.get(), request_parameters, consumer); 470 StartCacheLookupRequest(request.get(), request_parameters, consumer);
465 } else { 471 } else {
466 FetchOAuth2Token(request.get(), 472 FetchOAuth2Token(request.get(),
467 account_id, 473 account_id,
468 getter, 474 getter,
469 client_id, 475 client_id,
470 client_secret, 476 client_secret,
471 scopes); 477 scopes);
472 } 478 }
473 return request.PassAs<Request>(); 479 return request.PassAs<Request>();
474 } 480 }
475 481
476 scoped_ptr<OAuth2TokenService::RequestImpl> OAuth2TokenService::CreateRequest( 482 scoped_ptr<OAuth2TokenService::RequestImpl> OAuth2TokenService::CreateRequest(
483 const std::string& account_id,
477 Consumer* consumer) { 484 Consumer* consumer) {
478 return scoped_ptr<RequestImpl>(new RequestImpl(consumer)); 485 return scoped_ptr<RequestImpl>(new RequestImpl(account_id, consumer));
479 } 486 }
480 487
481 void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request, 488 void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request,
482 const std::string& account_id, 489 const std::string& account_id,
483 net::URLRequestContextGetter* getter, 490 net::URLRequestContextGetter* getter,
484 const std::string& client_id, 491 const std::string& client_id,
485 const std::string& client_secret, 492 const std::string& client_secret,
486 const ScopeSet& scopes) { 493 const ScopeSet& scopes) {
487 std::string refresh_token = GetRefreshToken(account_id); 494 std::string refresh_token = GetRefreshToken(account_id);
488 495
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 const std::string& account_id, 740 const std::string& account_id,
734 const ScopeSet& scopes) const { 741 const ScopeSet& scopes) const {
735 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( 742 PendingFetcherMap::const_iterator iter = pending_fetchers_.find(
736 OAuth2TokenService::RequestParameters( 743 OAuth2TokenService::RequestParameters(
737 client_id, 744 client_id,
738 account_id, 745 account_id,
739 scopes)); 746 scopes));
740 return iter == pending_fetchers_.end() ? 747 return iter == pending_fetchers_.end() ?
741 0 : iter->second->GetWaitingRequestCount(); 748 0 : iter->second->GetWaitingRequestCount();
742 } 749 }
OLDNEW
« google_apis/gaia/oauth2_token_service.h ('K') | « google_apis/gaia/oauth2_token_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698