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 "components/component_updater/test/url_request_post_interceptor.h" | 5 #include "components/component_updater/test/url_request_post_interceptor.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 public: | 24 public: |
25 URLRequestMockJob(net::URLRequest* request, | 25 URLRequestMockJob(net::URLRequest* request, |
26 net::NetworkDelegate* network_delegate, | 26 net::NetworkDelegate* network_delegate, |
27 int response_code, | 27 int response_code, |
28 const std::string& response_body) | 28 const std::string& response_body) |
29 : net::URLRequestSimpleJob(request, network_delegate), | 29 : net::URLRequestSimpleJob(request, network_delegate), |
30 response_code_(response_code), | 30 response_code_(response_code), |
31 response_body_(response_body) {} | 31 response_body_(response_body) {} |
32 | 32 |
33 protected: | 33 protected: |
34 virtual int GetResponseCode() const override { return response_code_; } | 34 int GetResponseCode() const override { return response_code_; } |
35 | 35 |
36 virtual int GetData(std::string* mime_type, | 36 int GetData(std::string* mime_type, |
37 std::string* charset, | 37 std::string* charset, |
38 std::string* data, | 38 std::string* data, |
39 const net::CompletionCallback& callback) const override { | 39 const net::CompletionCallback& callback) const override { |
40 mime_type->assign("text/plain"); | 40 mime_type->assign("text/plain"); |
41 charset->assign("US-ASCII"); | 41 charset->assign("US-ASCII"); |
42 data->assign(response_body_); | 42 data->assign(response_body_); |
43 return net::OK; | 43 return net::OK; |
44 } | 44 } |
45 | 45 |
46 private: | 46 private: |
47 virtual ~URLRequestMockJob() {} | 47 ~URLRequestMockJob() override {} |
48 | 48 |
49 int response_code_; | 49 int response_code_; |
50 std::string response_body_; | 50 std::string response_body_; |
51 DISALLOW_COPY_AND_ASSIGN(URLRequestMockJob); | 51 DISALLOW_COPY_AND_ASSIGN(URLRequestMockJob); |
52 }; | 52 }; |
53 | 53 |
54 URLRequestPostInterceptor::URLRequestPostInterceptor( | 54 URLRequestPostInterceptor::URLRequestPostInterceptor( |
55 const GURL& url, | 55 const GURL& url, |
56 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) | 56 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) |
57 : url_(url), io_task_runner_(io_task_runner), hit_count_(0) { | 57 : url_(url), io_task_runner_(io_task_runner), hit_count_(0) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 void OnCreateInterceptor(URLRequestPostInterceptor* interceptor) { | 164 void OnCreateInterceptor(URLRequestPostInterceptor* interceptor) { |
165 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 165 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
166 DCHECK(interceptors_.find(interceptor->GetUrl()) == interceptors_.end()); | 166 DCHECK(interceptors_.find(interceptor->GetUrl()) == interceptors_.end()); |
167 | 167 |
168 interceptors_.insert(std::make_pair(interceptor->GetUrl(), interceptor)); | 168 interceptors_.insert(std::make_pair(interceptor->GetUrl(), interceptor)); |
169 } | 169 } |
170 | 170 |
171 private: | 171 private: |
172 virtual ~Delegate() {} | 172 ~Delegate() override {} |
173 | 173 |
174 virtual net::URLRequestJob* MaybeInterceptRequest( | 174 net::URLRequestJob* MaybeInterceptRequest( |
175 net::URLRequest* request, | 175 net::URLRequest* request, |
176 net::NetworkDelegate* network_delegate) const override { | 176 net::NetworkDelegate* network_delegate) const override { |
177 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 177 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
178 | 178 |
179 // Only intercepts POST. | 179 // Only intercepts POST. |
180 if (!request->has_upload()) | 180 if (!request->has_upload()) |
181 return NULL; | 181 return NULL; |
182 | 182 |
183 GURL url = request->url(); | 183 GURL url = request->url(); |
184 if (url.has_query()) { | 184 if (url.has_query()) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 return CreateInterceptorForPath(POST_INTERCEPT_PATH); | 297 return CreateInterceptorForPath(POST_INTERCEPT_PATH); |
298 } | 298 } |
299 | 299 |
300 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath( | 300 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath( |
301 const char* url_path) { | 301 const char* url_path) { |
302 return URLRequestPostInterceptorFactory::CreateInterceptor( | 302 return URLRequestPostInterceptorFactory::CreateInterceptor( |
303 base::FilePath::FromUTF8Unsafe(url_path)); | 303 base::FilePath::FromUTF8Unsafe(url_path)); |
304 } | 304 } |
305 | 305 |
306 } // namespace component_updater | 306 } // namespace component_updater |
OLD | NEW |