1 // Copyright 2013 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/signin/signin_oauth_helper.h"
7 #include "base/message_loop/message_loop.h"
8 #include "google_apis/gaia/gaia_auth_fetcher.h"
9 #include "google_apis/gaia/gaia_constants.h"
11 SigninOAuthHelper::SigninOAuthHelper(net::URLRequestContextGetter* getter,
12 const std::string& session_index,
14 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter),
18 DCHECK(!session_index.empty());
19 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchange(session_index);
22 SigninOAuthHelper::~SigninOAuthHelper() {}
24 void SigninOAuthHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) {
25 refresh_token_ = result.refresh_token;
26 gaia_auth_fetcher_.StartOAuthLogin(result.access_token,
27 GaiaConstants::kGaiaService);
30 void SigninOAuthHelper::OnClientOAuthFailure(
31 const GoogleServiceAuthError& error) {
32 VLOG(1) << "SigninOAuthHelper::OnClientOAuthFailure: " << error.ToString();
33 consumer_->OnSigninOAuthInformationFailure(error);
36 void SigninOAuthHelper::OnClientLoginSuccess(const ClientLoginResult& result) {
37 gaia_auth_fetcher_.StartGetUserInfo(result.lsid);
40 void SigninOAuthHelper::OnClientLoginFailure(
41 const GoogleServiceAuthError& error) {
42 VLOG(1) << "SigninOAuthHelper::OnClientLoginFailure: " << error.ToString();
43 consumer_->OnSigninOAuthInformationFailure(error);
46 void SigninOAuthHelper::OnGetUserInfoSuccess(const UserInfoMap& data) {
47 UserInfoMap::const_iterator email_iter = data.find("email");
48 UserInfoMap::const_iterator display_email_iter = data.find("displayEmail");
49 if (email_iter == data.end() || display_email_iter == data.end()) {
50 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess: no email found:"
51 << " email=" << email_iter->second
52 << " displayEmail=" << display_email_iter->second;
53 consumer_->OnSigninOAuthInformationFailure(
54 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
56 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess:"
57 << " email=" << email_iter->second
58 << " displayEmail=" << display_email_iter->second;
59 consumer_->OnSigninOAuthInformationAvailable(email_iter->second,
60 display_email_iter->second,
65 void SigninOAuthHelper::OnGetUserInfoFailure(
66 const GoogleServiceAuthError& error) {
67 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoFailure : " << error.ToString();
68 consumer_->OnSigninOAuthInformationFailure(error);