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