| 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 <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 TestRequestInterceptor::Delegate::Delegate( | 202 TestRequestInterceptor::Delegate::Delegate( |
| 203 const std::string& hostname, | 203 const std::string& hostname, |
| 204 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 204 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
| 205 : hostname_(hostname), io_task_runner_(io_task_runner) {} | 205 : hostname_(hostname), io_task_runner_(io_task_runner) {} |
| 206 | 206 |
| 207 TestRequestInterceptor::Delegate::~Delegate() {} | 207 TestRequestInterceptor::Delegate::~Delegate() {} |
| 208 | 208 |
| 209 net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptRequest( | 209 net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptRequest( |
| 210 net::URLRequest* request, | 210 net::URLRequest* request, |
| 211 net::NetworkDelegate* network_delegate) const { | 211 net::NetworkDelegate* network_delegate) const { |
| 212 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 212 CHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 213 | 213 |
| 214 if (request->url().host_piece() != hostname_) { | 214 if (request->url().host_piece() != hostname_) { |
| 215 // Reject requests to other servers. | 215 // Reject requests to other servers. |
| 216 return ErrorJobCallback( | 216 return ErrorJobCallback( |
| 217 net::ERR_CONNECTION_REFUSED, request, network_delegate); | 217 net::ERR_CONNECTION_REFUSED, request, network_delegate); |
| 218 } | 218 } |
| 219 | 219 |
| 220 if (pending_job_callbacks_.empty()) { | 220 if (pending_job_callbacks_.empty()) { |
| 221 // Reject dmserver requests by default. | 221 // Reject dmserver requests by default. |
| 222 return BadRequestJobCallback(request, network_delegate); | 222 return BadRequestJobCallback(request, network_delegate); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 base::Passed(&callbacks))); | 233 base::Passed(&callbacks))); |
| 234 } | 234 } |
| 235 | 235 |
| 236 JobCallback callback = pending_job_callbacks_.front(); | 236 JobCallback callback = pending_job_callbacks_.front(); |
| 237 pending_job_callbacks_.pop(); | 237 pending_job_callbacks_.pop(); |
| 238 return callback.Run(request, network_delegate); | 238 return callback.Run(request, network_delegate); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void TestRequestInterceptor::Delegate::GetPendingSize( | 241 void TestRequestInterceptor::Delegate::GetPendingSize( |
| 242 size_t* pending_size) const { | 242 size_t* pending_size) const { |
| 243 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 243 CHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 244 *pending_size = pending_job_callbacks_.size(); | 244 *pending_size = pending_job_callbacks_.size(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void TestRequestInterceptor::Delegate::AddRequestServicedCallback( | 247 void TestRequestInterceptor::Delegate::AddRequestServicedCallback( |
| 248 const base::Closure& callback) { | 248 const base::Closure& callback) { |
| 249 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 249 CHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 250 request_serviced_callbacks_.push_back(callback); | 250 request_serviced_callbacks_.push_back(callback); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void TestRequestInterceptor::Delegate::PushJobCallback( | 253 void TestRequestInterceptor::Delegate::PushJobCallback( |
| 254 const JobCallback& callback) { | 254 const JobCallback& callback) { |
| 255 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 255 CHECK(io_task_runner_->RunsTasksInCurrentSequence()); |
| 256 pending_job_callbacks_.push(callback); | 256 pending_job_callbacks_.push(callback); |
| 257 } | 257 } |
| 258 | 258 |
| 259 // static | 259 // static |
| 260 void TestRequestInterceptor::Delegate::InvokeRequestServicedCallbacks( | 260 void TestRequestInterceptor::Delegate::InvokeRequestServicedCallbacks( |
| 261 std::unique_ptr<std::vector<base::Closure>> callbacks) { | 261 std::unique_ptr<std::vector<base::Closure>> callbacks) { |
| 262 for (const auto& p : *callbacks) | 262 for (const auto& p : *callbacks) |
| 263 p.Run(); | 263 p.Run(); |
| 264 } | 264 } |
| 265 | 265 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 io_task_runner_->PostTask(FROM_HERE, task); | 341 io_task_runner_->PostTask(FROM_HERE, task); |
| 342 base::RunLoop run_loop; | 342 base::RunLoop run_loop; |
| 343 io_task_runner_->PostTask( | 343 io_task_runner_->PostTask( |
| 344 FROM_HERE, base::BindOnce(base::IgnoreResult(&base::TaskRunner::PostTask), | 344 FROM_HERE, base::BindOnce(base::IgnoreResult(&base::TaskRunner::PostTask), |
| 345 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, | 345 base::ThreadTaskRunnerHandle::Get(), FROM_HERE, |
| 346 run_loop.QuitClosure())); | 346 run_loop.QuitClosure())); |
| 347 run_loop.Run(); | 347 run_loop.Run(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 } // namespace policy | 350 } // namespace policy |
| OLD | NEW |