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

Side by Side Diff: chrome/browser/signin/fake_profile_oauth2_token_service.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address roger's comments Created 5 years, 6 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 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/fake_profile_oauth2_token_service.h" 5 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
9 10
10 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() { 11 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() {
11 } 12 }
12 13
13 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() { 14 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() {
14 } 15 }
15 16
16 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() 17 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService()
17 : auto_post_fetch_response_on_message_loop_(false), 18 : ProfileOAuth2TokenService(new FakeOAuth2TokenServiceDelegate(nullptr)),
19 auto_post_fetch_response_on_message_loop_(false),
18 weak_ptr_factory_(this) { 20 weak_ptr_factory_(this) {
19 } 21 }
20 22
21 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { 23 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() {
22 } 24 }
23 25
24 bool FakeProfileOAuth2TokenService::RefreshTokenIsAvailable(
25 const std::string& account_id) const {
26 return !GetRefreshToken(account_id).empty();
27 }
28
29 void FakeProfileOAuth2TokenService::LoadCredentials(
30 const std::string& primary_account_id) {
31 // Empty implementation as FakeProfileOAuth2TokenService does not have any
32 // credentials to load.
33 }
34
35 std::vector<std::string> FakeProfileOAuth2TokenService::GetAccounts() {
36 std::vector<std::string> account_ids;
37 for (std::map<std::string, std::string>::const_iterator iter =
38 refresh_tokens_.begin(); iter != refresh_tokens_.end(); ++iter) {
39 account_ids.push_back(iter->first);
40 }
41 return account_ids;
42 }
43
44 void FakeProfileOAuth2TokenService::UpdateCredentials(
45 const std::string& account_id,
46 const std::string& refresh_token) {
47 IssueRefreshTokenForUser(account_id, refresh_token);
48 }
49
50 void FakeProfileOAuth2TokenService::IssueRefreshToken(
51 const std::string& token) {
52 IssueRefreshTokenForUser("account_id", token);
53 }
54
55 void FakeProfileOAuth2TokenService::IssueRefreshTokenForUser(
56 const std::string& account_id,
57 const std::string& token) {
58 ScopedBatchChange batch(this);
59 if (token.empty()) {
60 refresh_tokens_.erase(account_id);
61 FireRefreshTokenRevoked(account_id);
62 } else {
63 refresh_tokens_[account_id] = token;
64 FireRefreshTokenAvailable(account_id);
65 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
66 }
67 }
68
69 void FakeProfileOAuth2TokenService::IssueAllRefreshTokensLoaded() {
70 FireRefreshTokensLoaded();
71 }
72
73 void FakeProfileOAuth2TokenService::IssueAllTokensForAccount( 26 void FakeProfileOAuth2TokenService::IssueAllTokensForAccount(
74 const std::string& account_id, 27 const std::string& account_id,
75 const std::string& access_token, 28 const std::string& access_token,
76 const base::Time& expiration) { 29 const base::Time& expiration) {
77 CompleteRequests(account_id, 30 CompleteRequests(account_id,
78 true, 31 true,
79 ScopeSet(), 32 ScopeSet(),
80 GoogleServiceAuthError::AuthErrorNone(), 33 GoogleServiceAuthError::AuthErrorNone(),
81 access_token, 34 access_token,
82 expiration); 35 expiration);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 it != requests.end(); ++it) { 95 it != requests.end(); ++it) {
143 DCHECK(it->request); 96 DCHECK(it->request);
144 97
145 bool scope_matches = all_scopes || it->scopes == scope; 98 bool scope_matches = all_scopes || it->scopes == scope;
146 bool account_matches = account_id.empty() || account_id == it->account_id; 99 bool account_matches = account_id.empty() || account_id == it->account_id;
147 if (account_matches && scope_matches) 100 if (account_matches && scope_matches)
148 it->request->InformConsumer(error, access_token, expiration); 101 it->request->InformConsumer(error, access_token, expiration);
149 } 102 }
150 } 103 }
151 104
152 std::string FakeProfileOAuth2TokenService::GetRefreshToken(
153 const std::string& account_id) const {
154 std::map<std::string, std::string>::const_iterator it =
155 refresh_tokens_.find(account_id);
156 if (it != refresh_tokens_.end())
157 return it->second;
158 return std::string();
159 }
160
161 net::URLRequestContextGetter*
162 FakeProfileOAuth2TokenService::GetRequestContext() {
163 return NULL;
164 }
165
166 std::vector<FakeProfileOAuth2TokenService::PendingRequest> 105 std::vector<FakeProfileOAuth2TokenService::PendingRequest>
167 FakeProfileOAuth2TokenService::GetPendingRequests() { 106 FakeProfileOAuth2TokenService::GetPendingRequests() {
168 std::vector<PendingRequest> valid_requests; 107 std::vector<PendingRequest> valid_requests;
169 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); 108 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
170 it != pending_requests_.end(); ++it) { 109 it != pending_requests_.end(); ++it) {
171 if (it->request) 110 if (it->request)
172 valid_requests.push_back(*it); 111 valid_requests.push_back(*it);
173 } 112 }
174 return valid_requests; 113 return valid_requests;
175 } 114 }
(...skipping 16 matching lines...) Expand all
192 if (auto_post_fetch_response_on_message_loop_) { 131 if (auto_post_fetch_response_on_message_loop_) {
193 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 132 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
194 &FakeProfileOAuth2TokenService::IssueAllTokensForAccount, 133 &FakeProfileOAuth2TokenService::IssueAllTokensForAccount,
195 weak_ptr_factory_.GetWeakPtr(), 134 weak_ptr_factory_.GetWeakPtr(),
196 account_id, 135 account_id,
197 "access_token", 136 "access_token",
198 base::Time::Max())); 137 base::Time::Max()));
199 } 138 }
200 } 139 }
201 140
202 OAuth2AccessTokenFetcher* 141 void FakeProfileOAuth2TokenService::InvalidateAccessTokenImpl(
203 FakeProfileOAuth2TokenService::CreateAccessTokenFetcher(
204 const std::string& account_id,
205 net::URLRequestContextGetter* getter,
206 OAuth2AccessTokenConsumer* consumer) {
207 NOTREACHED();
208 return NULL;
209 }
210
211 void FakeProfileOAuth2TokenService::InvalidateOAuth2Token(
212 const std::string& account_id, 142 const std::string& account_id,
213 const std::string& client_id, 143 const std::string& client_id,
214 const ScopeSet& scopes, 144 const ScopeSet& scopes,
215 const std::string& access_token) { 145 const std::string& access_token) {
216 // Do nothing, as we don't have a cache from which to remove the token. 146 // Do nothing, as we don't have a cache from which to remove the token.
217 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698