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

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

Issue 10861036: net: Remove UploadElement::TYPE_CHUNK (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused UploadElement::set_type() Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/urlmon_url_request.cc ('k') | net/base/upload_data.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 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 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/common_param_traits.h" 5 #include "content/public/common/common_param_traits.h"
6 6
7 #include "content/public/common/content_constants.h" 7 #include "content/public/common/content_constants.h"
8 #include "content/public/common/referrer.h" 8 #include "content/public/common/referrer.h"
9 #include "net/base/host_port_pair.h" 9 #include "net/base/host_port_pair.h"
10 #include "net/base/upload_data.h" 10 #include "net/base/upload_data.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 template <> 130 template <>
131 struct ParamTraits<net::UploadElement> { 131 struct ParamTraits<net::UploadElement> {
132 typedef net::UploadElement param_type; 132 typedef net::UploadElement param_type;
133 static void Write(Message* m, const param_type& p) { 133 static void Write(Message* m, const param_type& p) {
134 WriteParam(m, static_cast<int>(p.type())); 134 WriteParam(m, static_cast<int>(p.type()));
135 switch (p.type()) { 135 switch (p.type()) {
136 case net::UploadElement::TYPE_BYTES: { 136 case net::UploadElement::TYPE_BYTES: {
137 m->WriteData(p.bytes(), static_cast<int>(p.bytes_length())); 137 m->WriteData(p.bytes(), static_cast<int>(p.bytes_length()));
138 break; 138 break;
139 } 139 }
140 case net::UploadElement::TYPE_CHUNK: {
141 std::string chunk_length = StringPrintf(
142 "%X\r\n", static_cast<unsigned int>(p.bytes_length()));
143 std::vector<char> bytes;
144 bytes.insert(bytes.end(), chunk_length.data(),
145 chunk_length.data() + chunk_length.length());
146 const char* data = p.bytes();
147 bytes.insert(bytes.end(), data, data + p.bytes_length());
148 const char* crlf = "\r\n";
149 bytes.insert(bytes.end(), crlf, crlf + strlen(crlf));
150 if (p.is_last_chunk()) {
151 const char* end_of_data = "0\r\n\r\n";
152 bytes.insert(bytes.end(), end_of_data,
153 end_of_data + strlen(end_of_data));
154 }
155 m->WriteData(&bytes[0], static_cast<int>(bytes.size()));
156 // If this element is part of a chunk upload then send over information
157 // indicating if this is the last chunk.
158 WriteParam(m, p.is_last_chunk());
159 break;
160 }
161 default: { 140 default: {
162 DCHECK(p.type() == net::UploadElement::TYPE_FILE); 141 DCHECK(p.type() == net::UploadElement::TYPE_FILE);
163 WriteParam(m, p.file_path()); 142 WriteParam(m, p.file_path());
164 WriteParam(m, p.file_range_offset()); 143 WriteParam(m, p.file_range_offset());
165 WriteParam(m, p.file_range_length()); 144 WriteParam(m, p.file_range_length());
166 WriteParam(m, p.expected_file_modification_time()); 145 WriteParam(m, p.expected_file_modification_time());
167 break; 146 break;
168 } 147 }
169 } 148 }
170 } 149 }
171 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { 150 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
172 int type; 151 int type;
173 if (!ReadParam(m, iter, &type)) 152 if (!ReadParam(m, iter, &type))
174 return false; 153 return false;
175 switch (type) { 154 switch (type) {
176 case net::UploadElement::TYPE_BYTES: { 155 case net::UploadElement::TYPE_BYTES: {
177 const char* data; 156 const char* data;
178 int len; 157 int len;
179 if (!m->ReadData(iter, &data, &len)) 158 if (!m->ReadData(iter, &data, &len))
180 return false; 159 return false;
181 r->SetToBytes(data, len); 160 r->SetToBytes(data, len);
182 break; 161 break;
183 } 162 }
184 case net::UploadElement::TYPE_CHUNK: {
185 const char* data;
186 int len;
187 if (!m->ReadData(iter, &data, &len))
188 return false;
189 r->SetToBytes(data, len);
190 // If this element is part of a chunk upload then we need to explicitly
191 // set the type of the element and whether it is the last chunk.
192 bool is_last_chunk = false;
193 if (!ReadParam(m, iter, &is_last_chunk))
194 return false;
195 r->set_type(net::UploadElement::TYPE_CHUNK);
196 r->set_is_last_chunk(is_last_chunk);
197 break;
198 }
199 default: { 163 default: {
200 DCHECK(type == net::UploadElement::TYPE_FILE); 164 DCHECK(type == net::UploadElement::TYPE_FILE);
201 FilePath file_path; 165 FilePath file_path;
202 uint64 offset, length; 166 uint64 offset, length;
203 base::Time expected_modification_time; 167 base::Time expected_modification_time;
204 if (!ReadParam(m, iter, &file_path)) 168 if (!ReadParam(m, iter, &file_path))
205 return false; 169 return false;
206 if (!ReadParam(m, iter, &offset)) 170 if (!ReadParam(m, iter, &offset))
207 return false; 171 return false;
208 if (!ReadParam(m, iter, &length)) 172 if (!ReadParam(m, iter, &length))
(...skipping 12 matching lines...) Expand all
221 } 185 }
222 }; 186 };
223 187
224 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, 188 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m,
225 const param_type& p) { 189 const param_type& p) {
226 WriteParam(m, p.get() != NULL); 190 WriteParam(m, p.get() != NULL);
227 if (p) { 191 if (p) {
228 WriteParam(m, *p->elements()); 192 WriteParam(m, *p->elements());
229 WriteParam(m, p->identifier()); 193 WriteParam(m, p->identifier());
230 WriteParam(m, p->is_chunked()); 194 WriteParam(m, p->is_chunked());
195 WriteParam(m, p->last_chunk_appended());
231 } 196 }
232 } 197 }
233 198
234 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, 199 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m,
235 PickleIterator* iter, 200 PickleIterator* iter,
236 param_type* r) { 201 param_type* r) {
237 bool has_object; 202 bool has_object;
238 if (!ReadParam(m, iter, &has_object)) 203 if (!ReadParam(m, iter, &has_object))
239 return false; 204 return false;
240 if (!has_object) 205 if (!has_object)
241 return true; 206 return true;
242 std::vector<net::UploadElement> elements; 207 std::vector<net::UploadElement> elements;
243 if (!ReadParam(m, iter, &elements)) 208 if (!ReadParam(m, iter, &elements))
244 return false; 209 return false;
245 int64 identifier; 210 int64 identifier;
246 if (!ReadParam(m, iter, &identifier)) 211 if (!ReadParam(m, iter, &identifier))
247 return false; 212 return false;
248 bool is_chunked = false; 213 bool is_chunked = false;
249 if (!ReadParam(m, iter, &is_chunked)) 214 if (!ReadParam(m, iter, &is_chunked))
250 return false; 215 return false;
216 bool last_chunk_appended = false;
217 if (!ReadParam(m, iter, &last_chunk_appended))
218 return false;
251 *r = new net::UploadData; 219 *r = new net::UploadData;
252 (*r)->swap_elements(&elements); 220 (*r)->swap_elements(&elements);
253 (*r)->set_identifier(identifier); 221 (*r)->set_identifier(identifier);
254 (*r)->set_is_chunked(is_chunked); 222 (*r)->set_is_chunked(is_chunked);
223 (*r)->set_last_chunk_appended(last_chunk_appended);
255 return true; 224 return true;
256 } 225 }
257 226
258 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, 227 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p,
259 std::string* l) { 228 std::string* l) {
260 l->append("<net::UploadData>"); 229 l->append("<net::UploadData>");
261 } 230 }
262 231
263 template <> 232 template <>
264 struct ParamTraits<webkit_glue::ResourceRequestBody::Element> { 233 struct ParamTraits<webkit_glue::ResourceRequestBody::Element> {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 591 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
623 #include "content/public/common/common_param_traits_macros.h" 592 #include "content/public/common/common_param_traits_macros.h"
624 } // namespace IPC 593 } // namespace IPC
625 594
626 // Generate param traits log methods. 595 // Generate param traits log methods.
627 #include "ipc/param_traits_log_macros.h" 596 #include "ipc/param_traits_log_macros.h"
628 namespace IPC { 597 namespace IPC {
629 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 598 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
630 #include "content/public/common/common_param_traits_macros.h" 599 #include "content/public/common/common_param_traits_macros.h"
631 } // namespace IPC 600 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome_frame/urlmon_url_request.cc ('k') | net/base/upload_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698