1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "google_apis/gaia/ubertoken_fetcher.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "google_apis/gaia/gaia_auth_fetcher.h"
11 #include "google_apis/gaia/gaia_constants.h"
12 #include "google_apis/gaia/google_service_auth_error.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
14
UbertokenFetcher(OAuth2TokenService * token_service,UbertokenConsumer * consumer,net::URLRequestContextGetter * request_context)15 UbertokenFetcher::UbertokenFetcher(
16 OAuth2TokenService* token_service,
17 UbertokenConsumer* consumer,
18 net::URLRequestContextGetter* request_context)
19 : OAuth2TokenService::Consumer("uber_token_fetcher"),
20 token_service_(token_service),
21 consumer_(consumer),
22 request_context_(request_context) {
23 DCHECK(token_service);
24 DCHECK(consumer);
25 DCHECK(request_context);
26 }
27
~UbertokenFetcher()28 UbertokenFetcher::~UbertokenFetcher() {
29 }
30
StartFetchingToken(const std::string & account_id)31 void UbertokenFetcher::StartFetchingToken(const std::string& account_id) {
32 OAuth2TokenService::ScopeSet scopes;
33 scopes.insert(GaiaConstants::kOAuth1LoginScope);
34 access_token_request_ =
35 token_service_->StartRequest(account_id, scopes, this);
36 }
37
OnUberAuthTokenSuccess(const std::string & token)38 void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) {
39 consumer_->OnUbertokenSuccess(token);
40 }
41
OnUberAuthTokenFailure(const GoogleServiceAuthError & error)42 void UbertokenFetcher::OnUberAuthTokenFailure(
43 const GoogleServiceAuthError& error) {
44 consumer_->OnUbertokenFailure(error);
45 }
46
OnGetTokenSuccess(const OAuth2TokenService::Request * request,const std::string & access_token,const base::Time & expiration_time)47 void UbertokenFetcher::OnGetTokenSuccess(
48 const OAuth2TokenService::Request* request,
49 const std::string& access_token,
50 const base::Time& expiration_time) {
51 access_token_request_.reset();
52 gaia_auth_fetcher_.reset(new GaiaAuthFetcher(this,
53 GaiaConstants::kChromeSource,
54 request_context_));
55 gaia_auth_fetcher_->StartTokenFetchForUberAuthExchange(access_token);
56 }
57
OnGetTokenFailure(const OAuth2TokenService::Request * request,const GoogleServiceAuthError & error)58 void UbertokenFetcher::OnGetTokenFailure(
59 const OAuth2TokenService::Request* request,
60 const GoogleServiceAuthError& error) {
61 access_token_request_.reset();
62 consumer_->OnUbertokenFailure(error);
63 }
64