OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/web_view/url_request_cloneable.h" | 5 #include "components/web_view/url_request_cloneable.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "mojo/common/data_pipe_utils.h" | 11 #include "mojo/common/data_pipe_utils.h" |
11 #include "mojo/common/url_type_converters.h" | 12 #include "mojo/common/url_type_converters.h" |
12 | 13 |
13 namespace web_view { | 14 namespace web_view { |
14 | 15 |
15 // TODO(erg): In the long run, we might not want to have a stack of | 16 // TODO(erg): In the long run, we might not want to have a stack of |
16 // URLRequestPtrs, but another type that captures most of the data. When I saw | 17 // URLRequestPtrs, but another type that captures most of the data. When I saw |
17 // NavigationController the first time, I didn't understand why they made their | 18 // NavigationController the first time, I didn't understand why they made their |
18 // own datastructure which kept track of everything in a request. The reason is | 19 // own datastructure which kept track of everything in a request. The reason is |
19 // that they have to build requests from multiple different datatypes. | 20 // that they have to build requests from multiple different datatypes. |
20 | 21 |
21 URLRequestCloneable::URLRequestCloneable(mojo::URLRequestPtr original_request) | 22 URLRequestCloneable::URLRequestCloneable(mojo::URLRequestPtr original_request) |
22 : url_(original_request->url), | 23 : url_(original_request->url), |
23 method_(original_request->method), | 24 method_(original_request->method), |
24 headers_(original_request->headers.Pass()), | 25 headers_(std::move(original_request->headers)), |
25 response_body_buffer_size_(original_request->response_body_buffer_size), | 26 response_body_buffer_size_(original_request->response_body_buffer_size), |
26 auto_follow_redirects_(original_request->auto_follow_redirects), | 27 auto_follow_redirects_(original_request->auto_follow_redirects), |
27 bypass_cache_(original_request->bypass_cache), | 28 bypass_cache_(original_request->bypass_cache), |
28 original_body_null_(original_request->body.is_null()), | 29 original_body_null_(original_request->body.is_null()), |
29 body_(original_request->body.size()), | 30 body_(original_request->body.size()), |
30 originating_time_(base::TimeTicks::FromInternalValue( | 31 originating_time_(base::TimeTicks::FromInternalValue( |
31 original_request->originating_time_ticks)) { | 32 original_request->originating_time_ticks)) { |
32 // TODO(erg): Maybe we can do some sort of async copy here? | 33 // TODO(erg): Maybe we can do some sort of async copy here? |
33 for (size_t i = 0; i < original_request->body.size(); ++i) { | 34 for (size_t i = 0; i < original_request->body.size(); ++i) { |
34 mojo::common::BlockingCopyToString(original_request->body[i].Pass(), | 35 mojo::common::BlockingCopyToString(std::move(original_request->body[i]), |
35 &body_[i]); | 36 &body_[i]); |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 URLRequestCloneable::URLRequestCloneable(const GURL& raw_url) | 40 URLRequestCloneable::URLRequestCloneable(const GURL& raw_url) |
40 : url_(mojo::String::From(raw_url)), | 41 : url_(mojo::String::From(raw_url)), |
41 method_("GET"), | 42 method_("GET"), |
42 headers_(), | 43 headers_(), |
43 response_body_buffer_size_(0), | 44 response_body_buffer_size_(0), |
44 auto_follow_redirects_(false), | 45 auto_follow_redirects_(false), |
(...skipping 16 matching lines...) Expand all Loading... |
61 request->body = | 62 request->body = |
62 mojo::Array<mojo::ScopedDataPipeConsumerHandle>(body_.size()); | 63 mojo::Array<mojo::ScopedDataPipeConsumerHandle>(body_.size()); |
63 for (size_t i = 0; i < body_.size(); ++i) { | 64 for (size_t i = 0; i < body_.size(); ++i) { |
64 uint32_t num_bytes = static_cast<uint32_t>(body_[i].size()); | 65 uint32_t num_bytes = static_cast<uint32_t>(body_[i].size()); |
65 MojoCreateDataPipeOptions options; | 66 MojoCreateDataPipeOptions options; |
66 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 67 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
67 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 68 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
68 options.element_num_bytes = 1; | 69 options.element_num_bytes = 1; |
69 options.capacity_num_bytes = num_bytes; | 70 options.capacity_num_bytes = num_bytes; |
70 mojo::DataPipe data_pipe(options); | 71 mojo::DataPipe data_pipe(options); |
71 request->body[i] = data_pipe.consumer_handle.Pass(); | 72 request->body[i] = std::move(data_pipe.consumer_handle); |
72 WriteDataRaw(data_pipe.producer_handle.get(), body_[i].data(), &num_bytes, | 73 WriteDataRaw(data_pipe.producer_handle.get(), body_[i].data(), &num_bytes, |
73 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); | 74 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); |
74 DCHECK_EQ(num_bytes, body_[i].size()); | 75 DCHECK_EQ(num_bytes, body_[i].size()); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 request->originating_time_ticks = originating_time_.ToInternalValue(); | 79 request->originating_time_ticks = originating_time_.ToInternalValue(); |
79 | 80 |
80 return request.Pass(); | 81 return request; |
81 } | 82 } |
82 | 83 |
83 } // namespace web_view | 84 } // namespace web_view |
OLD | NEW |