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.
5 #include "chrome/browser/chromeos/login/signin/oauth2_token_initializer.h"
7 #include "chrome/browser/browser_process.h"
11 OAuth2TokenInitializer::OAuth2TokenInitializer() {
14 OAuth2TokenInitializer::~OAuth2TokenInitializer() {
17 void OAuth2TokenInitializer::Start(const UserContext
& user_context
,
18 const FetchOAuth2TokensCallback
& callback
) {
19 DCHECK(!user_context
.GetAuthCode().empty());
21 user_context_
= user_context
;
22 oauth2_token_fetcher_
.reset(new OAuth2TokenFetcher(
23 this, g_browser_process
->system_request_context()));
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());
30 void OAuth2TokenInitializer::OnOAuth2TokensAvailable(
31 const GaiaAuthConsumer::ClientOAuthResult
& oauth2_tokens
) {
32 VLOG(1) << "OAuth2 tokens fetched";
33 user_context_
.SetAuthCode(std::string());
34 user_context_
.SetRefreshToken(oauth2_tokens
.refresh_token
);
35 user_context_
.SetAccessToken(oauth2_tokens
.access_token
);
36 callback_
.Run(true, user_context_
);
39 void OAuth2TokenInitializer::OnOAuth2TokensFetchFailed() {
40 LOG(WARNING
) << "OAuth2TokenInitializer - OAuth2 token fetch failed";
41 callback_
.Run(false, user_context_
);
44 } // namespace chromeos