| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/ubertoken_fetcher.h" | 5 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service.h" | |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 13 #include "google_apis/gaia/gaia_auth_fetcher.h" | 10 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 14 #include "google_apis/gaia/gaia_constants.h" | 11 #include "google_apis/gaia/gaia_constants.h" |
| 15 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
| 16 #include "google_apis/gaia/google_service_auth_error.h" | 13 #include "google_apis/gaia/google_service_auth_error.h" |
| 17 #include "google_apis/gaia/oauth2_token_service.h" | 14 #include "google_apis/gaia/oauth2_token_service.h" |
| 18 | 15 |
| 19 UbertokenFetcher::UbertokenFetcher(Profile* profile, | 16 UbertokenFetcher::UbertokenFetcher( |
| 20 UbertokenConsumer* consumer) | 17 OAuth2TokenService* token_service, |
| 18 UbertokenConsumer* consumer, |
| 19 net::URLRequestContextGetter* request_context) |
| 21 : OAuth2TokenService::Consumer("uber_token_fetcher"), | 20 : OAuth2TokenService::Consumer("uber_token_fetcher"), |
| 22 profile_(profile), consumer_(consumer) { | 21 token_service_(token_service), |
| 23 DCHECK(profile); | 22 consumer_(consumer), |
| 23 request_context_(request_context) { |
| 24 DCHECK(token_service); |
| 24 DCHECK(consumer); | 25 DCHECK(consumer); |
| 26 DCHECK(request_context); |
| 25 } | 27 } |
| 26 | 28 |
| 27 UbertokenFetcher::~UbertokenFetcher() { | 29 UbertokenFetcher::~UbertokenFetcher() { |
| 28 } | 30 } |
| 29 | 31 |
| 30 void UbertokenFetcher::StartFetchingToken(const std::string& account_id) { | 32 void UbertokenFetcher::StartFetchingToken(const std::string& account_id) { |
| 31 OAuth2TokenService::ScopeSet scopes; | 33 OAuth2TokenService::ScopeSet scopes; |
| 32 scopes.insert(GaiaUrls::GetInstance()->oauth1_login_scope()); | 34 scopes.insert(GaiaUrls::GetInstance()->oauth1_login_scope()); |
| 33 OAuth2TokenService* token_service = | 35 access_token_request_ = |
| 34 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 36 token_service_->StartRequest(account_id, scopes, this); |
| 35 access_token_request_ = token_service->StartRequest(account_id, scopes, this); | |
| 36 } | 37 } |
| 37 | 38 |
| 38 void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) { | 39 void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) { |
| 39 consumer_->OnUbertokenSuccess(token); | 40 consumer_->OnUbertokenSuccess(token); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void UbertokenFetcher::OnUberAuthTokenFailure( | 43 void UbertokenFetcher::OnUberAuthTokenFailure( |
| 43 const GoogleServiceAuthError& error) { | 44 const GoogleServiceAuthError& error) { |
| 44 consumer_->OnUbertokenFailure(error); | 45 consumer_->OnUbertokenFailure(error); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void UbertokenFetcher::OnGetTokenSuccess( | 48 void UbertokenFetcher::OnGetTokenSuccess( |
| 48 const OAuth2TokenService::Request* request, | 49 const OAuth2TokenService::Request* request, |
| 49 const std::string& access_token, | 50 const std::string& access_token, |
| 50 const base::Time& expiration_time) { | 51 const base::Time& expiration_time) { |
| 51 access_token_request_.reset(); | 52 access_token_request_.reset(); |
| 52 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this, | 53 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this, |
| 53 GaiaConstants::kChromeSource, | 54 GaiaConstants::kChromeSource, |
| 54 profile_->GetRequestContext())); | 55 request_context_)); |
| 55 gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token); | 56 gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void UbertokenFetcher::OnGetTokenFailure( | 59 void UbertokenFetcher::OnGetTokenFailure( |
| 59 const OAuth2TokenService::Request* request, | 60 const OAuth2TokenService::Request* request, |
| 60 const GoogleServiceAuthError& error) { | 61 const GoogleServiceAuthError& error) { |
| 61 access_token_request_.reset(); | 62 access_token_request_.reset(); |
| 62 consumer_->OnUbertokenFailure(error); | 63 consumer_->OnUbertokenFailure(error); |
| 63 } | 64 } |
| OLD | NEW |