Index: content/browser/loader/upload_data_stream_builder.cc |
diff --git a/webkit/glue/resource_request_body.cc b/content/browser/loader/upload_data_stream_builder.cc |
similarity index 63% |
rename from webkit/glue/resource_request_body.cc |
rename to content/browser/loader/upload_data_stream_builder.cc |
index 2bde26ddb16091ce9ef64d4cb17bf8387b36a17b..c8feb83729a074d247eb2a869ac691ace402cc66 100644 |
--- a/webkit/glue/resource_request_body.cc |
+++ b/content/browser/loader/upload_data_stream_builder.cc |
@@ -1,8 +1,8 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2013 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 "content/browser/loader/upload_data_stream_builder.h" |
#include "base/logging.h" |
#include "net/base/upload_bytes_element_reader.h" |
@@ -10,12 +10,13 @@ |
#include "net/base/upload_file_element_reader.h" |
#include "webkit/browser/blob/blob_storage_controller.h" |
#include "webkit/browser/fileapi/upload_file_system_file_element_reader.h" |
+#include "webkit/common/resource_request_body.h" |
using webkit_blob::BlobData; |
using webkit_blob::BlobStorageController; |
+using webkit_glue::ResourceRequestBody; |
-namespace webkit_glue { |
- |
+namespace content { |
namespace { |
// A subclass of net::UploadBytesElementReader which owns ResourceRequestBody. |
@@ -61,50 +62,47 @@ class FileElementReader : public net::UploadFileElementReader { |
DISALLOW_COPY_AND_ASSIGN(FileElementReader); |
}; |
-} // namespace |
- |
-ResourceRequestBody::ResourceRequestBody() : identifier_(0) {} |
+void ResolveBlobReference( |
+ ResourceRequestBody* body, |
+ webkit_blob::BlobStorageController* blob_controller, |
+ const GURL& blob_url, |
+ std::vector<const ResourceRequestBody::Element*>* resolved_elements) { |
+ DCHECK(blob_controller); |
+ BlobData* blob_data = blob_controller->GetBlobDataFromUrl(blob_url); |
+ DCHECK(blob_data); |
+ if (!blob_data) |
+ return; |
-void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) { |
- if (bytes_len > 0) { |
- elements_.push_back(Element()); |
- elements_.back().SetToBytes(bytes, bytes_len); |
- } |
-} |
+ // If there is no element in the referred blob data, just return. |
+ if (blob_data->items().empty()) |
+ return; |
-void ResourceRequestBody::AppendFileRange( |
- const base::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); |
-} |
+ // Ensure the blob and any attached shareable files survive until |
+ // upload completion. |
+ body->SetUserData(blob_data, new base::UserDataAdapter<BlobData>(blob_data)); |
-void ResourceRequestBody::AppendBlob(const GURL& blob_url) { |
- elements_.push_back(Element()); |
- elements_.back().SetToBlobUrl(blob_url); |
+ // Append the elements in the referred blob data. |
+ for (size_t i = 0; i < blob_data->items().size(); ++i) { |
+ const BlobData::Item& item = blob_data->items().at(i); |
+ DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); |
+ resolved_elements->push_back(&item); |
+ } |
} |
-void ResourceRequestBody::AppendFileSystemFileRange( |
- const GURL& url, uint64 offset, uint64 length, |
- const base::Time& expected_modification_time) { |
- elements_.push_back(Element()); |
- elements_.back().SetToFileSystemUrlRange(url, offset, length, |
- expected_modification_time); |
-} |
+} // namespace |
-net::UploadDataStream* |
-ResourceRequestBody::ResolveElementsAndCreateUploadDataStream( |
+scoped_ptr<net::UploadDataStream> UploadDataStreamBuilder::Build( |
+ ResourceRequestBody* body, |
BlobStorageController* blob_controller, |
fileapi::FileSystemContext* file_system_context, |
base::TaskRunner* file_task_runner) { |
// Resolve all blob elements. |
- std::vector<const Element*> resolved_elements; |
- for (size_t i = 0; i < elements_.size(); ++i) { |
- const Element& element = elements_[i]; |
- if (element.type() == Element::TYPE_BLOB) { |
- ResolveBlobReference(blob_controller, element.url(), &resolved_elements); |
+ std::vector<const ResourceRequestBody::Element*> resolved_elements; |
+ for (size_t i = 0; i < body->elements()->size(); ++i) { |
+ const ResourceRequestBody::Element& element = (*body->elements())[i]; |
+ if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) { |
+ ResolveBlobReference(body, blob_controller, element.url(), |
+ &resolved_elements); |
} else { |
// No need to resolve, just append the element. |
resolved_elements.push_back(&element); |
@@ -113,16 +111,16 @@ ResourceRequestBody::ResolveElementsAndCreateUploadDataStream( |
ScopedVector<net::UploadElementReader> element_readers; |
for (size_t i = 0; i < resolved_elements.size(); ++i) { |
- const Element& element = *resolved_elements[i]; |
+ const ResourceRequestBody::Element& element = *resolved_elements[i]; |
switch (element.type()) { |
- case Element::TYPE_BYTES: |
- element_readers.push_back(new BytesElementReader(this, element)); |
+ case ResourceRequestBody::Element::TYPE_BYTES: |
+ element_readers.push_back(new BytesElementReader(body, element)); |
break; |
- case Element::TYPE_FILE: |
+ case ResourceRequestBody::Element::TYPE_FILE: |
element_readers.push_back( |
- new FileElementReader(this, file_task_runner, element)); |
+ new FileElementReader(body, file_task_runner, element)); |
break; |
- case Element::TYPE_FILE_FILESYSTEM: |
+ case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: |
element_readers.push_back( |
new fileapi::UploadFileSystemFileElementReader( |
file_system_context, |
@@ -131,44 +129,18 @@ ResourceRequestBody::ResolveElementsAndCreateUploadDataStream( |
element.length(), |
element.expected_modification_time())); |
break; |
- case Element::TYPE_BLOB: |
+ case ResourceRequestBody::Element::TYPE_BLOB: |
// Blob elements should be resolved beforehand. |
NOTREACHED(); |
break; |
- case Element::TYPE_UNKNOWN: |
+ case ResourceRequestBody::Element::TYPE_UNKNOWN: |
NOTREACHED(); |
break; |
} |
} |
- return new net::UploadDataStream(&element_readers, identifier_); |
-} |
- |
-ResourceRequestBody::~ResourceRequestBody() {} |
- |
-void ResourceRequestBody::ResolveBlobReference( |
- webkit_blob::BlobStorageController* blob_controller, |
- const GURL& blob_url, |
- std::vector<const Element*>* resolved_elements) { |
- DCHECK(blob_controller); |
- BlobData* blob_data = blob_controller->GetBlobDataFromUrl(blob_url); |
- DCHECK(blob_data); |
- if (!blob_data) |
- return; |
- |
- // If there is no element in the referred blob data, just return. |
- if (blob_data->items().empty()) |
- return; |
- |
- // Ensure the blob and any attached shareable files survive until |
- // upload completion. |
- SetUserData(blob_data, new base::UserDataAdapter<BlobData>(blob_data)); |
- // Append the elements in the referred blob data. |
- for (size_t i = 0; i < blob_data->items().size(); ++i) { |
- const BlobData::Item& item = blob_data->items().at(i); |
- DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); |
- resolved_elements->push_back(&item); |
- } |
+ return make_scoped_ptr( |
+ new net::UploadDataStream(&element_readers, body->identifier())); |
} |
-} // namespace webkit_glue |
+} // namespace content |