| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) const override; |
| 169 | 169 |
| 170 net::URLRequestJob* MaybeInterceptResponse( |
| 171 net::URLRequest* request, |
| 172 net::NetworkDelegate* network_delegate) const override; |
| 173 |
| 174 net::URLRequestJob* MaybeInterceptRedirect( |
| 175 net::URLRequest* request, |
| 176 net::NetworkDelegate* network_delegate, |
| 177 const GURL& location) const override; |
| 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 |
| 179 // the IO thread. | 188 // the IO thread. |
| (...skipping 21 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::MaybeInterceptResponse( |
| 221 net::URLRequest* request, |
| 222 net::NetworkDelegate* network_delegate) const { |
| 223 return NULL; |
| 224 } |
| 225 |
| 226 net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeInterceptRedirect( |
| 227 net::URLRequest* request, |
| 228 net::NetworkDelegate* network_delegate, |
| 229 const GURL& location) 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 |