[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / resource_messages.cc
blob2f86ae2ecd750dd7e144a5a9ebd8ed55e986c748
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
3 // found in the LICENSE file.
5 #include "content/common/resource_messages.h"
7 #include "net/base/load_timing_info.h"
8 #include "net/http/http_response_headers.h"
10 namespace IPC {
12 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write(
13 Message* m, const param_type& p) {
14 WriteParam(m, p.get() != NULL);
15 if (p.get()) {
16 // Do not disclose Set-Cookie headers over IPC.
17 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES);
21 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders>>::Read(
22 const Message* m,
23 base::PickleIterator* iter,
24 param_type* r) {
25 bool has_object;
26 if (!ReadParam(m, iter, &has_object))
27 return false;
28 if (has_object)
29 *r = new net::HttpResponseHeaders(iter);
30 return true;
33 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log(
34 const param_type& p, std::string* l) {
35 l->append("<HttpResponseHeaders>");
38 void ParamTraits<storage::DataElement>::Write(Message* m, const param_type& p) {
39 WriteParam(m, static_cast<int>(p.type()));
40 switch (p.type()) {
41 case storage::DataElement::TYPE_BYTES: {
42 m->WriteData(p.bytes(), static_cast<int>(p.length()));
43 break;
45 case storage::DataElement::TYPE_FILE: {
46 WriteParam(m, p.path());
47 WriteParam(m, p.offset());
48 WriteParam(m, p.length());
49 WriteParam(m, p.expected_modification_time());
50 break;
52 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
53 WriteParam(m, p.filesystem_url());
54 WriteParam(m, p.offset());
55 WriteParam(m, p.length());
56 WriteParam(m, p.expected_modification_time());
57 break;
59 default: {
60 DCHECK(p.type() == storage::DataElement::TYPE_BLOB);
61 WriteParam(m, p.blob_uuid());
62 WriteParam(m, p.offset());
63 WriteParam(m, p.length());
64 break;
69 bool ParamTraits<storage::DataElement>::Read(const Message* m,
70 base::PickleIterator* iter,
71 param_type* r) {
72 int type;
73 if (!ReadParam(m, iter, &type))
74 return false;
75 switch (type) {
76 case storage::DataElement::TYPE_BYTES: {
77 const char* data;
78 int len;
79 if (!iter->ReadData(&data, &len))
80 return false;
81 r->SetToBytes(data, len);
82 break;
84 case storage::DataElement::TYPE_FILE: {
85 base::FilePath file_path;
86 uint64 offset, length;
87 base::Time expected_modification_time;
88 if (!ReadParam(m, iter, &file_path))
89 return false;
90 if (!ReadParam(m, iter, &offset))
91 return false;
92 if (!ReadParam(m, iter, &length))
93 return false;
94 if (!ReadParam(m, iter, &expected_modification_time))
95 return false;
96 r->SetToFilePathRange(file_path, offset, length,
97 expected_modification_time);
98 break;
100 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
101 GURL file_system_url;
102 uint64 offset, length;
103 base::Time expected_modification_time;
104 if (!ReadParam(m, iter, &file_system_url))
105 return false;
106 if (!ReadParam(m, iter, &offset))
107 return false;
108 if (!ReadParam(m, iter, &length))
109 return false;
110 if (!ReadParam(m, iter, &expected_modification_time))
111 return false;
112 r->SetToFileSystemUrlRange(file_system_url, offset, length,
113 expected_modification_time);
114 break;
116 default: {
117 DCHECK(type == storage::DataElement::TYPE_BLOB);
118 std::string blob_uuid;
119 uint64 offset, length;
120 if (!ReadParam(m, iter, &blob_uuid))
121 return false;
122 if (!ReadParam(m, iter, &offset))
123 return false;
124 if (!ReadParam(m, iter, &length))
125 return false;
126 r->SetToBlobRange(blob_uuid, offset, length);
127 break;
130 return true;
133 void ParamTraits<storage::DataElement>::Log(const param_type& p,
134 std::string* l) {
135 l->append("<storage::DataElement>");
138 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Write(
139 Message* m, const param_type& p) {
140 WriteParam(m, p.get() != NULL);
141 if (p.get()) {
142 WriteParam(m, p->http_status_code);
143 WriteParam(m, p->http_status_text);
144 WriteParam(m, p->request_headers);
145 WriteParam(m, p->response_headers);
146 WriteParam(m, p->request_headers_text);
147 WriteParam(m, p->response_headers_text);
151 bool ParamTraits<scoped_refptr<content::ResourceDevToolsInfo>>::Read(
152 const Message* m,
153 base::PickleIterator* iter,
154 param_type* r) {
155 bool has_object;
156 if (!ReadParam(m, iter, &has_object))
157 return false;
158 if (!has_object)
159 return true;
160 *r = new content::ResourceDevToolsInfo();
161 return
162 ReadParam(m, iter, &(*r)->http_status_code) &&
163 ReadParam(m, iter, &(*r)->http_status_text) &&
164 ReadParam(m, iter, &(*r)->request_headers) &&
165 ReadParam(m, iter, &(*r)->response_headers) &&
166 ReadParam(m, iter, &(*r)->request_headers_text) &&
167 ReadParam(m, iter, &(*r)->response_headers_text);
170 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Log(
171 const param_type& p, std::string* l) {
172 l->append("(");
173 if (p.get()) {
174 LogParam(p->request_headers, l);
175 l->append(", ");
176 LogParam(p->response_headers, l);
178 l->append(")");
181 void ParamTraits<net::LoadTimingInfo>::Write(
182 Message* m, const param_type& p) {
183 WriteParam(m, p.socket_log_id);
184 WriteParam(m, p.socket_reused);
185 WriteParam(m, p.request_start_time.is_null());
186 if (p.request_start_time.is_null())
187 return;
188 WriteParam(m, p.request_start_time);
189 WriteParam(m, p.request_start);
190 WriteParam(m, p.proxy_resolve_start);
191 WriteParam(m, p.proxy_resolve_end);
192 WriteParam(m, p.connect_timing.dns_start);
193 WriteParam(m, p.connect_timing.dns_end);
194 WriteParam(m, p.connect_timing.connect_start);
195 WriteParam(m, p.connect_timing.connect_end);
196 WriteParam(m, p.connect_timing.ssl_start);
197 WriteParam(m, p.connect_timing.ssl_end);
198 WriteParam(m, p.send_start);
199 WriteParam(m, p.send_end);
200 WriteParam(m, p.receive_headers_end);
203 bool ParamTraits<net::LoadTimingInfo>::Read(const Message* m,
204 base::PickleIterator* iter,
205 param_type* r) {
206 bool has_no_times;
207 if (!ReadParam(m, iter, &r->socket_log_id) ||
208 !ReadParam(m, iter, &r->socket_reused) ||
209 !ReadParam(m, iter, &has_no_times)) {
210 return false;
212 if (has_no_times)
213 return true;
215 return
216 ReadParam(m, iter, &r->request_start_time) &&
217 ReadParam(m, iter, &r->request_start) &&
218 ReadParam(m, iter, &r->proxy_resolve_start) &&
219 ReadParam(m, iter, &r->proxy_resolve_end) &&
220 ReadParam(m, iter, &r->connect_timing.dns_start) &&
221 ReadParam(m, iter, &r->connect_timing.dns_end) &&
222 ReadParam(m, iter, &r->connect_timing.connect_start) &&
223 ReadParam(m, iter, &r->connect_timing.connect_end) &&
224 ReadParam(m, iter, &r->connect_timing.ssl_start) &&
225 ReadParam(m, iter, &r->connect_timing.ssl_end) &&
226 ReadParam(m, iter, &r->send_start) &&
227 ReadParam(m, iter, &r->send_end) &&
228 ReadParam(m, iter, &r->receive_headers_end);
231 void ParamTraits<net::LoadTimingInfo>::Log(const param_type& p,
232 std::string* l) {
233 l->append("(");
234 LogParam(p.socket_log_id, l);
235 l->append(",");
236 LogParam(p.socket_reused, l);
237 l->append(",");
238 LogParam(p.request_start_time, l);
239 l->append(", ");
240 LogParam(p.request_start, l);
241 l->append(", ");
242 LogParam(p.proxy_resolve_start, l);
243 l->append(", ");
244 LogParam(p.proxy_resolve_end, l);
245 l->append(", ");
246 LogParam(p.connect_timing.dns_start, l);
247 l->append(", ");
248 LogParam(p.connect_timing.dns_end, l);
249 l->append(", ");
250 LogParam(p.connect_timing.connect_start, l);
251 l->append(", ");
252 LogParam(p.connect_timing.connect_end, l);
253 l->append(", ");
254 LogParam(p.connect_timing.ssl_start, l);
255 l->append(", ");
256 LogParam(p.connect_timing.ssl_end, l);
257 l->append(", ");
258 LogParam(p.send_start, l);
259 l->append(", ");
260 LogParam(p.send_end, l);
261 l->append(", ");
262 LogParam(p.receive_headers_end, l);
263 l->append(")");
266 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Write(
267 Message* m,
268 const param_type& p) {
269 WriteParam(m, p.get() != NULL);
270 if (p.get()) {
271 WriteParam(m, *p->elements());
272 WriteParam(m, p->identifier());
276 bool ParamTraits<scoped_refptr<content::ResourceRequestBody>>::Read(
277 const Message* m,
278 base::PickleIterator* iter,
279 param_type* r) {
280 bool has_object;
281 if (!ReadParam(m, iter, &has_object))
282 return false;
283 if (!has_object)
284 return true;
285 std::vector<storage::DataElement> elements;
286 if (!ReadParam(m, iter, &elements))
287 return false;
288 int64 identifier;
289 if (!ReadParam(m, iter, &identifier))
290 return false;
291 *r = new content::ResourceRequestBody;
292 (*r)->swap_elements(&elements);
293 (*r)->set_identifier(identifier);
294 return true;
297 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Log(
298 const param_type& p, std::string* l) {
299 l->append("<ResourceRequestBody>");
302 } // namespace IPC