Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: google_apis/gaia/fake_oauth2_token_service_delegate.cc

Issue 1267843003: Fix reconcilor loop when the primary account is in an auth error state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "google_apis/gaia/fake_oauth2_token_service_delegate.h" 5 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
6 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" 6 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
7 7
8 FakeOAuth2TokenServiceDelegate::AccountInfo::AccountInfo(
9 const std::string& refresh_token)
10 : refresh_token(refresh_token),
11 error(GoogleServiceAuthError::NONE) {}
12
8 FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate( 13 FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate(
9 net::URLRequestContextGetter* request_context) 14 net::URLRequestContextGetter* request_context)
10 : request_context_(request_context) { 15 : request_context_(request_context) {
11 } 16 }
12 17
13 FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() { 18 FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() {
14 } 19 }
15 20
16 OAuth2AccessTokenFetcher* 21 OAuth2AccessTokenFetcher*
17 FakeOAuth2TokenServiceDelegate::CreateAccessTokenFetcher( 22 FakeOAuth2TokenServiceDelegate::CreateAccessTokenFetcher(
18 const std::string& account_id, 23 const std::string& account_id,
19 net::URLRequestContextGetter* getter, 24 net::URLRequestContextGetter* getter,
20 OAuth2AccessTokenConsumer* consumer) { 25 OAuth2AccessTokenConsumer* consumer) {
21 std::map<std::string, std::string>::const_iterator it = 26 AccountInfoMap::const_iterator it = refresh_tokens_.find(account_id);
22 refresh_tokens_.find(account_id);
23 DCHECK(it != refresh_tokens_.end()); 27 DCHECK(it != refresh_tokens_.end());
24 std::string refresh_token(it->second); 28 return new OAuth2AccessTokenFetcherImpl(consumer, getter,
25 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token); 29 it->second->refresh_token);
26 } 30 }
27 31
28 bool FakeOAuth2TokenServiceDelegate::RefreshTokenIsAvailable( 32 bool FakeOAuth2TokenServiceDelegate::RefreshTokenIsAvailable(
29 const std::string& account_id) const { 33 const std::string& account_id) const {
30 return !GetRefreshToken(account_id).empty(); 34 return !GetRefreshToken(account_id).empty();
31 } 35 }
32 36
37 bool FakeOAuth2TokenServiceDelegate::RefreshTokenHasError(
38 const std::string& account_id) const {
39 auto it = refresh_tokens_.find(account_id);
40 // TODO(rogerta): should we distinguish between transient and persistent?
41 return it == refresh_tokens_.end()
42 ? false
43 : it->second->error.state() != GoogleServiceAuthError::NONE;
44 }
45
33 std::string FakeOAuth2TokenServiceDelegate::GetRefreshToken( 46 std::string FakeOAuth2TokenServiceDelegate::GetRefreshToken(
34 const std::string& account_id) const { 47 const std::string& account_id) const {
35 std::map<std::string, std::string>::const_iterator it = 48 AccountInfoMap::const_iterator it = refresh_tokens_.find(account_id);
36 refresh_tokens_.find(account_id);
37 if (it != refresh_tokens_.end()) 49 if (it != refresh_tokens_.end())
38 return it->second; 50 return it->second->refresh_token;
39 return std::string(); 51 return std::string();
40 } 52 }
41 53
42 std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() { 54 std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
43 std::vector<std::string> account_ids; 55 std::vector<std::string> account_ids;
44 for (std::map<std::string, std::string>::const_iterator iter = 56 for (AccountInfoMap::const_iterator iter = refresh_tokens_.begin();
45 refresh_tokens_.begin();
46 iter != refresh_tokens_.end(); ++iter) { 57 iter != refresh_tokens_.end(); ++iter) {
47 account_ids.push_back(iter->first); 58 account_ids.push_back(iter->first);
48 } 59 }
49 return account_ids; 60 return account_ids;
50 } 61 }
51 62
52 void FakeOAuth2TokenServiceDelegate::RevokeAllCredentials() { 63 void FakeOAuth2TokenServiceDelegate::RevokeAllCredentials() {
53 std::vector<std::string> account_ids = GetAccounts(); 64 std::vector<std::string> account_ids = GetAccounts();
54 for (std::vector<std::string>::const_iterator it = account_ids.begin(); 65 for (std::vector<std::string>::const_iterator it = account_ids.begin();
55 it != account_ids.end(); it++) { 66 it != account_ids.end(); it++) {
(...skipping 13 matching lines...) Expand all
69 } 80 }
70 81
71 void FakeOAuth2TokenServiceDelegate::IssueRefreshTokenForUser( 82 void FakeOAuth2TokenServiceDelegate::IssueRefreshTokenForUser(
72 const std::string& account_id, 83 const std::string& account_id,
73 const std::string& token) { 84 const std::string& token) {
74 ScopedBatchChange batch(this); 85 ScopedBatchChange batch(this);
75 if (token.empty()) { 86 if (token.empty()) {
76 refresh_tokens_.erase(account_id); 87 refresh_tokens_.erase(account_id);
77 FireRefreshTokenRevoked(account_id); 88 FireRefreshTokenRevoked(account_id);
78 } else { 89 } else {
79 refresh_tokens_[account_id] = token; 90 refresh_tokens_[account_id].reset(new AccountInfo(token));
80 FireRefreshTokenAvailable(account_id); 91 FireRefreshTokenAvailable(account_id);
81 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? 92 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
82 } 93 }
83 } 94 }
84 95
85 void FakeOAuth2TokenServiceDelegate::RevokeCredentials( 96 void FakeOAuth2TokenServiceDelegate::RevokeCredentials(
86 const std::string& account_id) { 97 const std::string& account_id) {
87 IssueRefreshTokenForUser(account_id, std::string()); 98 IssueRefreshTokenForUser(account_id, std::string());
88 } 99 }
89 100
90 net::URLRequestContextGetter* 101 net::URLRequestContextGetter*
91 FakeOAuth2TokenServiceDelegate::GetRequestContext() const { 102 FakeOAuth2TokenServiceDelegate::GetRequestContext() const {
92 return request_context_.get(); 103 return request_context_.get();
93 } 104 }
105
106 void FakeOAuth2TokenServiceDelegate::SetLastErrorForAccount(
107 const std::string& account_id,
108 const GoogleServiceAuthError& error) {
109 auto it = refresh_tokens_.find(account_id);
110 DCHECK(it != refresh_tokens_.end());
111 it->second->error = error;
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698