| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/signin/signin_oauth_helper.h" | 5 #include "components/signin/core/browser/signin_oauth_helper.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "google_apis/gaia/gaia_auth_fetcher.h" | 8 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 9 #include "google_apis/gaia/gaia_constants.h" | 9 #include "google_apis/gaia/gaia_constants.h" |
| 10 | 10 |
| 11 SigninOAuthHelper::SigninOAuthHelper(net::URLRequestContextGetter* getter, | 11 SigninOAuthHelper::SigninOAuthHelper(net::URLRequestContextGetter* getter, |
| 12 const std::string& session_index, | 12 const std::string& session_index, |
| 13 Consumer* consumer) | 13 Consumer* consumer) |
| 14 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), | 14 : gaia_auth_fetcher_(this, GaiaConstants::kChromeSource, getter), |
| 15 consumer_(consumer) { | 15 consumer_(consumer) { |
| 16 DCHECK(consumer_); | 16 DCHECK(consumer_); |
| 17 DCHECK(getter); | 17 DCHECK(getter); |
| 18 DCHECK(!session_index.empty()); | 18 DCHECK(!session_index.empty()); |
| 19 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchange(session_index); | 19 gaia_auth_fetcher_.StartCookieForOAuthLoginTokenExchange(session_index); |
| 20 } | 20 } |
| 21 | 21 |
| 22 SigninOAuthHelper::~SigninOAuthHelper() {} | 22 SigninOAuthHelper::~SigninOAuthHelper() {} |
| 23 | 23 |
| 24 void SigninOAuthHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { | 24 void SigninOAuthHelper::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
| 25 refresh_token_ = result.refresh_token; | 25 refresh_token_ = result.refresh_token; |
| 26 gaia_auth_fetcher_.StartOAuthLogin(result.access_token, | 26 gaia_auth_fetcher_.StartOAuthLogin(result.access_token, |
| 27 GaiaConstants::kGaiaService); | 27 GaiaConstants::kGaiaService); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void SigninOAuthHelper::OnClientOAuthFailure( | 30 void SigninOAuthHelper::OnClientOAuthFailure( |
| 31 const GoogleServiceAuthError& error) { | 31 const GoogleServiceAuthError& error) { |
| 32 VLOG(1) << "SigninOAuthHelper::OnClientOAuthFailure: " << error.ToString(); | 32 VLOG(1) << "SigninOAuthHelper::OnClientOAuthFailure: " << error.ToString(); |
| 33 consumer_->OnSigninOAuthInformationFailure(error); | 33 consumer_->OnSigninOAuthInformationFailure(error); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void SigninOAuthHelper::OnClientLoginSuccess(const ClientLoginResult& result) { | 36 void SigninOAuthHelper::OnClientLoginSuccess(const ClientLoginResult& result) { |
| 37 gaia_auth_fetcher_.StartGetUserInfo(result.lsid); | 37 gaia_auth_fetcher_.StartGetUserInfo(result.lsid); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SigninOAuthHelper::OnClientLoginFailure( | 40 void SigninOAuthHelper::OnClientLoginFailure( |
| 41 const GoogleServiceAuthError& error) { | 41 const GoogleServiceAuthError& error) { |
| 42 VLOG(1) << "SigninOAuthHelper::OnClientLoginFailure: " << error.ToString(); | 42 VLOG(1) << "SigninOAuthHelper::OnClientLoginFailure: " << error.ToString(); |
| 43 consumer_->OnSigninOAuthInformationFailure(error); | 43 consumer_->OnSigninOAuthInformationFailure(error); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SigninOAuthHelper::OnGetUserInfoSuccess(const UserInfoMap& data) { | 46 void SigninOAuthHelper::OnGetUserInfoSuccess(const UserInfoMap& data) { |
| 47 UserInfoMap::const_iterator email_iter = data.find("email"); | 47 UserInfoMap::const_iterator email_iter = data.find("email"); |
| 48 UserInfoMap::const_iterator display_email_iter = data.find("displayEmail"); | 48 UserInfoMap::const_iterator display_email_iter = data.find("displayEmail"); |
| 49 if (email_iter == data.end() || display_email_iter == data.end()) { | 49 if (email_iter == data.end() || display_email_iter == data.end()) { |
| 50 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess: no email found:" | 50 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess: no email found:" |
| 51 << " email=" << email_iter->second | 51 << " email=" << email_iter->second |
| 52 << " displayEmail=" << display_email_iter->second; | 52 << " displayEmail=" << display_email_iter->second; |
| 53 consumer_->OnSigninOAuthInformationFailure( | 53 consumer_->OnSigninOAuthInformationFailure( |
| 54 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); | 54 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); |
| 55 } else { | 55 } else { |
| 56 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess:" | 56 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoSuccess:" |
| 57 << " email=" << email_iter->second | 57 << " email=" << email_iter->second |
| 58 << " displayEmail=" << display_email_iter->second; | 58 << " displayEmail=" << display_email_iter->second; |
| 59 consumer_->OnSigninOAuthInformationAvailable(email_iter->second, | 59 consumer_->OnSigninOAuthInformationAvailable( |
| 60 display_email_iter->second, | 60 email_iter->second, display_email_iter->second, refresh_token_); |
| 61 refresh_token_); | |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 | 63 |
| 65 void SigninOAuthHelper::OnGetUserInfoFailure( | 64 void SigninOAuthHelper::OnGetUserInfoFailure( |
| 66 const GoogleServiceAuthError& error) { | 65 const GoogleServiceAuthError& error) { |
| 67 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoFailure : " << error.ToString(); | 66 VLOG(1) << "SigninOAuthHelper::OnGetUserInfoFailure : " << error.ToString(); |
| 68 consumer_->OnSigninOAuthInformationFailure(error); | 67 consumer_->OnSigninOAuthInformationFailure(error); |
| 69 } | 68 } |
| OLD | NEW |