Enable SigninAllowed policy on Android and plumb it through to SigninManager
[chromium-blink-merge.git] / google_apis / gaia / ubertoken_fetcher.cc
blobda0ff27c14c1dd9943f2e15b0610514e49bc81ce
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.
5 #include "google_apis/gaia/ubertoken_fetcher.h"
7 #include <vector>
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"
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);
28 UbertokenFetcher::~UbertokenFetcher() {
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);
38 void UbertokenFetcher::OnUberAuthTokenSuccess(const std::string& token) {
39 consumer_->OnUbertokenSuccess(token);
42 void UbertokenFetcher::OnUberAuthTokenFailure(
43 const GoogleServiceAuthError& error) {
44 consumer_->OnUbertokenFailure(error);
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);
58 void UbertokenFetcher::OnGetTokenFailure(
59 const OAuth2TokenService::Request* request,
60 const GoogleServiceAuthError& error) {
61 access_token_request_.reset();
62 consumer_->OnUbertokenFailure(error);