OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/policy/cloud/test_request_interceptor.h" | 5 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { | 159 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { |
160 public: | 160 public: |
161 Delegate(const std::string& hostname, | 161 Delegate(const std::string& hostname, |
162 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 162 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
163 ~Delegate() override; | 163 ~Delegate() override; |
164 | 164 |
165 // net::URLRequestInterceptor implementation: | 165 // net::URLRequestInterceptor implementation: |
166 net::URLRequestJob* MaybeInterceptRequest( | 166 net::URLRequestJob* MaybeInterceptRequest( |
167 net::URLRequest* request, | 167 net::URLRequest* request, |
168 net::NetworkDelegate* network_delegate) const override; | 168 net::NetworkDelegate* network_delegate) override; |
| 169 |
| 170 net::URLRequestJob* MaybeInterceptRedirect( |
| 171 net::URLRequest* request, |
| 172 net::NetworkDelegate* network_delegate, |
| 173 const GURL& location) override; |
| 174 |
| 175 net::URLRequestJob* MaybeInterceptResponse( |
| 176 net::URLRequest* request, |
| 177 net::NetworkDelegate* network_delegate) override; |
169 | 178 |
170 void GetPendingSize(size_t* pending_size) const; | 179 void GetPendingSize(size_t* pending_size) const; |
171 void PushJobCallback(const JobCallback& callback); | 180 void PushJobCallback(const JobCallback& callback); |
172 | 181 |
173 private: | 182 private: |
174 const std::string hostname_; | 183 const std::string hostname_; |
175 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 184 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
176 | 185 |
177 // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a | 186 // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a |
178 // const method; it can't reenter though, because it runs exclusively on | 187 // const method; it can't reenter though, because it runs exclusively on |
(...skipping 22 matching lines...) Expand all Loading... |
201 if (pending_job_callbacks_.empty()) { | 210 if (pending_job_callbacks_.empty()) { |
202 // Reject dmserver requests by default. | 211 // Reject dmserver requests by default. |
203 return BadRequestJobCallback(request, network_delegate); | 212 return BadRequestJobCallback(request, network_delegate); |
204 } | 213 } |
205 | 214 |
206 JobCallback callback = pending_job_callbacks_.front(); | 215 JobCallback callback = pending_job_callbacks_.front(); |
207 pending_job_callbacks_.pop(); | 216 pending_job_callbacks_.pop(); |
208 return callback.Run(request, network_delegate); | 217 return callback.Run(request, network_delegate); |
209 } | 218 } |
210 | 219 |
| 220 net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptRedirect( |
| 221 net::URLRequest* request, |
| 222 net::NetworkDelegate* network_delegate, |
| 223 const GURL& location) const { |
| 224 return NULL; |
| 225 } |
| 226 |
| 227 net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptResponse( |
| 228 net::URLRequest* request, |
| 229 net::NetworkDelegate* network_delegate) const { |
| 230 return NULL; |
| 231 } |
| 232 |
211 void TestRequestInterceptor::Delegate::GetPendingSize( | 233 void TestRequestInterceptor::Delegate::GetPendingSize( |
212 size_t* pending_size) const { | 234 size_t* pending_size) const { |
213 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 235 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
214 *pending_size = pending_job_callbacks_.size(); | 236 *pending_size = pending_job_callbacks_.size(); |
215 } | 237 } |
216 | 238 |
217 void TestRequestInterceptor::Delegate::PushJobCallback( | 239 void TestRequestInterceptor::Delegate::PushJobCallback( |
218 const JobCallback& callback) { | 240 const JobCallback& callback) { |
219 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 241 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
220 pending_job_callbacks_.push(callback); | 242 pending_job_callbacks_.push(callback); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 FROM_HERE, | 308 FROM_HERE, |
287 base::Bind( | 309 base::Bind( |
288 base::IgnoreResult(&base::MessageLoopProxy::PostTask), | 310 base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
289 base::MessageLoopProxy::current(), | 311 base::MessageLoopProxy::current(), |
290 FROM_HERE, | 312 FROM_HERE, |
291 run_loop.QuitClosure())); | 313 run_loop.QuitClosure())); |
292 run_loop.Run(); | 314 run_loop.Run(); |
293 } | 315 } |
294 | 316 |
295 } // namespace policy | 317 } // namespace policy |
OLD | NEW |