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

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

Issue 336253002: Add IdentityProvider-based AccountTracker to google_apis (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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.h" 5 #include "google_apis/gaia/fake_oauth2_token_service.h"
6 6
7 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) {} 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() {
8 }
9
10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() {
11 }
12
13 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) {
14 }
8 15
9 FakeOAuth2TokenService::~FakeOAuth2TokenService() { 16 FakeOAuth2TokenService::~FakeOAuth2TokenService() {
10 } 17 }
11 18
19 std::vector<std::string> FakeOAuth2TokenService::GetAccounts() {
20 return std::vector<std::string>(account_ids_.begin(), account_ids_.end());
21 }
22
12 void FakeOAuth2TokenService::FetchOAuth2Token( 23 void FakeOAuth2TokenService::FetchOAuth2Token(
13 RequestImpl* request, 24 RequestImpl* request,
14 const std::string& account_id, 25 const std::string& account_id,
15 net::URLRequestContextGetter* getter, 26 net::URLRequestContextGetter* getter,
16 const std::string& client_id, 27 const std::string& client_id,
17 const std::string& client_secret, 28 const std::string& client_secret,
18 const ScopeSet& scopes) { 29 const ScopeSet& scopes) {
30 PendingRequest pending_request;
31 pending_request.account_id = account_id;
32 pending_request.client_id = client_id;
33 pending_request.client_secret = client_secret;
34 pending_request.scopes = scopes;
35 pending_request.request = request->AsWeakPtr();
36 pending_requests_.push_back(pending_request);
19 } 37 }
20 38
21 void FakeOAuth2TokenService::InvalidateOAuth2Token( 39 void FakeOAuth2TokenService::InvalidateOAuth2Token(
22 const std::string& account_id, 40 const std::string& account_id,
23 const std::string& client_id, 41 const std::string& client_id,
24 const ScopeSet& scopes, 42 const ScopeSet& scopes,
25 const std::string& access_token) { 43 const std::string& access_token) {
26 } 44 }
27 45
28 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() { 46 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() {
29 return request_context_; 47 return request_context_;
30 } 48 }
31 49
32 bool FakeOAuth2TokenService::RefreshTokenIsAvailable( 50 bool FakeOAuth2TokenService::RefreshTokenIsAvailable(
33 const std::string& account_id) const { 51 const std::string& account_id) const {
34 return account_ids_.count(account_id) != 0; 52 return account_ids_.count(account_id) != 0;
35 }; 53 };
36 54
37 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) { 55 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) {
38 account_ids_.insert(account_id); 56 account_ids_.insert(account_id);
57 FireRefreshTokenAvailable(account_id);
39 } 58 }
40 59
60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) {
61 account_ids_.erase(account_id);
62 FireRefreshTokenRevoked(account_id);
63 }
64
65 void FakeOAuth2TokenService::IssueAllTokensForAccount(
66 const std::string& account_id,
67 const std::string& access_token,
68 const base::Time& expiration) {
69
70 // Walk the requests and notify the callbacks.
71 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin();
72 it != pending_requests_.end(); ++it) {
73 if (it->request && (account_id == it->account_id)) {
74 it->request->InformConsumer(
75 GoogleServiceAuthError::AuthErrorNone(), access_token, expiration);
76 }
77 }
78 }
79
80
41 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( 81 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher(
42 const std::string& account_id, 82 const std::string& account_id,
43 net::URLRequestContextGetter* getter, 83 net::URLRequestContextGetter* getter,
44 OAuth2AccessTokenConsumer* consumer) { 84 OAuth2AccessTokenConsumer* consumer) {
45 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus 85 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus
46 // |CreateAccessTokenFetcher| should never be called. 86 // |CreateAccessTokenFetcher| should never be called.
47 NOTREACHED(); 87 NOTREACHED();
48 return NULL; 88 return NULL;
49 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698