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

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: Address final comments Created 5 years, 5 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 std::vector<std::string> FakeOAuth2TokenServiceDelegate::GetAccounts() {
43 std::vector<std::string> account_ids;
44 for (std::map<std::string, std::string>::const_iterator iter =
45 refresh_tokens_.begin();
46 iter != refresh_tokens_.end(); ++iter) {
47 account_ids.push_back(iter->first);
48 }
49 return account_ids;
50 }
51
52 void FakeOAuth2TokenServiceDelegate::RevokeAllCredentials() {
53 std::vector<std::string> account_ids = GetAccounts();
54 for (std::vector<std::string>::const_iterator it = account_ids.begin();
55 it != account_ids.end(); it++) {
56 RevokeCredentials(*it);
57 }
58 }
59
60 void FakeOAuth2TokenServiceDelegate::LoadCredentials(
61 const std::string& primary_account_id) {
62 FireRefreshTokensLoaded();
63 }
64
65 void FakeOAuth2TokenServiceDelegate::UpdateCredentials(
66 const std::string& account_id,
67 const std::string& refresh_token) {
68 IssueRefreshTokenForUser(account_id, refresh_token);
69 }
70
71 void FakeOAuth2TokenServiceDelegate::IssueRefreshTokenForUser(
72 const std::string& account_id,
73 const std::string& token) {
74 ScopedBatchChange batch(this);
75 if (token.empty()) {
76 refresh_tokens_.erase(account_id);
77 FireRefreshTokenRevoked(account_id);
78 } else {
79 refresh_tokens_[account_id] = token;
80 FireRefreshTokenAvailable(account_id);
81 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here?
82 }
83 }
84
85 void FakeOAuth2TokenServiceDelegate::RevokeCredentials(
86 const std::string& account_id) {
87 IssueRefreshTokenForUser(account_id, std::string());
88 }
89
90 net::URLRequestContextGetter*
91 FakeOAuth2TokenServiceDelegate::GetRequestContext() const {
92 return request_context_.get();
93 }
OLDNEW
« no previous file with comments | « google_apis/gaia/fake_oauth2_token_service_delegate.h ('k') | google_apis/gaia/oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698