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

Side by Side Diff: content/common/resource_request_body.cc

Issue 1987053002: Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/data/test_body/g Created 4 years, 7 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 | « content/common/resource_request_body.h ('k') | content/content_renderer.gypi » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/resource_request_body.h" 5 #include "content/common/resource_request_body.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/common/page_state_serialization.h" 8 #include "content/common/page_state_serialization.h"
9 9
10 using blink::WebHTTPBody; 10 using blink::WebHTTPBody;
11 using blink::WebString; 11 using blink::WebString;
12 12
13 namespace content { 13 namespace content {
14 14
15 ResourceRequestBody::ResourceRequestBody() 15 ResourceRequestBody::ResourceRequestBody()
16 : identifier_(0) { 16 : identifier_(0) {
17 } 17 }
18 18
19 void ResourceRequestBody::AppendExplodedHTTPBodyElement(
20 const ExplodedHttpBodyElement& element) {
21 // Note: this code is based on GetRequestBodyForWebURLRequest (in
22 // web_url_request_util.cc). The other function transforms a
23 // blink::WebHTTPBody into a ResourceRequestBody. This function is used to
24 // transform an ExplodedHttpBody into a ResourceRequestBody.
25 switch (element.type) {
26 case WebHTTPBody::Element::TypeData:
27 if (!element.data.empty()) {
28 // Blink sometimes gives empty data to append. These aren't
29 // necessary so they are just optimized out here.
30 AppendBytes(element.data.data(), static_cast<int>(element.data.size()));
31 }
32 break;
33 case WebHTTPBody::Element::TypeFile:
34 if (element.file_length == -1) {
35 AppendFileRange(
36 base::FilePath::FromUTF16Unsafe(element.file_path.string()), 0,
37 std::numeric_limits<uint64_t>::max(), base::Time());
38 } else {
39 AppendFileRange(
40 base::FilePath::FromUTF16Unsafe(element.file_path.string()),
41 static_cast<uint64_t>(element.file_start),
42 static_cast<uint64_t>(element.file_length),
43 base::Time::FromDoubleT(element.file_modification_time));
44 }
45 break;
46 case WebHTTPBody::Element::TypeFileSystemURL: {
47 GURL file_system_url = element.filesystem_url;
48 DCHECK(file_system_url.SchemeIsFileSystem());
49 AppendFileSystemFileRange(
50 file_system_url, static_cast<uint64_t>(element.file_start),
51 static_cast<uint64_t>(element.file_length),
52 base::Time::FromDoubleT(element.file_modification_time));
53 break;
54 }
55 case WebHTTPBody::Element::TypeBlob:
56 AppendBlob(element.blob_uuid);
57 break;
58 default:
59 NOTREACHED();
60 }
61 }
62
63 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { 19 void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) {
64 if (bytes_len > 0) { 20 if (bytes_len > 0) {
65 elements_.push_back(Element()); 21 elements_.push_back(Element());
66 elements_.back().SetToBytes(bytes, bytes_len); 22 elements_.back().SetToBytes(bytes, bytes_len);
67 } 23 }
68 } 24 }
69 25
70 void ResourceRequestBody::AppendFileRange( 26 void ResourceRequestBody::AppendFileRange(
71 const base::FilePath& file_path, 27 const base::FilePath& file_path,
72 uint64_t offset, 28 uint64_t offset,
(...skipping 16 matching lines...) Expand all
89 const base::Time& expected_modification_time) { 45 const base::Time& expected_modification_time) {
90 elements_.push_back(Element()); 46 elements_.push_back(Element());
91 elements_.back().SetToFileSystemUrlRange(url, offset, length, 47 elements_.back().SetToFileSystemUrlRange(url, offset, length,
92 expected_modification_time); 48 expected_modification_time);
93 } 49 }
94 50
95 ResourceRequestBody::~ResourceRequestBody() { 51 ResourceRequestBody::~ResourceRequestBody() {
96 } 52 }
97 53
98 } // namespace content 54 } // namespace content
OLDNEW
« no previous file with comments | « content/common/resource_request_body.h ('k') | content/content_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698