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 #include "chrome/browser/profiles/profile.h" |
| 8 |
7 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() { | 9 FakeProfileOAuth2TokenService::PendingRequest::PendingRequest() { |
8 } | 10 } |
9 | 11 |
10 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() { | 12 FakeProfileOAuth2TokenService::PendingRequest::~PendingRequest() { |
11 } | 13 } |
12 | 14 |
13 // static | 15 // static |
14 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build( | 16 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build( |
15 content::BrowserContext* profile) { | 17 content::BrowserContext* context) { |
16 return new FakeProfileOAuth2TokenService(); | 18 // Initialize called explicitly here, instead of by passing a Profile to the |
| 19 // constructor, as not all of the consuming tests need an initialized service. |
| 20 ProfileOAuth2TokenService* token_service = |
| 21 new FakeProfileOAuth2TokenService(); |
| 22 token_service->Initialize(static_cast<Profile*>(context)); |
| 23 return token_service; |
17 } | 24 } |
18 | 25 |
19 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() { | 26 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() |
| 27 : is_initialized_(false) { |
20 } | 28 } |
21 | 29 |
22 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { | 30 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { |
23 } | 31 } |
24 | 32 |
| 33 void FakeProfileOAuth2TokenService::Initialize(Profile* profile) { |
| 34 ProfileOAuth2TokenService::Initialize(profile); |
| 35 is_initialized_ = true; |
| 36 } |
| 37 |
25 void FakeProfileOAuth2TokenService::Shutdown() { | 38 void FakeProfileOAuth2TokenService::Shutdown() { |
26 // Do not call the base class handler because it assumes that Initialize() | 39 if (is_initialized_) { |
27 // is always called before Shutdown() and that's not the case for this mock. | 40 ProfileOAuth2TokenService::Shutdown(); |
| 41 is_initialized_ = false; |
| 42 } |
28 } | 43 } |
29 | 44 |
30 void FakeProfileOAuth2TokenService::IssueRefreshToken( | 45 void FakeProfileOAuth2TokenService::IssueRefreshToken( |
31 const std::string& token) { | 46 const std::string& token) { |
32 refresh_token_ = token; | 47 refresh_token_ = token; |
33 if (refresh_token_.empty()) | 48 if (refresh_token_.empty()) |
34 FireRefreshTokenRevoked("account_id"); | 49 FireRefreshTokenRevoked("account_id"); |
35 else | 50 else |
36 FireRefreshTokenAvailable("account_id"); | 51 FireRefreshTokenAvailable("account_id"); |
37 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? | 52 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = | 93 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = |
79 GetPendingRequests(); | 94 GetPendingRequests(); |
80 // Walk the requests and notify the callbacks. | 95 // Walk the requests and notify the callbacks. |
81 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 96 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
82 it != pending_requests_.end(); ++it) { | 97 it != pending_requests_.end(); ++it) { |
83 if (it->request && (all_scopes || it->scopes == scope)) | 98 if (it->request && (all_scopes || it->scopes == scope)) |
84 it->request->InformConsumer(error, access_token, expiration); | 99 it->request->InformConsumer(error, access_token, expiration); |
85 } | 100 } |
86 } | 101 } |
87 | 102 |
88 std::string FakeProfileOAuth2TokenService::GetRefreshToken() { | 103 std::string FakeProfileOAuth2TokenService::GetRefreshToken( |
| 104 const std::string& account_id) { |
89 return refresh_token_; | 105 return refresh_token_; |
90 } | 106 } |
91 | 107 |
92 net::URLRequestContextGetter* | 108 net::URLRequestContextGetter* |
93 FakeProfileOAuth2TokenService::GetRequestContext() { | 109 FakeProfileOAuth2TokenService::GetRequestContext() { |
94 return NULL; | 110 return NULL; |
95 } | 111 } |
96 | 112 |
97 std::vector<FakeProfileOAuth2TokenService::PendingRequest> | 113 std::vector<FakeProfileOAuth2TokenService::PendingRequest> |
98 FakeProfileOAuth2TokenService::GetPendingRequests() { | 114 FakeProfileOAuth2TokenService::GetPendingRequests() { |
99 std::vector<PendingRequest> valid_requests; | 115 std::vector<PendingRequest> valid_requests; |
100 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); | 116 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
101 it != pending_requests_.end(); ++it) { | 117 it != pending_requests_.end(); ++it) { |
102 if (it->request) | 118 if (it->request) |
103 valid_requests.push_back(*it); | 119 valid_requests.push_back(*it); |
104 } | 120 } |
105 return valid_requests; | 121 return valid_requests; |
106 } | 122 } |
107 | 123 |
108 void FakeProfileOAuth2TokenService::FetchOAuth2Token( | 124 void FakeProfileOAuth2TokenService::FetchOAuth2Token( |
109 RequestImpl* request, | 125 RequestImpl* request, |
| 126 const std::string& account_id, |
110 net::URLRequestContextGetter* getter, | 127 net::URLRequestContextGetter* getter, |
111 const std::string& client_id, | 128 const std::string& client_id, |
112 const std::string& client_secret, | 129 const std::string& client_secret, |
113 const ScopeSet& scopes) { | 130 const ScopeSet& scopes) { |
114 PendingRequest pending_request; | 131 PendingRequest pending_request; |
| 132 pending_request.account_id = account_id; |
115 pending_request.client_id = client_id; | 133 pending_request.client_id = client_id; |
116 pending_request.client_secret = client_secret; | 134 pending_request.client_secret = client_secret; |
117 pending_request.scopes = scopes; | 135 pending_request.scopes = scopes; |
118 pending_request.request = request->AsWeakPtr(); | 136 pending_request.request = request->AsWeakPtr(); |
119 pending_requests_.push_back(pending_request); | 137 pending_requests_.push_back(pending_request); |
120 } | 138 } |
OLD | NEW |