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

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

Issue 22581003: Handling of multiple concurrent requests from different clients in OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // completes fetching (in this case, the waiting requests will be called back 71 // completes fetching (in this case, the waiting requests will be called back
72 // with error). 72 // with error).
73 class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer { 73 class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
74 public: 74 public:
75 // Creates a Fetcher and starts fetching an OAuth2 access token for 75 // Creates a Fetcher and starts fetching an OAuth2 access token for
76 // |refresh_token| and |scopes| in the request context obtained by |getter|. 76 // |refresh_token| and |scopes| in the request context obtained by |getter|.
77 // The given |oauth2_token_service| will be informed when fetching is done. 77 // The given |oauth2_token_service| will be informed when fetching is done.
78 static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service, 78 static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service,
79 net::URLRequestContextGetter* getter, 79 net::URLRequestContextGetter* getter,
80 const std::string& chrome_client_id, 80 const std::string& chrome_client_id,
81 const std::string& chrome_client_secret, 81 const std::string& chrome_client_secret,
(NOT FOR CODE REVIEWS) 2013/08/07 19:56:49 Remove |chrome_| prefix from these two args. A fe
zel 2013/08/08 01:34:24 Done.
82 const std::string& refresh_token, 82 const std::string& refresh_token,
83 const OAuth2TokenService::ScopeSet& scopes, 83 const OAuth2TokenService::ScopeSet& scopes,
84 base::WeakPtr<RequestImpl> waiting_request); 84 base::WeakPtr<RequestImpl> waiting_request);
85 virtual ~Fetcher(); 85 virtual ~Fetcher();
86 86
87 // Add a request that is waiting for the result of this Fetcher. 87 // Add a request that is waiting for the result of this Fetcher.
88 void AddWaitingRequest(base::WeakPtr<RequestImpl> waiting_request); 88 void AddWaitingRequest(base::WeakPtr<RequestImpl> waiting_request);
89 89
90 void Cancel(); 90 void Cancel();
91 91
92 const OAuth2TokenService::ScopeSet& GetScopeSet() const; 92 const OAuth2TokenService::ScopeSet& GetScopeSet() const;
93 const std::string& GetRefreshToken() const; 93 const std::string& GetRefreshToken() const;
94 const std::string& GetClientId() const;
94 95
95 // The error result from this fetcher. 96 // The error result from this fetcher.
96 const GoogleServiceAuthError& error() const { return error_; } 97 const GoogleServiceAuthError& error() const { return error_; }
97 98
98 protected: 99 protected:
99 // OAuth2AccessTokenConsumer 100 // OAuth2AccessTokenConsumer
100 virtual void OnGetTokenSuccess(const std::string& access_token, 101 virtual void OnGetTokenSuccess(const std::string& access_token,
101 const base::Time& expiration_date) OVERRIDE; 102 const base::Time& expiration_date) OVERRIDE;
102 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; 103 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
103 104
(...skipping 25 matching lines...) Expand all
129 base::OneShotTimer<OAuth2TokenService::Fetcher> retry_timer_; 130 base::OneShotTimer<OAuth2TokenService::Fetcher> retry_timer_;
130 scoped_ptr<OAuth2AccessTokenFetcher> fetcher_; 131 scoped_ptr<OAuth2AccessTokenFetcher> fetcher_;
131 132
132 // Variables that store fetch results. 133 // Variables that store fetch results.
133 // Initialized to be GoogleServiceAuthError::SERVICE_UNAVAILABLE to handle 134 // Initialized to be GoogleServiceAuthError::SERVICE_UNAVAILABLE to handle
134 // destruction. 135 // destruction.
135 GoogleServiceAuthError error_; 136 GoogleServiceAuthError error_;
136 std::string access_token_; 137 std::string access_token_;
137 base::Time expiration_date_; 138 base::Time expiration_date_;
138 // OAuth2 client id and secret. 139 // OAuth2 client id and secret.
139 std::string chrome_client_id_; 140 std::string client_id_;
140 std::string chrome_client_secret_; 141 std::string client_secret_;
141 142
142 DISALLOW_COPY_AND_ASSIGN(Fetcher); 143 DISALLOW_COPY_AND_ASSIGN(Fetcher);
143 }; 144 };
144 145
145 // static 146 // static
146 OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart( 147 OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart(
147 OAuth2TokenService* oauth2_token_service, 148 OAuth2TokenService* oauth2_token_service,
148 net::URLRequestContextGetter* getter, 149 net::URLRequestContextGetter* getter,
149 const std::string& chrome_client_id, 150 const std::string& chrome_client_id,
150 const std::string& chrome_client_secret, 151 const std::string& chrome_client_secret,
151 const std::string& refresh_token, 152 const std::string& refresh_token,
152 const OAuth2TokenService::ScopeSet& scopes, 153 const OAuth2TokenService::ScopeSet& scopes,
153 base::WeakPtr<RequestImpl> waiting_request) { 154 base::WeakPtr<RequestImpl> waiting_request) {
154 OAuth2TokenService::Fetcher* fetcher = new Fetcher( 155 OAuth2TokenService::Fetcher* fetcher = new Fetcher(
155 oauth2_token_service, 156 oauth2_token_service,
156 getter, 157 getter,
157 chrome_client_id, 158 chrome_client_id,
158 chrome_client_secret, 159 chrome_client_secret,
159 refresh_token, 160 refresh_token,
160 scopes, 161 scopes,
161 waiting_request); 162 waiting_request);
162 fetcher->Start(); 163 fetcher->Start();
163 return fetcher; 164 return fetcher;
164 } 165 }
165 166
166 OAuth2TokenService::Fetcher::Fetcher( 167 OAuth2TokenService::Fetcher::Fetcher(
167 OAuth2TokenService* oauth2_token_service, 168 OAuth2TokenService* oauth2_token_service,
168 net::URLRequestContextGetter* getter, 169 net::URLRequestContextGetter* getter,
169 const std::string& chrome_client_id, 170 const std::string& client_id,
170 const std::string& chrome_client_secret, 171 const std::string& client_secret,
171 const std::string& refresh_token, 172 const std::string& refresh_token,
172 const OAuth2TokenService::ScopeSet& scopes, 173 const OAuth2TokenService::ScopeSet& scopes,
173 base::WeakPtr<RequestImpl> waiting_request) 174 base::WeakPtr<RequestImpl> waiting_request)
174 : oauth2_token_service_(oauth2_token_service), 175 : oauth2_token_service_(oauth2_token_service),
175 getter_(getter), 176 getter_(getter),
176 refresh_token_(refresh_token), 177 refresh_token_(refresh_token),
177 scopes_(scopes), 178 scopes_(scopes),
178 retry_number_(0), 179 retry_number_(0),
179 error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE), 180 error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE),
180 chrome_client_id_(chrome_client_id), 181 client_id_(client_id),
181 chrome_client_secret_(chrome_client_secret) { 182 client_secret_(client_secret) {
182 DCHECK(oauth2_token_service_); 183 DCHECK(oauth2_token_service_);
183 DCHECK(getter_.get()); 184 DCHECK(getter_.get());
184 DCHECK(refresh_token_.length()); 185 DCHECK(refresh_token_.length());
185 waiting_requests_.push_back(waiting_request); 186 waiting_requests_.push_back(waiting_request);
186 } 187 }
187 188
188 OAuth2TokenService::Fetcher::~Fetcher() { 189 OAuth2TokenService::Fetcher::~Fetcher() {
189 // Inform the waiting requests if it has not done so. 190 // Inform the waiting requests if it has not done so.
190 if (waiting_requests_.size()) 191 if (waiting_requests_.size())
191 InformWaitingRequests(); 192 InformWaitingRequests();
192 } 193 }
193 194
194 void OAuth2TokenService::Fetcher::Start() { 195 void OAuth2TokenService::Fetcher::Start() {
195 fetcher_.reset(new OAuth2AccessTokenFetcher(this, getter_.get())); 196 fetcher_.reset(new OAuth2AccessTokenFetcher(this, getter_.get()));
196 fetcher_->Start(chrome_client_id_, 197 fetcher_->Start(client_id_,
197 chrome_client_secret_, 198 client_secret_,
198 refresh_token_, 199 refresh_token_,
199 std::vector<std::string>(scopes_.begin(), scopes_.end())); 200 std::vector<std::string>(scopes_.begin(), scopes_.end()));
200 retry_timer_.Stop(); 201 retry_timer_.Stop();
201 } 202 }
202 203
203 void OAuth2TokenService::Fetcher::OnGetTokenSuccess( 204 void OAuth2TokenService::Fetcher::OnGetTokenSuccess(
204 const std::string& access_token, 205 const std::string& access_token,
205 const base::Time& expiration_date) { 206 const base::Time& expiration_date) {
206 fetcher_.reset(); 207 fetcher_.reset();
207 208
208 // Fetch completes. 209 // Fetch completes.
209 error_ = GoogleServiceAuthError::AuthErrorNone(); 210 error_ = GoogleServiceAuthError::AuthErrorNone();
210 access_token_ = access_token; 211 access_token_ = access_token;
211 expiration_date_ = expiration_date; 212 expiration_date_ = expiration_date;
212 213
213 // Subclasses may override this method to skip caching in some cases, but 214 // Subclasses may override this method to skip caching in some cases, but
214 // we still inform all waiting Consumers of a successful token fetch below. 215 // we still inform all waiting Consumers of a successful token fetch below.
215 // This is intentional -- some consumers may need the token for cleanup 216 // This is intentional -- some consumers may need the token for cleanup
216 // tasks. https://chromiumcodereview.appspot.com/11312124/ 217 // tasks. https://chromiumcodereview.appspot.com/11312124/
217 oauth2_token_service_->RegisterCacheEntry(refresh_token_, 218 oauth2_token_service_->RegisterCacheEntry(client_id_,
219 refresh_token_,
218 scopes_, 220 scopes_,
219 access_token_, 221 access_token_,
220 expiration_date_); 222 expiration_date_);
221 InformWaitingRequestsAndDelete(); 223 InformWaitingRequestsAndDelete();
222 } 224 }
223 225
224 void OAuth2TokenService::Fetcher::OnGetTokenFailure( 226 void OAuth2TokenService::Fetcher::OnGetTokenFailure(
225 const GoogleServiceAuthError& error) { 227 const GoogleServiceAuthError& error) {
226 fetcher_.reset(); 228 fetcher_.reset();
227 229
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 294
293 const OAuth2TokenService::ScopeSet& OAuth2TokenService::Fetcher::GetScopeSet() 295 const OAuth2TokenService::ScopeSet& OAuth2TokenService::Fetcher::GetScopeSet()
294 const { 296 const {
295 return scopes_; 297 return scopes_;
296 } 298 }
297 299
298 const std::string& OAuth2TokenService::Fetcher::GetRefreshToken() const { 300 const std::string& OAuth2TokenService::Fetcher::GetRefreshToken() const {
299 return refresh_token_; 301 return refresh_token_;
300 } 302 }
301 303
304 const std::string& OAuth2TokenService::Fetcher::GetClientId() const {
305 return client_id_;
306 }
307
302 OAuth2TokenService::Request::Request() { 308 OAuth2TokenService::Request::Request() {
303 } 309 }
304 310
305 OAuth2TokenService::Request::~Request() { 311 OAuth2TokenService::Request::~Request() {
306 } 312 }
307 313
308 OAuth2TokenService::Consumer::Consumer() { 314 OAuth2TokenService::Consumer::Consumer() {
309 } 315 }
310 316
311 OAuth2TokenService::Consumer::~Consumer() { 317 OAuth2TokenService::Consumer::~Consumer() {
(...skipping 26 matching lines...) Expand all
338 const OAuth2TokenService::ScopeSet& scopes, 344 const OAuth2TokenService::ScopeSet& scopes,
339 OAuth2TokenService::Consumer* consumer) { 345 OAuth2TokenService::Consumer* consumer) {
340 return StartRequestForClientWithContext( 346 return StartRequestForClientWithContext(
341 GetRequestContext(), 347 GetRequestContext(),
342 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 348 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
343 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 349 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
344 scopes, 350 scopes,
345 consumer); 351 consumer);
346 } 352 }
347 353
354 #if defined(OS_CHROMEOS)
348 scoped_ptr<OAuth2TokenService::Request> 355 scoped_ptr<OAuth2TokenService::Request>
349 OAuth2TokenService::StartRequestForClient( 356 OAuth2TokenService::StartRequestForClient(
350 const std::string& client_id, 357 const std::string& client_id,
351 const std::string& client_secret, 358 const std::string& client_secret,
352 const OAuth2TokenService::ScopeSet& scopes, 359 const OAuth2TokenService::ScopeSet& scopes,
353 OAuth2TokenService::Consumer* consumer) { 360 OAuth2TokenService::Consumer* consumer) {
354 return StartRequestForClientWithContext( 361 return StartRequestForClientWithContext(
355 GetRequestContext(), 362 GetRequestContext(),
356 client_id, 363 client_id,
357 client_secret, 364 client_secret,
358 scopes, 365 scopes,
359 consumer); 366 consumer);
360 } 367 }
368 #endif
361 369
362 scoped_ptr<OAuth2TokenService::Request> 370 scoped_ptr<OAuth2TokenService::Request>
363 OAuth2TokenService::StartRequestWithContext( 371 OAuth2TokenService::StartRequestWithContext(
364 net::URLRequestContextGetter* getter, 372 net::URLRequestContextGetter* getter,
365 const ScopeSet& scopes, 373 const ScopeSet& scopes,
366 Consumer* consumer) { 374 Consumer* consumer) {
367 return StartRequestForClientWithContext( 375 return StartRequestForClientWithContext(
368 getter, 376 getter,
369 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 377 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
370 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 378 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
(...skipping 17 matching lines...) Expand all
388 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 396 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
389 &RequestImpl::InformConsumer, 397 &RequestImpl::InformConsumer,
390 request->AsWeakPtr(), 398 request->AsWeakPtr(),
391 GoogleServiceAuthError( 399 GoogleServiceAuthError(
392 GoogleServiceAuthError::USER_NOT_SIGNED_UP), 400 GoogleServiceAuthError::USER_NOT_SIGNED_UP),
393 std::string(), 401 std::string(),
394 base::Time())); 402 base::Time()));
395 return request.PassAs<Request>(); 403 return request.PassAs<Request>();
396 } 404 }
397 405
398 if (HasCacheEntry(scopes)) 406 ClientScopeSet client_scopes(client_id, scopes);
399 return StartCacheLookupRequest(scopes, consumer); 407 if (HasCacheEntry(client_scopes))
408 return StartCacheLookupRequest(client_scopes, consumer);
400 409
401 // If there is already a pending fetcher for |scopes| and |refresh_token|, 410 // If there is already a pending fetcher for |scopes| and |refresh_token|,
402 // simply register this |request| for those results rather than starting 411 // simply register this |request| for those results rather than starting
403 // a new fetcher. 412 // a new fetcher.
404 FetchParameters fetch_parameters = std::make_pair(refresh_token, scopes); 413 FetchParameters fetch_parameters = std::make_pair(
414 std::make_pair(client_id, refresh_token), scopes);
405 std::map<FetchParameters, Fetcher*>::iterator iter = 415 std::map<FetchParameters, Fetcher*>::iterator iter =
406 pending_fetchers_.find(fetch_parameters); 416 pending_fetchers_.find(fetch_parameters);
407 if (iter != pending_fetchers_.end()) { 417 if (iter != pending_fetchers_.end()) {
408 iter->second->AddWaitingRequest(request->AsWeakPtr()); 418 iter->second->AddWaitingRequest(request->AsWeakPtr());
409 return request.PassAs<Request>(); 419 return request.PassAs<Request>();
410 } 420 }
411 421
412 pending_fetchers_[fetch_parameters] = 422 pending_fetchers_[fetch_parameters] =
413 Fetcher::CreateAndStart(this, 423 Fetcher::CreateAndStart(this,
414 getter, 424 getter,
415 client_id, 425 client_id,
416 client_secret, 426 client_secret,
417 refresh_token, 427 refresh_token,
418 scopes, 428 scopes,
419 request->AsWeakPtr()); 429 request->AsWeakPtr());
420 return request.PassAs<Request>(); 430 return request.PassAs<Request>();
421 } 431 }
422 432
423 scoped_ptr<OAuth2TokenService::Request> 433 scoped_ptr<OAuth2TokenService::Request>
424 OAuth2TokenService::StartCacheLookupRequest( 434 OAuth2TokenService::StartCacheLookupRequest(
425 const OAuth2TokenService::ScopeSet& scopes, 435 const OAuth2TokenService::ClientScopeSet& client_scopes,
426 OAuth2TokenService::Consumer* consumer) { 436 OAuth2TokenService::Consumer* consumer) {
427 CHECK(HasCacheEntry(scopes)); 437 CHECK(HasCacheEntry(client_scopes));
428 const CacheEntry* cache_entry = GetCacheEntry(scopes); 438 const CacheEntry* cache_entry = GetCacheEntry(client_scopes);
429 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); 439 scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
430 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 440 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
431 &RequestImpl::InformConsumer, 441 &RequestImpl::InformConsumer,
432 request->AsWeakPtr(), 442 request->AsWeakPtr(),
433 GoogleServiceAuthError(GoogleServiceAuthError::NONE), 443 GoogleServiceAuthError(GoogleServiceAuthError::NONE),
434 cache_entry->access_token, 444 cache_entry->access_token,
435 cache_entry->expiration_date)); 445 cache_entry->expiration_date));
436 return request.PassAs<Request>(); 446 return request.PassAs<Request>();
437 } 447 }
438 448
439 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes, 449 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes,
440 const std::string& invalid_token) { 450 const std::string& invalid_token) {
441 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 451 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
442 RemoveCacheEntry(scopes, invalid_token); 452 RemoveCacheEntry(
453 ClientScopeSet(GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
454 scopes),
455 invalid_token);
443 } 456 }
444 457
445 void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) { 458 void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) {
446 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 459 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
447 460
448 // Update the auth error state so auth errors are appropriately communicated 461 // Update the auth error state so auth errors are appropriately communicated
449 // to the user. 462 // to the user.
450 UpdateAuthError(fetcher->error()); 463 UpdateAuthError(fetcher->error());
451 464
452 // Note |fetcher| is recorded in |pending_fetcher_| mapped to its refresh 465 // Note |fetcher| is recorded in |pending_fetcher_| mapped to its refresh
(...skipping 17 matching lines...) Expand all
470 // (3) Each of the Fetchers recorded in |pending_fetchers_| is mapped to its 483 // (3) Each of the Fetchers recorded in |pending_fetchers_| is mapped to its
471 // refresh token and ScopeSet. This is guaranteed by Fetcher creation in 484 // refresh token and ScopeSet. This is guaranteed by Fetcher creation in
472 // method StartRequest(). 485 // method StartRequest().
473 // 486 //
474 // When this method is called, |fetcher| is alive and uncompleted. 487 // When this method is called, |fetcher| is alive and uncompleted.
475 // By (1), |fetcher| is created by this service. 488 // By (1), |fetcher| is created by this service.
476 // Then by (2), |fetcher| is recorded in |pending_fetchers_|. 489 // Then by (2), |fetcher| is recorded in |pending_fetchers_|.
477 // Then by (3), |fetcher_| is mapped to its refresh token and ScopeSet. 490 // Then by (3), |fetcher_| is mapped to its refresh token and ScopeSet.
478 std::map<FetchParameters, Fetcher*>::iterator iter = 491 std::map<FetchParameters, Fetcher*>::iterator iter =
479 pending_fetchers_.find(std::make_pair( 492 pending_fetchers_.find(std::make_pair(
480 fetcher->GetRefreshToken(), fetcher->GetScopeSet())); 493 std::make_pair(fetcher->GetClientId(),
494 fetcher->GetRefreshToken()),
495 fetcher->GetScopeSet()));
481 DCHECK(iter != pending_fetchers_.end()); 496 DCHECK(iter != pending_fetchers_.end());
482 DCHECK_EQ(fetcher, iter->second); 497 DCHECK_EQ(fetcher, iter->second);
483 pending_fetchers_.erase(iter); 498 pending_fetchers_.erase(iter);
484 } 499 }
485 500
486 bool OAuth2TokenService::HasCacheEntry( 501 bool OAuth2TokenService::HasCacheEntry(
487 const OAuth2TokenService::ScopeSet& scopes) { 502 const ClientScopeSet& client_scopes) {
488 const CacheEntry* cache_entry = GetCacheEntry(scopes); 503 const CacheEntry* cache_entry = GetCacheEntry(client_scopes);
489 return cache_entry && cache_entry->access_token.length(); 504 return cache_entry && cache_entry->access_token.length();
490 } 505 }
491 506
492 const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry( 507 const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry(
493 const OAuth2TokenService::ScopeSet& scopes) { 508 const ClientScopeSet& client_scopes) {
494 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 509 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
495 TokenCache::iterator token_iterator = token_cache_.find(scopes); 510 TokenCache::iterator token_iterator = token_cache_.find(client_scopes);
496 if (token_iterator == token_cache_.end()) 511 if (token_iterator == token_cache_.end())
497 return NULL; 512 return NULL;
498 if (token_iterator->second.expiration_date <= base::Time::Now()) { 513 if (token_iterator->second.expiration_date <= base::Time::Now()) {
499 token_cache_.erase(token_iterator); 514 token_cache_.erase(token_iterator);
500 return NULL; 515 return NULL;
501 } 516 }
502 return &token_iterator->second; 517 return &token_iterator->second;
503 } 518 }
504 519
505 bool OAuth2TokenService::RemoveCacheEntry( 520 bool OAuth2TokenService::RemoveCacheEntry(
506 const OAuth2TokenService::ScopeSet& scopes, 521 const ClientScopeSet& client_scopes,
507 const std::string& token_to_remove) { 522 const std::string& token_to_remove) {
508 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 523 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
509 TokenCache::iterator token_iterator = token_cache_.find(scopes); 524 TokenCache::iterator token_iterator = token_cache_.find(client_scopes);
510 if (token_iterator != token_cache_.end() && 525 if (token_iterator != token_cache_.end() &&
511 token_iterator->second.access_token == token_to_remove) { 526 token_iterator->second.access_token == token_to_remove) {
512 token_cache_.erase(token_iterator); 527 token_cache_.erase(token_iterator);
513 return true; 528 return true;
514 } 529 }
515 return false; 530 return false;
516 } 531 }
517 532
518 void OAuth2TokenService::RegisterCacheEntry( 533 void OAuth2TokenService::RegisterCacheEntry(
534 const std::string& client_id,
519 const std::string& refresh_token, 535 const std::string& refresh_token,
520 const OAuth2TokenService::ScopeSet& scopes, 536 const OAuth2TokenService::ScopeSet& scopes,
521 const std::string& access_token, 537 const std::string& access_token,
522 const base::Time& expiration_date) { 538 const base::Time& expiration_date) {
523 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 539 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
524 540
525 CacheEntry& token = token_cache_[scopes]; 541 CacheEntry& token = token_cache_[ClientScopeSet(client_id, scopes)];
526 token.access_token = access_token; 542 token.access_token = access_token;
527 token.expiration_date = expiration_date; 543 token.expiration_date = expiration_date;
528 } 544 }
529 545
530 void OAuth2TokenService::UpdateAuthError(const GoogleServiceAuthError& error) { 546 void OAuth2TokenService::UpdateAuthError(const GoogleServiceAuthError& error) {
531 // Default implementation does nothing. 547 // Default implementation does nothing.
532 } 548 }
533 549
534 void OAuth2TokenService::ClearCache() { 550 void OAuth2TokenService::ClearCache() {
535 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 551 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 11 matching lines...) Expand all
547 CancelFetchers(fetchers_to_cancel); 563 CancelFetchers(fetchers_to_cancel);
548 } 564 }
549 565
550 void OAuth2TokenService::CancelRequestsForToken( 566 void OAuth2TokenService::CancelRequestsForToken(
551 const std::string& refresh_token) { 567 const std::string& refresh_token) {
552 std::vector<Fetcher*> fetchers_to_cancel; 568 std::vector<Fetcher*> fetchers_to_cancel;
553 for (std::map<FetchParameters, Fetcher*>::iterator iter = 569 for (std::map<FetchParameters, Fetcher*>::iterator iter =
554 pending_fetchers_.begin(); 570 pending_fetchers_.begin();
555 iter != pending_fetchers_.end(); 571 iter != pending_fetchers_.end();
556 ++iter) { 572 ++iter) {
557 if (iter->first.first == refresh_token) 573 if (iter->first.first.second == refresh_token)
558 fetchers_to_cancel.push_back(iter->second); 574 fetchers_to_cancel.push_back(iter->second);
559 } 575 }
560 CancelFetchers(fetchers_to_cancel); 576 CancelFetchers(fetchers_to_cancel);
561 } 577 }
562 578
563 void OAuth2TokenService::CancelFetchers( 579 void OAuth2TokenService::CancelFetchers(
564 std::vector<Fetcher*> fetchers_to_cancel) { 580 std::vector<Fetcher*> fetchers_to_cancel) {
565 for (std::vector<OAuth2TokenService::Fetcher*>::iterator iter = 581 for (std::vector<OAuth2TokenService::Fetcher*>::iterator iter =
566 fetchers_to_cancel.begin(); 582 fetchers_to_cancel.begin();
567 iter != fetchers_to_cancel.end(); 583 iter != fetchers_to_cancel.end();
(...skipping 25 matching lines...) Expand all
593 609
594 int OAuth2TokenService::cache_size_for_testing() const { 610 int OAuth2TokenService::cache_size_for_testing() const {
595 return token_cache_.size(); 611 return token_cache_.size();
596 } 612 }
597 613
598 void OAuth2TokenService::set_max_authorization_token_fetch_retries_for_testing( 614 void OAuth2TokenService::set_max_authorization_token_fetch_retries_for_testing(
599 int max_retries) { 615 int max_retries) {
600 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 616 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
601 max_fetch_retry_num_ = max_retries; 617 max_fetch_retry_num_ = max_retries;
602 } 618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698