OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "chrome/browser/chromeos/login/signin/oauth2_token_initializer.h" |
| 6 |
| 7 #include "chrome/browser/browser_process.h" |
| 8 |
| 9 namespace chromeos { |
| 10 |
| 11 OAuth2TokenInitializer::OAuth2TokenInitializer() { |
| 12 } |
| 13 |
| 14 OAuth2TokenInitializer::~OAuth2TokenInitializer() { |
| 15 } |
| 16 |
| 17 void OAuth2TokenInitializer::Start(const UserContext& user_context, |
| 18 const FetchOAuth2TokensCallback& callback) { |
| 19 DCHECK(!user_context.GetAuthCode().empty()); |
| 20 callback_ = callback; |
| 21 user_context_ = user_context; |
| 22 oauth2_token_fetcher_.reset(new OAuth2TokenFetcher( |
| 23 this, g_browser_process->system_request_context())); |
| 24 oauth2_token_fetcher_->StartExchangeFromAuthCode(user_context.GetAuthCode()); |
| 25 } |
| 26 |
| 27 void OAuth2TokenInitializer::OnOAuth2TokensAvailable( |
| 28 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { |
| 29 VLOG(1) << "OAuth2 tokens fetched"; |
| 30 user_context_.SetAuthCode(std::string()); |
| 31 user_context_.SetRefreshToken(oauth2_tokens.refresh_token); |
| 32 user_context_.SetAccessToken(oauth2_tokens.access_token); |
| 33 callback_.Run(true, user_context_); |
| 34 } |
| 35 |
| 36 void OAuth2TokenInitializer::OnOAuth2TokensFetchFailed() { |
| 37 LOG(WARNING) << "OAuth2TokenInitializer - OAuth2 token fetch failed"; |
| 38 callback_.Run(false, user_context_); |
| 39 } |
| 40 |
| 41 } // namespace chromeos |
OLD | NEW |