| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // scheduled for deletion at the end of OnGetTokenFailure/OnGetTokenSuccess | 172 // scheduled for deletion at the end of OnGetTokenFailure/OnGetTokenSuccess |
| 173 // (whichever comes first). | 173 // (whichever comes first). |
| 174 OAuth2TokenService* const oauth2_token_service_; | 174 OAuth2TokenService* const oauth2_token_service_; |
| 175 scoped_refptr<net::URLRequestContextGetter> getter_; | 175 scoped_refptr<net::URLRequestContextGetter> getter_; |
| 176 const std::string account_id_; | 176 const std::string account_id_; |
| 177 const ScopeSet scopes_; | 177 const ScopeSet scopes_; |
| 178 std::vector<base::WeakPtr<RequestImpl> > waiting_requests_; | 178 std::vector<base::WeakPtr<RequestImpl> > waiting_requests_; |
| 179 | 179 |
| 180 int retry_number_; | 180 int retry_number_; |
| 181 base::OneShotTimer retry_timer_; | 181 base::OneShotTimer retry_timer_; |
| 182 scoped_ptr<OAuth2AccessTokenFetcher> fetcher_; | 182 std::unique_ptr<OAuth2AccessTokenFetcher> fetcher_; |
| 183 | 183 |
| 184 // Variables that store fetch results. | 184 // Variables that store fetch results. |
| 185 // Initialized to be GoogleServiceAuthError::SERVICE_UNAVAILABLE to handle | 185 // Initialized to be GoogleServiceAuthError::SERVICE_UNAVAILABLE to handle |
| 186 // destruction. | 186 // destruction. |
| 187 GoogleServiceAuthError error_; | 187 GoogleServiceAuthError error_; |
| 188 std::string access_token_; | 188 std::string access_token_; |
| 189 base::Time expiration_date_; | 189 base::Time expiration_date_; |
| 190 | 190 |
| 191 // OAuth2 client id and secret. | 191 // OAuth2 client id and secret. |
| 192 std::string client_id_; | 192 std::string client_id_; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 414 |
| 415 void OAuth2TokenService::AddDiagnosticsObserver(DiagnosticsObserver* observer) { | 415 void OAuth2TokenService::AddDiagnosticsObserver(DiagnosticsObserver* observer) { |
| 416 diagnostics_observer_list_.AddObserver(observer); | 416 diagnostics_observer_list_.AddObserver(observer); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void OAuth2TokenService::RemoveDiagnosticsObserver( | 419 void OAuth2TokenService::RemoveDiagnosticsObserver( |
| 420 DiagnosticsObserver* observer) { | 420 DiagnosticsObserver* observer) { |
| 421 diagnostics_observer_list_.RemoveObserver(observer); | 421 diagnostics_observer_list_.RemoveObserver(observer); |
| 422 } | 422 } |
| 423 | 423 |
| 424 scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( | 424 std::unique_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( |
| 425 const std::string& account_id, | 425 const std::string& account_id, |
| 426 const OAuth2TokenService::ScopeSet& scopes, | 426 const OAuth2TokenService::ScopeSet& scopes, |
| 427 OAuth2TokenService::Consumer* consumer) { | 427 OAuth2TokenService::Consumer* consumer) { |
| 428 return StartRequestForClientWithContext( | 428 return StartRequestForClientWithContext( |
| 429 account_id, | 429 account_id, |
| 430 GetRequestContext(), | 430 GetRequestContext(), |
| 431 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 431 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| 432 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 432 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
| 433 scopes, | 433 scopes, |
| 434 consumer); | 434 consumer); |
| 435 } | 435 } |
| 436 | 436 |
| 437 scoped_ptr<OAuth2TokenService::Request> | 437 std::unique_ptr<OAuth2TokenService::Request> |
| 438 OAuth2TokenService::StartRequestForClient( | 438 OAuth2TokenService::StartRequestForClient( |
| 439 const std::string& account_id, | 439 const std::string& account_id, |
| 440 const std::string& client_id, | 440 const std::string& client_id, |
| 441 const std::string& client_secret, | 441 const std::string& client_secret, |
| 442 const OAuth2TokenService::ScopeSet& scopes, | 442 const OAuth2TokenService::ScopeSet& scopes, |
| 443 OAuth2TokenService::Consumer* consumer) { | 443 OAuth2TokenService::Consumer* consumer) { |
| 444 return StartRequestForClientWithContext( | 444 return StartRequestForClientWithContext( |
| 445 account_id, | 445 account_id, |
| 446 GetRequestContext(), | 446 GetRequestContext(), |
| 447 client_id, | 447 client_id, |
| 448 client_secret, | 448 client_secret, |
| 449 scopes, | 449 scopes, |
| 450 consumer); | 450 consumer); |
| 451 } | 451 } |
| 452 | 452 |
| 453 net::URLRequestContextGetter* OAuth2TokenService::GetRequestContext() const { | 453 net::URLRequestContextGetter* OAuth2TokenService::GetRequestContext() const { |
| 454 return delegate_->GetRequestContext(); | 454 return delegate_->GetRequestContext(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 scoped_ptr<OAuth2TokenService::Request> | 457 std::unique_ptr<OAuth2TokenService::Request> |
| 458 OAuth2TokenService::StartRequestWithContext( | 458 OAuth2TokenService::StartRequestWithContext( |
| 459 const std::string& account_id, | 459 const std::string& account_id, |
| 460 net::URLRequestContextGetter* getter, | 460 net::URLRequestContextGetter* getter, |
| 461 const ScopeSet& scopes, | 461 const ScopeSet& scopes, |
| 462 Consumer* consumer) { | 462 Consumer* consumer) { |
| 463 return StartRequestForClientWithContext( | 463 return StartRequestForClientWithContext( |
| 464 account_id, | 464 account_id, |
| 465 getter, | 465 getter, |
| 466 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 466 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| 467 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 467 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
| 468 scopes, | 468 scopes, |
| 469 consumer); | 469 consumer); |
| 470 } | 470 } |
| 471 | 471 |
| 472 scoped_ptr<OAuth2TokenService::Request> | 472 std::unique_ptr<OAuth2TokenService::Request> |
| 473 OAuth2TokenService::StartRequestForClientWithContext( | 473 OAuth2TokenService::StartRequestForClientWithContext( |
| 474 const std::string& account_id, | 474 const std::string& account_id, |
| 475 net::URLRequestContextGetter* getter, | 475 net::URLRequestContextGetter* getter, |
| 476 const std::string& client_id, | 476 const std::string& client_id, |
| 477 const std::string& client_secret, | 477 const std::string& client_secret, |
| 478 const ScopeSet& scopes, | 478 const ScopeSet& scopes, |
| 479 Consumer* consumer) { | 479 Consumer* consumer) { |
| 480 DCHECK(CalledOnValidThread()); | 480 DCHECK(CalledOnValidThread()); |
| 481 | 481 |
| 482 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 482 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 483 // fixed. | 483 // fixed. |
| 484 tracked_objects::ScopedTracker tracking_profile1( | 484 tracked_objects::ScopedTracker tracking_profile1( |
| 485 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 485 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 486 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); | 486 "422460 OAuth2TokenService::StartRequestForClientWithContext 1")); |
| 487 scoped_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); | 487 std::unique_ptr<RequestImpl> request(new RequestImpl(account_id, consumer)); |
| 488 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, | 488 FOR_EACH_OBSERVER(DiagnosticsObserver, diagnostics_observer_list_, |
| 489 OnAccessTokenRequested(account_id, | 489 OnAccessTokenRequested(account_id, |
| 490 consumer->id(), | 490 consumer->id(), |
| 491 scopes)); | 491 scopes)); |
| 492 | 492 |
| 493 if (!RefreshTokenIsAvailable(account_id)) { | 493 if (!RefreshTokenIsAvailable(account_id)) { |
| 494 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 | 494 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 |
| 495 // is fixed. | 495 // is fixed. |
| 496 tracked_objects::ScopedTracker tracking_profile2( | 496 tracked_objects::ScopedTracker tracking_profile2( |
| 497 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 497 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 const std::string& account_id, | 828 const std::string& account_id, |
| 829 const ScopeSet& scopes) const { | 829 const ScopeSet& scopes) const { |
| 830 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 830 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
| 831 OAuth2TokenService::RequestParameters( | 831 OAuth2TokenService::RequestParameters( |
| 832 client_id, | 832 client_id, |
| 833 account_id, | 833 account_id, |
| 834 scopes)); | 834 scopes)); |
| 835 return iter == pending_fetchers_.end() ? | 835 return iter == pending_fetchers_.end() ? |
| 836 0 : iter->second->GetWaitingRequestCount(); | 836 0 : iter->second->GetWaitingRequestCount(); |
| 837 } | 837 } |
| OLD | NEW |