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

Side by Side Diff: content/public/common/page_state.cc

Issue 1987053002: Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing on top of ToT... 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/public/common/page_state.h" 5 #include "content/public/common/page_state.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/nullable_string16.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "content/common/page_state_serialization.h" 12 #include "content/common/page_state_serialization.h"
12 13
13 namespace content { 14 namespace content {
14 namespace { 15 namespace {
15 16
16 base::NullableString16 ToNullableString16(const std::string& utf8) { 17 base::NullableString16 ToNullableString16(const std::string& utf8) {
17 return base::NullableString16(base::UTF8ToUTF16(utf8), false); 18 return base::NullableString16(base::UTF8ToUTF16(utf8), false);
18 } 19 }
19 20
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const char* optional_body_data, 81 const char* optional_body_data,
81 const base::FilePath* optional_body_file_path) { 82 const base::FilePath* optional_body_file_path) {
82 ExplodedPageState state; 83 ExplodedPageState state;
83 84
84 state.top.url_string = ToNullableString16(url.possibly_invalid_spec()); 85 state.top.url_string = ToNullableString16(url.possibly_invalid_spec());
85 86
86 if (optional_body_data || optional_body_file_path) { 87 if (optional_body_data || optional_body_file_path) {
87 state.top.http_body.is_null = false; 88 state.top.http_body.is_null = false;
88 if (optional_body_data) { 89 if (optional_body_data) {
89 ExplodedHttpBodyElement element; 90 ExplodedHttpBodyElement element;
90 element.type = blink::WebHTTPBody::Element::TypeData; 91 std::string body_data(optional_body_data);
91 element.data = optional_body_data; 92 element.SetToBytes(body_data.data(), body_data.size());
92 state.top.http_body.elements.push_back(element); 93 state.top.http_body.elements.push_back(element);
93 } 94 }
94 if (optional_body_file_path) { 95 if (optional_body_file_path) {
95 ExplodedHttpBodyElement element; 96 ExplodedHttpBodyElement element;
96 element.type = blink::WebHTTPBody::Element::TypeFile; 97 element.SetToFilePath(*optional_body_file_path);
97 element.file_path = 98 state.referenced_files.push_back(base::NullableString16(
98 ToNullableString16(optional_body_file_path->AsUTF8Unsafe()); 99 optional_body_file_path->AsUTF16Unsafe(), false));
99 state.top.http_body.elements.push_back(element);
100 state.referenced_files.push_back(element.file_path);
101 } 100 }
102 state.top.http_body.contains_passwords = 101 state.top.http_body.contains_passwords =
103 body_contains_password_data; 102 body_contains_password_data;
104 } 103 }
105 104
106 return ToPageState(state); 105 return ToPageState(state);
107 } 106 }
108 107
109 PageState::PageState() { 108 PageState::PageState() {
110 } 109 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 164 }
166 165
167 PageState::PageState(const std::string& data) 166 PageState::PageState(const std::string& data)
168 : data_(data) { 167 : data_(data) {
169 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass 168 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass
170 // bogus encoded data to CreateFromEncodedData. 169 // bogus encoded data to CreateFromEncodedData.
171 //DCHECK(IsValid()); 170 //DCHECK(IsValid());
172 } 171 }
173 172
174 } // namespace content 173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698