| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/test_url_request_interceptor.h" | 5 #include "net/url_request/test_url_request_interceptor.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 public: | 23 public: |
| 24 TestURLRequestJob(net::URLRequest* request, | 24 TestURLRequestJob(net::URLRequest* request, |
| 25 net::NetworkDelegate* network_delegate, | 25 net::NetworkDelegate* network_delegate, |
| 26 const base::FilePath& file_path, | 26 const base::FilePath& file_path, |
| 27 const scoped_refptr<base::TaskRunner>& worker_task_runner) | 27 const scoped_refptr<base::TaskRunner>& worker_task_runner) |
| 28 : net::URLRequestFileJob(request, | 28 : net::URLRequestFileJob(request, |
| 29 network_delegate, | 29 network_delegate, |
| 30 file_path, | 30 file_path, |
| 31 worker_task_runner) {} | 31 worker_task_runner) {} |
| 32 | 32 |
| 33 virtual int GetResponseCode() const OVERRIDE { return 200; } | 33 virtual int GetResponseCode() const override { return 200; } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 virtual ~TestURLRequestJob() {} | 36 virtual ~TestURLRequestJob() {} |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(TestURLRequestJob); | 38 DISALLOW_COPY_AND_ASSIGN(TestURLRequestJob); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 // This class handles the actual URL request interception. It may be constructed | 43 // This class handles the actual URL request interception. It may be constructed |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 base::AutoLock auto_lock(hit_count_lock_); | 86 base::AutoLock auto_lock(hit_count_lock_); |
| 87 return hit_count_; | 87 return hit_count_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 typedef std::map<GURL, base::FilePath> ResponseMap; | 91 typedef std::map<GURL, base::FilePath> ResponseMap; |
| 92 | 92 |
| 93 // When computing matches, this ignores the query parameters of the url. | 93 // When computing matches, this ignores the query parameters of the url. |
| 94 virtual net::URLRequestJob* MaybeInterceptRequest( | 94 virtual net::URLRequestJob* MaybeInterceptRequest( |
| 95 net::URLRequest* request, | 95 net::URLRequest* request, |
| 96 net::NetworkDelegate* network_delegate) const OVERRIDE { | 96 net::NetworkDelegate* network_delegate) const override { |
| 97 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 97 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 98 if (request->url().scheme() != scheme_ || | 98 if (request->url().scheme() != scheme_ || |
| 99 request->url().host() != hostname_) { | 99 request->url().host() != hostname_) { |
| 100 return NULL; | 100 return NULL; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ResponseMap::const_iterator it = responses_.find(request->url()); | 103 ResponseMap::const_iterator it = responses_.find(request->url()); |
| 104 if (it == responses_.end()) { | 104 if (it == responses_.end()) { |
| 105 // Search for this request's url, ignoring any query parameters. | 105 // Search for this request's url, ignoring any query parameters. |
| 106 GURL url = request->url(); | 106 GURL url = request->url(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 LocalHostTestURLRequestInterceptor::LocalHostTestURLRequestInterceptor( | 190 LocalHostTestURLRequestInterceptor::LocalHostTestURLRequestInterceptor( |
| 191 const scoped_refptr<base::TaskRunner>& network_task_runner, | 191 const scoped_refptr<base::TaskRunner>& network_task_runner, |
| 192 const scoped_refptr<base::TaskRunner>& worker_task_runner) | 192 const scoped_refptr<base::TaskRunner>& worker_task_runner) |
| 193 : TestURLRequestInterceptor("http", | 193 : TestURLRequestInterceptor("http", |
| 194 "localhost", | 194 "localhost", |
| 195 network_task_runner, | 195 network_task_runner, |
| 196 worker_task_runner) { | 196 worker_task_runner) { |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace net | 199 } // namespace net |
| OLD | NEW |