Index: webkit/glue/resource_request_body.cc |
diff --git a/webkit/glue/resource_request_body.cc b/webkit/glue/resource_request_body.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cbd49f5062cfe01c07440cb569cedb3e9374e6f7 |
--- /dev/null |
+++ b/webkit/glue/resource_request_body.cc |
@@ -0,0 +1,75 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/glue/resource_request_body.h" |
+ |
+#include "base/logging.h" |
+#include "net/base/upload_data.h" |
+ |
+namespace webkit_glue { |
+ |
+ResourceRequestBody::Element::Element() |
+ : type_(TYPE_BYTES), |
+ bytes_start_(NULL), |
+ bytes_length_(0), |
+ file_range_offset_(0), |
+ file_range_length_(kuint64max) { |
+} |
+ |
+ResourceRequestBody::Element::~Element() {} |
+ |
+ResourceRequestBody::ResourceRequestBody() : identifier_(0) {} |
+ |
+void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
+ if (bytes_len > 0) { |
+ elements_.push_back(Element()); |
+ elements_.back().SetToBytes(bytes, bytes_len); |
+ } |
+} |
+ |
+void ResourceRequestBody::AppendFileRange( |
+ const FilePath& file_path, |
+ uint64 offset, uint64 length, |
+ const base::Time& expected_modification_time) { |
+ elements_.push_back(Element()); |
+ elements_.back().SetToFilePathRange(file_path, offset, length, |
+ expected_modification_time); |
+} |
+ |
+void ResourceRequestBody::AppendBlob(const GURL& blob_url) { |
+ elements_.push_back(Element()); |
+ elements_.back().SetToBlobUrl(blob_url); |
+} |
+ |
+void ResourceRequestBody::PopulateUploadData( |
+ net::UploadData* upload_data) { |
+ DCHECK(upload_data); |
+ DCHECK(!upload_data->is_chunked()); |
+ upload_data->SetUserData( |
darin (slow to review)
2012/08/15 17:49:55
Oh, I see! You should add a comment about how thi
kinuko
2012/08/16 08:14:59
Done.
|
+ this, new base::UserDataAdapter<ResourceRequestBody>(this)); |
+ std::vector<net::UploadData::Element>* uploads = |
+ upload_data->elements_mutable(); |
+ for (size_t i = 0; i < elements_.size(); ++i) { |
+ const Element& element = elements_[i]; |
+ if (element.type() == TYPE_BYTES) { |
+ uploads->push_back(net::UploadData::Element()); |
+ uploads->back().SetToSharedBytes(element.bytes(), |
+ element.bytes_length()); |
+ continue; |
+ } |
+ |
+ DCHECK(element.type() == TYPE_FILE); |
+ uploads->push_back(net::UploadData::Element()); |
+ uploads->back().SetToFilePathRange( |
+ element.file_path(), |
+ element.file_range_offset(), |
+ element.file_range_length(), |
+ element.expected_file_modification_time()); |
+ } |
+ upload_data->set_identifier(identifier_); |
+} |
+ |
+ResourceRequestBody::~ResourceRequestBody() {} |
+ |
+} // namespace webkit_glue |