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 <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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const OAuth2TokenService::ScopeSet& scopes, | 207 const OAuth2TokenService::ScopeSet& scopes, |
208 base::WeakPtr<RequestImpl> waiting_request) { | 208 base::WeakPtr<RequestImpl> waiting_request) { |
209 OAuth2TokenService::Fetcher* fetcher = new Fetcher( | 209 OAuth2TokenService::Fetcher* fetcher = new Fetcher( |
210 oauth2_token_service, | 210 oauth2_token_service, |
211 account_id, | 211 account_id, |
212 getter, | 212 getter, |
213 client_id, | 213 client_id, |
214 client_secret, | 214 client_secret, |
215 scopes, | 215 scopes, |
216 waiting_request); | 216 waiting_request); |
| 217 |
| 218 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. |
| 219 tracked_objects::ScopedTracker tracking_profile( |
| 220 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 221 "422460 OAuth2TokenService::Fetcher::CreateAndStart")); |
| 222 |
217 fetcher->Start(); | 223 fetcher->Start(); |
218 return fetcher; | 224 return fetcher; |
219 } | 225 } |
220 | 226 |
221 OAuth2TokenService::Fetcher::Fetcher( | 227 OAuth2TokenService::Fetcher::Fetcher( |
222 OAuth2TokenService* oauth2_token_service, | 228 OAuth2TokenService* oauth2_token_service, |
223 const std::string& account_id, | 229 const std::string& account_id, |
224 net::URLRequestContextGetter* getter, | 230 net::URLRequestContextGetter* getter, |
225 const std::string& client_id, | 231 const std::string& client_id, |
226 const std::string& client_secret, | 232 const std::string& client_secret, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 scoped_ptr<OAuth2TokenService::Request> | 460 scoped_ptr<OAuth2TokenService::Request> |
455 OAuth2TokenService::StartRequestForClientWithContext( | 461 OAuth2TokenService::StartRequestForClientWithContext( |
456 const std::string& account_id, | 462 const std::string& account_id, |
457 net::URLRequestContextGetter* getter, | 463 net::URLRequestContextGetter* getter, |
458 const std::string& client_id, | 464 const std::string& client_id, |
459 const std::string& client_secret, | 465 const std::string& client_secret, |
460 const ScopeSet& scopes, | 466 const ScopeSet& scopes, |
461 Consumer* consumer) { | 467 Consumer* consumer) { |
462 DCHECK(CalledOnValidThread()); | 468 DCHECK(CalledOnValidThread()); |
463 | 469 |
| 470 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. |
| 471 tracked_objects::ScopedTracker tracking_profile1( |
| 472 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 473 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); |
| 474 |
464 scoped_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); | 475 scoped_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); |
465 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 476 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
466 OnAccessTokenRequested(account_id, | 477 OnAccessTokenRequested(account_id, |
467 consumer->id(), | 478 consumer->id(), |
468 scopes)); | 479 scopes)); |
469 | 480 |
470 if (!RefreshTokenIsAvailable(account_id)) { | 481 if (!RefreshTokenIsAvailable(account_id)) { |
| 482 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. |
| 483 tracked_objects::ScopedTracker tracking_profile2( |
| 484 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 485 "422460 OAuth2TokenService::StartRequestForClientWithContext 2")); |
| 486 |
471 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); | 487 GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP); |
472 | 488 |
473 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 489 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
474 OnFetchAccessTokenComplete( | 490 OnFetchAccessTokenComplete( |
475 account_id, consumer->id(), scopes, error, | 491 account_id, consumer->id(), scopes, error, |
476 base::Time())); | 492 base::Time())); |
477 | 493 |
478 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 494 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
479 &RequestImpl::InformConsumer, | 495 &RequestImpl::InformConsumer, |
480 request->AsWeakPtr(), | 496 request->AsWeakPtr(), |
481 error, | 497 error, |
482 std::string(), | 498 std::string(), |
483 base::Time())); | 499 base::Time())); |
484 return request.Pass(); | 500 return request.Pass(); |
485 } | 501 } |
486 | 502 |
487 RequestParameters request_parameters(client_id, | 503 RequestParameters request_parameters(client_id, |
488 account_id, | 504 account_id, |
489 scopes); | 505 scopes); |
490 if (HasCacheEntry(request_parameters)) { | 506 if (HasCacheEntry(request_parameters)) { |
| 507 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. |
| 508 tracked_objects::ScopedTracker tracking_profile3( |
| 509 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 510 "422460 OAuth2TokenService::StartRequestForClientWithContext 3")); |
| 511 |
491 StartCacheLookupRequest(request.get(), request_parameters, consumer); | 512 StartCacheLookupRequest(request.get(), request_parameters, consumer); |
492 } else { | 513 } else { |
493 FetchOAuth2Token(request.get(), | 514 FetchOAuth2Token(request.get(), |
494 account_id, | 515 account_id, |
495 getter, | 516 getter, |
496 client_id, | 517 client_id, |
497 client_secret, | 518 client_secret, |
498 scopes); | 519 scopes); |
499 } | 520 } |
500 return request.Pass(); | 521 return request.Pass(); |
501 } | 522 } |
502 | 523 |
503 void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request, | 524 void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request, |
504 const std::string& account_id, | 525 const std::string& account_id, |
505 net::URLRequestContextGetter* getter, | 526 net::URLRequestContextGetter* getter, |
506 const std::string& client_id, | 527 const std::string& client_id, |
507 const std::string& client_secret, | 528 const std::string& client_secret, |
508 const ScopeSet& scopes) { | 529 const ScopeSet& scopes) { |
| 530 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. |
| 531 tracked_objects::ScopedTracker tracking_profile( |
| 532 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 533 "422460 OAuth2TokenService::FetchOAuth2Token")); |
| 534 |
509 // If there is already a pending fetcher for |scopes| and |account_id|, | 535 // If there is already a pending fetcher for |scopes| and |account_id|, |
510 // simply register this |request| for those results rather than starting | 536 // simply register this |request| for those results rather than starting |
511 // a new fetcher. | 537 // a new fetcher. |
512 RequestParameters request_parameters = RequestParameters(client_id, | 538 RequestParameters request_parameters = RequestParameters(client_id, |
513 account_id, | 539 account_id, |
514 scopes); | 540 scopes); |
515 std::map<RequestParameters, Fetcher*>::iterator iter = | 541 std::map<RequestParameters, Fetcher*>::iterator iter = |
516 pending_fetchers_.find(request_parameters); | 542 pending_fetchers_.find(request_parameters); |
517 if (iter != pending_fetchers_.end()) { | 543 if (iter != pending_fetchers_.end()) { |
518 iter->second->AddWaitingRequest(request->AsWeakPtr()); | 544 iter->second->AddWaitingRequest(request->AsWeakPtr()); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 const std::string& account_id, | 835 const std::string& account_id, |
810 const ScopeSet& scopes) const { | 836 const ScopeSet& scopes) const { |
811 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 837 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
812 OAuth2TokenService::RequestParameters( | 838 OAuth2TokenService::RequestParameters( |
813 client_id, | 839 client_id, |
814 account_id, | 840 account_id, |
815 scopes)); | 841 scopes)); |
816 return iter == pending_fetchers_.end() ? | 842 return iter == pending_fetchers_.end() ? |
817 0 : iter->second->GetWaitingRequestCount(); | 843 0 : iter->second->GetWaitingRequestCount(); |
818 } | 844 } |
OLD | NEW |