Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 // Release all the pending fetchers. | 296 // Release all the pending fetchers. |
| 297 STLDeleteContainerPairSecondPointers( | 297 STLDeleteContainerPairSecondPointers( |
| 298 pending_fetchers_.begin(), pending_fetchers_.end()); | 298 pending_fetchers_.begin(), pending_fetchers_.end()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool OAuth2TokenService::RefreshTokenIsAvailable() { | 301 bool OAuth2TokenService::RefreshTokenIsAvailable() { |
| 302 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 302 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 303 return !GetRefreshToken().empty(); | 303 return !GetRefreshToken().empty(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // static | |
| 307 void OAuth2TokenService::InformConsumer( | |
| 308 base::WeakPtr<OAuth2TokenService::RequestImpl> request, | |
| 309 const GoogleServiceAuthError& error, | |
| 310 const std::string& access_token, | |
| 311 const base::Time& expiration_date) { | |
| 312 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 313 | |
| 314 if (request) | |
| 315 request->InformConsumer(error, access_token, expiration_date); | |
| 316 } | |
| 317 | |
| 318 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( | 306 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( |
| 319 const OAuth2TokenService::ScopeSet& scopes, | 307 const OAuth2TokenService::ScopeSet& scopes, |
| 320 OAuth2TokenService::Consumer* consumer) { | 308 OAuth2TokenService::Consumer* consumer) { |
| 321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 309 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 322 | 310 |
| 323 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); | 311 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); |
| 324 | 312 |
| 325 std::string refresh_token = GetRefreshToken(); | 313 std::string refresh_token = GetRefreshToken(); |
| 326 if (refresh_token.empty()) { | 314 if (refresh_token.empty()) { |
| 327 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 315 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 328 &OAuth2TokenService::InformConsumer, | 316 &RequestImpl::InformConsumer, |
| 329 request->AsWeakPtr(), | 317 request->AsWeakPtr(), |
| 330 GoogleServiceAuthError( | 318 GoogleServiceAuthError( |
| 331 GoogleServiceAuthError::USER_NOT_SIGNED_UP), | 319 GoogleServiceAuthError::USER_NOT_SIGNED_UP), |
| 332 std::string(), | 320 std::string(), |
| 333 base::Time())); | 321 base::Time())); |
| 334 return request.PassAs<Request>(); | 322 return request.PassAs<Request>(); |
| 335 } | 323 } |
| 336 | 324 |
| 337 if (HasCacheEntry(scopes)) | 325 if (HasCacheEntry(scopes)) |
| 338 return StartCacheLookupRequest(scopes, consumer); | 326 return StartCacheLookupRequest(scopes, consumer); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 354 } | 342 } |
| 355 | 343 |
| 356 scoped_ptr<OAuth2TokenService::Request> | 344 scoped_ptr<OAuth2TokenService::Request> |
| 357 OAuth2TokenService::StartCacheLookupRequest( | 345 OAuth2TokenService::StartCacheLookupRequest( |
| 358 const OAuth2TokenService::ScopeSet& scopes, | 346 const OAuth2TokenService::ScopeSet& scopes, |
| 359 OAuth2TokenService::Consumer* consumer) { | 347 OAuth2TokenService::Consumer* consumer) { |
| 360 CHECK(HasCacheEntry(scopes)); | 348 CHECK(HasCacheEntry(scopes)); |
| 361 const CacheEntry* cache_entry = GetCacheEntry(scopes); | 349 const CacheEntry* cache_entry = GetCacheEntry(scopes); |
| 362 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); | 350 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); |
| 363 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 351 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 364 &OAuth2TokenService::InformConsumer, | 352 &RequestImpl::InformConsumer, |
| 365 request->AsWeakPtr(), | 353 request->AsWeakPtr(), |
| 366 GoogleServiceAuthError(GoogleServiceAuthError::NONE), | 354 GoogleServiceAuthError(GoogleServiceAuthError::NONE), |
| 367 cache_entry->access_token, | 355 cache_entry->access_token, |
| 368 cache_entry->expiration_date)); | 356 cache_entry->expiration_date)); |
| 369 return request.PassAs<Request>(); | 357 return request.PassAs<Request>(); |
| 370 } | 358 } |
| 371 | 359 |
| 372 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes, | 360 void OAuth2TokenService::InvalidateToken(const ScopeSet& scopes, |
| 373 const std::string& invalid_token) { | 361 const std::string& invalid_token) { |
| 374 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 362 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 return NULL; | 421 return NULL; |
| 434 } | 422 } |
| 435 return &token_iterator->second; | 423 return &token_iterator->second; |
| 436 } | 424 } |
| 437 | 425 |
| 438 bool OAuth2TokenService::RemoveCacheEntry( | 426 bool OAuth2TokenService::RemoveCacheEntry( |
| 439 const OAuth2TokenService::ScopeSet& scopes, | 427 const OAuth2TokenService::ScopeSet& scopes, |
| 440 const std::string& token_to_remove) { | 428 const std::string& token_to_remove) { |
| 441 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 429 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 442 TokenCache::iterator token_iterator = token_cache_.find(scopes); | 430 TokenCache::iterator token_iterator = token_cache_.find(scopes); |
| 443 if (token_iterator == token_cache_.end() && | 431 if (token_iterator != token_cache_.end() && |
|
Roger Tawa OOO till Jul 10th
2013/05/29 18:14:40
Seems like there are is unit test for InvalidateTo
Bernhard Bauer
2013/05/29 19:16:31
Done.
| |
| 444 token_iterator->second.access_token == token_to_remove) { | 432 token_iterator->second.access_token == token_to_remove) { |
| 445 token_cache_.erase(token_iterator); | 433 token_cache_.erase(token_iterator); |
| 446 return true; | 434 return true; |
| 447 } | 435 } |
| 448 return false; | 436 return false; |
| 449 } | 437 } |
| 450 | 438 |
| 451 void OAuth2TokenService::RegisterCacheEntry( | 439 void OAuth2TokenService::RegisterCacheEntry( |
| 452 const std::string& refresh_token, | 440 const std::string& refresh_token, |
| 453 const OAuth2TokenService::ScopeSet& scopes, | 441 const OAuth2TokenService::ScopeSet& scopes, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 465 } | 453 } |
| 466 | 454 |
| 467 void OAuth2TokenService::ClearCache() { | 455 void OAuth2TokenService::ClearCache() { |
| 468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 456 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 469 token_cache_.clear(); | 457 token_cache_.clear(); |
| 470 } | 458 } |
| 471 | 459 |
| 472 int OAuth2TokenService::cache_size_for_testing() const { | 460 int OAuth2TokenService::cache_size_for_testing() const { |
| 473 return token_cache_.size(); | 461 return token_cache_.size(); |
| 474 } | 462 } |
| OLD | NEW |