1 // Copyright 2014 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_login_verifier.h"
9 #include "base/logging.h"
10 #include "content/public/browser/browser_thread.h"
12 using content::BrowserThread
;
16 OAuth2LoginVerifier::OAuth2LoginVerifier(
17 OAuth2LoginVerifier::Delegate
* delegate
,
18 GaiaCookieManagerService
* cookie_manager_service
,
19 const std::string
& primary_account_id
,
20 const std::string
& oauthlogin_access_token
)
21 : delegate_(delegate
),
22 cookie_manager_service_(cookie_manager_service
),
23 primary_account_id_(primary_account_id
),
24 access_token_(oauthlogin_access_token
) {
26 cookie_manager_service_
->AddObserver(this);
29 OAuth2LoginVerifier::~OAuth2LoginVerifier() {
30 cookie_manager_service_
->RemoveObserver(this);
33 void OAuth2LoginVerifier::VerifyUserCookies() {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
36 std::vector
<gaia::ListedAccount
> accounts
;
37 if (cookie_manager_service_
->ListAccounts(&accounts
)) {
38 OnGaiaAccountsInCookieUpdated(
39 accounts
, GoogleServiceAuthError(GoogleServiceAuthError::NONE
));
43 void OAuth2LoginVerifier::VerifyProfileTokens() {
44 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
45 if (access_token_
.empty()) {
46 cookie_manager_service_
->AddAccountToCookie(primary_account_id_
);
48 cookie_manager_service_
->AddAccountToCookieWithToken(primary_account_id_
,
53 void OAuth2LoginVerifier::OnAddAccountToCookieCompleted(
54 const std::string
& account_id
,
55 const GoogleServiceAuthError
& error
) {
56 if (account_id
!= primary_account_id_
)
59 if (error
.state() == GoogleServiceAuthError::State::NONE
) {
60 VLOG(1) << "MergeSession successful.";
61 delegate_
->OnSessionMergeSuccess();
65 LOG(WARNING
) << "Failed MergeSession request,"
66 << " error: " << error
.state();
67 delegate_
->OnSessionMergeFailure(error
.IsTransientError());
70 void OAuth2LoginVerifier::OnGaiaAccountsInCookieUpdated(
71 const std::vector
<gaia::ListedAccount
>& accounts
,
72 const GoogleServiceAuthError
& error
) {
73 if (error
.state() == GoogleServiceAuthError::State::NONE
) {
74 VLOG(1) << "ListAccounts successful.";
75 delegate_
->OnListAccountsSuccess(accounts
);
79 LOG(WARNING
) << "Failed to get list of session accounts, "
80 << " error: " << error
.state();
81 delegate_
->OnListAccountsFailure(error
.IsTransientError());
84 } // namespace chromeos