OLD | NEW |
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::PendingRequest::PendingRequest() { | 7 FakeOAuth2TokenService::PendingRequest::PendingRequest() { |
8 } | 8 } |
9 | 9 |
10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { | 10 FakeOAuth2TokenService::PendingRequest::~PendingRequest() { |
11 } | 11 } |
12 | 12 |
13 FakeOAuth2TokenService::FakeOAuth2TokenService() : request_context_(NULL) { | 13 FakeOAuth2TokenService::FakeOAuth2TokenService() |
| 14 : OAuth2TokenService(new FakeOAuth2TokenServiceDelegate(nullptr)) { |
14 } | 15 } |
15 | 16 |
16 FakeOAuth2TokenService::~FakeOAuth2TokenService() { | 17 FakeOAuth2TokenService::~FakeOAuth2TokenService() { |
17 } | 18 } |
18 | 19 |
19 std::vector<std::string> FakeOAuth2TokenService::GetAccounts() { | |
20 return std::vector<std::string>(account_ids_.begin(), account_ids_.end()); | |
21 } | |
22 | |
23 void FakeOAuth2TokenService::FetchOAuth2Token( | 20 void FakeOAuth2TokenService::FetchOAuth2Token( |
24 RequestImpl* request, | 21 RequestImpl* request, |
25 const std::string& account_id, | 22 const std::string& account_id, |
26 net::URLRequestContextGetter* getter, | 23 net::URLRequestContextGetter* getter, |
27 const std::string& client_id, | 24 const std::string& client_id, |
28 const std::string& client_secret, | 25 const std::string& client_secret, |
29 const ScopeSet& scopes) { | 26 const ScopeSet& scopes) { |
30 PendingRequest pending_request; | 27 PendingRequest pending_request; |
31 pending_request.account_id = account_id; | 28 pending_request.account_id = account_id; |
32 pending_request.client_id = client_id; | 29 pending_request.client_id = client_id; |
33 pending_request.client_secret = client_secret; | 30 pending_request.client_secret = client_secret; |
34 pending_request.scopes = scopes; | 31 pending_request.scopes = scopes; |
35 pending_request.request = request->AsWeakPtr(); | 32 pending_request.request = request->AsWeakPtr(); |
36 pending_requests_.push_back(pending_request); | 33 pending_requests_.push_back(pending_request); |
37 } | 34 } |
38 | 35 |
39 void FakeOAuth2TokenService::InvalidateOAuth2Token( | 36 void FakeOAuth2TokenService::InvalidateAccessTokenImpl( |
40 const std::string& account_id, | 37 const std::string& account_id, |
41 const std::string& client_id, | 38 const std::string& client_id, |
42 const ScopeSet& scopes, | 39 const ScopeSet& scopes, |
43 const std::string& access_token) { | 40 const std::string& access_token) { |
44 } | 41 } |
45 | 42 |
46 net::URLRequestContextGetter* FakeOAuth2TokenService::GetRequestContext() { | |
47 return request_context_; | |
48 } | |
49 | |
50 bool FakeOAuth2TokenService::RefreshTokenIsAvailable( | |
51 const std::string& account_id) const { | |
52 return account_ids_.count(account_id) != 0; | |
53 }; | |
54 | |
55 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) { | 43 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) { |
56 account_ids_.insert(account_id); | 44 GetDelegate()->UpdateCredentials(account_id, "fake_refresh_token"); |
57 FireRefreshTokenAvailable(account_id); | |
58 } | 45 } |
59 | 46 |
60 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { | 47 void FakeOAuth2TokenService::RemoveAccount(const std::string& account_id) { |
61 account_ids_.erase(account_id); | 48 GetDelegate()->RevokeCredentials(account_id); |
62 FireRefreshTokenRevoked(account_id); | |
63 } | 49 } |
64 | 50 |
65 void FakeOAuth2TokenService::IssueAllTokensForAccount( | 51 void FakeOAuth2TokenService::IssueAllTokensForAccount( |
66 const std::string& account_id, | 52 const std::string& account_id, |
67 const std::string& access_token, | 53 const std::string& access_token, |
68 const base::Time& expiration) { | 54 const base::Time& expiration) { |
69 // Walk the requests and notify the callbacks. | 55 // Walk the requests and notify the callbacks. |
70 // Using a copy of pending requests to make sure a new token request triggered | 56 // Using a copy of pending requests to make sure a new token request triggered |
71 // from the handling code does not invalidate the iterator. | 57 // from the handling code does not invalidate the iterator. |
72 std::vector<PendingRequest> pending_requests_copy = pending_requests_; | 58 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
(...skipping 16 matching lines...) Expand all Loading... |
89 std::vector<PendingRequest> pending_requests_copy = pending_requests_; | 75 std::vector<PendingRequest> pending_requests_copy = pending_requests_; |
90 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); | 76 for (std::vector<PendingRequest>::iterator it = pending_requests_copy.begin(); |
91 it != pending_requests_copy.end(); | 77 it != pending_requests_copy.end(); |
92 ++it) { | 78 ++it) { |
93 if (it->request && (account_id == it->account_id)) { | 79 if (it->request && (account_id == it->account_id)) { |
94 it->request->InformConsumer(auth_error, std::string(), base::Time()); | 80 it->request->InformConsumer(auth_error, std::string(), base::Time()); |
95 } | 81 } |
96 } | 82 } |
97 } | 83 } |
98 | 84 |
99 OAuth2AccessTokenFetcher* FakeOAuth2TokenService::CreateAccessTokenFetcher( | 85 FakeOAuth2TokenServiceDelegate* |
100 const std::string& account_id, | 86 FakeOAuth2TokenService::GetFakeOAuth2TokenServiceDelegate() { |
101 net::URLRequestContextGetter* getter, | 87 return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate()); |
102 OAuth2AccessTokenConsumer* consumer) { | |
103 // |FakeOAuth2TokenService| overrides |FetchOAuth2Token| and thus | |
104 // |CreateAccessTokenFetcher| should never be called. | |
105 NOTREACHED(); | |
106 return NULL; | |
107 } | 88 } |
OLD | NEW |