OLD | NEW |
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 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() { | 7 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() { |
8 } | 8 } |
9 | 9 |
10 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() { | 10 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() { |
11 } | 11 } |
12 | 12 |
13 // static | 13 // static |
14 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build( | 14 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build( |
15 content::BrowserContext* profile) { | 15 content::BrowserContext* profile) { |
16 FakeProfileOAuth2TokenService* service = new FakeProfileOAuth2TokenService(); | 16 FakeProfileOAuth2TokenService* service = new FakeProfileOAuth2TokenService(); |
17 service->Initialize(reinterpret_cast<Profile*>(profile)); | 17 service->Initialize(reinterpret_cast<Profile*>(profile)); |
18 return service; | 18 return service; |
19 } | 19 } |
20 | 20 |
21 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() { | 21 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() { |
22 } | 22 } |
23 | 23 |
24 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { | 24 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { |
25 } | 25 } |
26 | 26 |
| 27 bool FakeProfileOAuth2TokenService::RefreshTokenIsAvailable( |
| 28 const std::string& account_id) { |
| 29 return !GetRefreshToken(account_id).empty(); |
| 30 } |
| 31 |
27 void FakeProfileOAuth2TokenService::IssueRefreshToken( | 32 void FakeProfileOAuth2TokenService::IssueRefreshToken( |
28 const std::string& token) { | 33 const std::string& token) { |
29 refresh_token_ = token; | 34 refresh_token_ = token; |
30 if (refresh_token_.empty()) | 35 if (refresh_token_.empty()) |
31 FireRefreshTokenRevoked("account_id"); | 36 FireRefreshTokenRevoked("account_id"); |
32 else | 37 else |
33 FireRefreshTokenAvailable("account_id"); | 38 FireRefreshTokenAvailable("account_id"); |
34 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? | 39 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? |
35 } | 40 } |
36 | 41 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = | 80 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = |
76 GetPendingRequests(); | 81 GetPendingRequests(); |
77 // Walk the requests and notify the callbacks. | 82 // Walk the requests and notify the callbacks. |
78 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 83 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
79 it != pending_requests_.end(); ++it) { | 84 it != pending_requests_.end(); ++it) { |
80 if (it->request && (all_scopes || it->scopes == scope)) | 85 if (it->request && (all_scopes || it->scopes == scope)) |
81 it->request->InformConsumer(error, access_token, expiration); | 86 it->request->InformConsumer(error, access_token, expiration); |
82 } | 87 } |
83 } | 88 } |
84 | 89 |
85 std::string FakeProfileOAuth2TokenService::GetRefreshToken() { | 90 std::string FakeProfileOAuth2TokenService::GetRefreshToken( |
| 91 const std::string& account_id) { |
86 return refresh_token_; | 92 return refresh_token_; |
87 } | 93 } |
88 | 94 |
89 net::URLRequestContextGetter* | 95 net::URLRequestContextGetter* |
90 FakeProfileOAuth2TokenService::GetRequestContext() { | 96 FakeProfileOAuth2TokenService::GetRequestContext() { |
91 return NULL; | 97 return NULL; |
92 } | 98 } |
93 | 99 |
94 std::vector<FakeProfileOAuth2TokenService::PendingRequest> | 100 std::vector<FakeProfileOAuth2TokenService::PendingRequest> |
95 FakeProfileOAuth2TokenService::GetPendingRequests() { | 101 FakeProfileOAuth2TokenService::GetPendingRequests() { |
96 std::vector<PendingRequest> valid_requests; | 102 std::vector<PendingRequest> valid_requests; |
97 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 103 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
98 it != pending_requests_.end(); ++it) { | 104 it != pending_requests_.end(); ++it) { |
99 if (it->request) | 105 if (it->request) |
100 valid_requests.push_back(*it); | 106 valid_requests.push_back(*it); |
101 } | 107 } |
102 return valid_requests; | 108 return valid_requests; |
103 } | 109 } |
104 | 110 |
105 void FakeProfileOAuth2TokenService::FetchOAuth2Token( | 111 void FakeProfileOAuth2TokenService::FetchOAuth2Token( |
106 RequestImpl* request, | 112 RequestImpl* request, |
| 113 const std::string& account_id, |
107 net::URLRequestContextGetter* getter, | 114 net::URLRequestContextGetter* getter, |
108 const std::string& client_id, | 115 const std::string& client_id, |
109 const std::string& client_secret, | 116 const std::string& client_secret, |
110 const ScopeSet& scopes) { | 117 const ScopeSet& scopes) { |
111 PendingRequest pending_request; | 118 PendingRequest pending_request; |
| 119 pending_request.account_id = account_id; |
112 pending_request.client_id = client_id; | 120 pending_request.client_id = client_id; |
113 pending_request.client_secret = client_secret; | 121 pending_request.client_secret = client_secret; |
114 pending_request.scopes = scopes; | 122 pending_request.scopes = scopes; |
115 pending_request.request = request->AsWeakPtr(); | 123 pending_request.request = request->AsWeakPtr(); |
116 pending_requests_.push_back(pending_request); | 124 pending_requests_.push_back(pending_request); |
117 } | 125 } |
OLD | NEW |