Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: components/update_client/url_request_post_interceptor.cc

Issue 2827233005: Remove URLRequestJob::GetResponseCode implementations outside of net/. (Closed)
Patch Set: Response to comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/browser/extension_protocols.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/update_client/url_request_post_interceptor.h" 5 #include "components/update_client/url_request_post_interceptor.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "components/update_client/test_configurator.h" 13 #include "components/update_client/test_configurator.h"
13 #include "net/base/upload_bytes_element_reader.h" 14 #include "net/base/upload_bytes_element_reader.h"
14 #include "net/base/upload_data_stream.h" 15 #include "net/base/upload_data_stream.h"
16 #include "net/http/http_response_headers.h"
17 #include "net/http/http_util.h"
15 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_filter.h" 19 #include "net/url_request/url_request_filter.h"
17 #include "net/url_request/url_request_interceptor.h" 20 #include "net/url_request/url_request_interceptor.h"
18 #include "net/url_request/url_request_simple_job.h" 21 #include "net/url_request/url_request_simple_job.h"
19 #include "net/url_request/url_request_test_util.h" 22 #include "net/url_request/url_request_test_util.h"
20 23
21 namespace update_client { 24 namespace update_client {
22 25
23 // Returns a canned response. 26 // Returns a canned response.
24 class URLRequestMockJob : public net::URLRequestSimpleJob { 27 class URLRequestMockJob : public net::URLRequestSimpleJob {
25 public: 28 public:
26 URLRequestMockJob(net::URLRequest* request, 29 URLRequestMockJob(net::URLRequest* request,
27 net::NetworkDelegate* network_delegate, 30 net::NetworkDelegate* network_delegate,
28 int response_code, 31 int response_code,
29 const std::string& response_body) 32 const std::string& response_body)
30 : net::URLRequestSimpleJob(request, network_delegate), 33 : net::URLRequestSimpleJob(request, network_delegate),
31 response_code_(response_code), 34 response_code_(response_code),
32 response_body_(response_body) {} 35 response_body_(response_body) {}
33 36
34 protected: 37 protected:
35 int GetResponseCode() const override { return response_code_; } 38 void GetResponseInfo(net::HttpResponseInfo* info) override {
39 const std::string headers =
40 base::StringPrintf("HTTP/1.1 %i OK\r\n\r\n", response_code_);
41 info->headers = base::MakeShared<net::HttpResponseHeaders>(
42 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.length()));
43 }
36 44
37 int GetData(std::string* mime_type, 45 int GetData(std::string* mime_type,
38 std::string* charset, 46 std::string* charset,
39 std::string* data, 47 std::string* data,
40 const net::CompletionCallback& callback) const override { 48 const net::CompletionCallback& callback) const override {
41 mime_type->assign("text/plain"); 49 mime_type->assign("text/plain");
42 charset->assign("US-ASCII"); 50 charset->assign("US-ASCII");
43 data->assign(response_body_); 51 data->assign(response_body_);
44 return net::OK; 52 return net::OK;
45 } 53 }
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return CreateInterceptorForPath(POST_INTERCEPT_PATH); 301 return CreateInterceptorForPath(POST_INTERCEPT_PATH);
294 } 302 }
295 303
296 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath( 304 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath(
297 const char* url_path) { 305 const char* url_path) {
298 return URLRequestPostInterceptorFactory::CreateInterceptor( 306 return URLRequestPostInterceptorFactory::CreateInterceptor(
299 base::FilePath::FromUTF8Unsafe(url_path)); 307 base::FilePath::FromUTF8Unsafe(url_path));
300 } 308 }
301 309
302 } // namespace update_client 310 } // namespace update_client
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698