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

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

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: works for all platforms commit e75a498951318d4deb65d40ce8b2def44cd5abc0 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "google_apis/gaia/fake_oauth2_token_service_delegate.h"
6 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
7
8 FakeOAuth2TokenServiceDelegate::FakeOAuth2TokenServiceDelegate(
9 net::URLRequestContextGetter* request_context)
10 : request_context_(request_context) {
11 }
12
13 FakeOAuth2TokenServiceDelegate::~FakeOAuth2TokenServiceDelegate() {
14 }
15
16 OAuth2AccessTokenFetcher*
17 FakeOAuth2TokenServiceDelegate::CreateAccessTokenFetcher(
18 const std::string& account_id,
19 net::URLRequestContextGetter* getter,
20 OAuth2AccessTokenConsumer* consumer) {
21 std::map<std::string, std::string>::const_iterator it =
22 refresh_tokens_.find(account_id);
23 DCHECK(it != refresh_tokens_.end());
24 std::string refresh_token(it->second);
25 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token);
26 }
27
28 bool FakeOAuth2TokenServiceDelegate::RefreshTokenIsAvailable(
29 const std::string& account_id) const {
30 return !GetRefreshToken(account_id).empty();
31 }
32
33 std::string FakeOAuth2TokenServiceDelegate::GetRefreshToken(
34 const std::string& account_id) const {
35 std::map<std::string, std::string>::const_iterator it =
36 refresh_tokens_.find(account_id);
37 if (it != refresh_tokens_.end())
38 return it->second;
39 return std::string();
40 }
41
42 void FakeOAuth2TokenServiceDelegate::UpdateAuthError(
43 const std::string& account_id,
44 const GoogleServiceAuthError& error) {
45 }
46
47 std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
48 std::vector<std::string> account_ids;
49 for (std::map<std::string, std::string>::const_iterator iter =
50 refresh_tokens_.begin();
51 iter != refresh_tokens_.end(); ++iter) {
52 account_ids.push_back(iter->first);
53 }
54 return account_ids;
55 }
56
57 void FakeOAuth2TokenServiceDelegate::RevokeAllCredentials() {
58 std::vector<std::string> account_ids = GetAccounts();
59 for (std::vector<std::string>::const_iterator it = account_ids.begin();
60 it != account_ids.end(); it++) {
61 RevokeCredentials(*it);
62 }
63 }
64
65 void FakeOAuth2TokenServiceDelegate::LoadCredentials(
66 const std::string& primary_account_id) {
67 FireRefreshTokensLoaded();
68 }
69
70 void FakeOAuth2TokenServiceDelegate::UpdateCredentials(
71 const std::string& account_id,
72 const std::string& refresh_token) {
73 IssueRefreshTokenForUser(account_id, refresh_token);
74 }
75
76 void FakeOAuth2TokenServiceDelegate::IssueRefreshTokenForUser(
77 const std::string& account_id,
78 const std::string& token) {
79 ScopedBatchChange batch(this);
80 if (token.empty()) {
81 refresh_tokens_.erase(account_id);
82 FireRefreshTokenRevoked(account_id);
83 } else {
84 refresh_tokens_[account_id] = token;
85 FireRefreshTokenAvailable(account_id);
86 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
87 }
88 }
89
90 void FakeOAuth2TokenServiceDelegate::RevokeCredentials(
91 const std::string& account_id) {
92 IssueRefreshTokenForUser(account_id, std::string());
93 }
94
95 net::URLRequestContextGetter*
96 FakeOAuth2TokenServiceDelegate::GetRequestContext() const {
97 return request_context_.get();
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698