Index: storage/browser/blob/blob_data_builder.cc |
diff --git a/storage/browser/blob/blob_data_builder.cc b/storage/browser/blob/blob_data_builder.cc |
index 94fb9e50388633ba5bfcff901338603efc5039b6..5a3a3f0fb2d1c78b8d3ca3d41e02fa858da85c82 100644 |
--- a/storage/browser/blob/blob_data_builder.cc |
+++ b/storage/browser/blob/blob_data_builder.cc |
@@ -15,6 +15,44 @@ BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { |
BlobDataBuilder::~BlobDataBuilder() { |
} |
+void BlobDataBuilder::AppendDataElement(const DataElement& ipc_data) { |
+ scoped_refptr<BlobDataItem> blob_item; |
+ |
+ uint64 length = ipc_data.length(); |
+ scoped_ptr<DataElement> element(new DataElement()); |
+ switch (ipc_data.type()) { |
+ case DataElement::TYPE_BYTES: |
+ DCHECK(!ipc_data.offset()); |
+ element->SetToBytes(ipc_data.bytes(), length); |
+ blob_item = new BlobDataItem(element.Pass()); |
+ break; |
+ case DataElement::TYPE_FILE: |
+ element->SetToFilePathRange(ipc_data.path(), ipc_data.offset(), length, |
+ ipc_data.expected_modification_time()); |
+ blob_item = new BlobDataItem( |
+ element.Pass(), ShareableFileReference::Get(ipc_data.path())); |
+ break; |
+ case DataElement::TYPE_FILE_FILESYSTEM: |
+ element->SetToFileSystemUrlRange(ipc_data.filesystem_url(), |
+ ipc_data.offset(), length, |
+ ipc_data.expected_modification_time()); |
+ blob_item = new BlobDataItem(element.Pass()); |
+ break; |
+ case DataElement::TYPE_BLOB: |
+ // This is a temporary item that will be deconstructed later. |
+ element->SetToBlobRange(ipc_data.blob_uuid(), ipc_data.offset(), |
+ ipc_data.length()); |
+ blob_item = new BlobDataItem(element.Pass()); |
+ break; |
+ case DataElement::TYPE_BYTES_DESCRIPTION: |
+ case DataElement::TYPE_UNKNOWN: |
+ case DataElement::TYPE_DISK_CACHE_ENTRY: // This type can't be sent by IPC. |
+ NOTREACHED(); |
+ break; |
+ } |
+ items_.push_back(blob_item.Pass()); |
+} |
+ |
void BlobDataBuilder::AppendData(const char* data, size_t length) { |
if (!length) |
return; |
@@ -23,6 +61,40 @@ void BlobDataBuilder::AppendData(const char* data, size_t length) { |
items_.push_back(new BlobDataItem(element.Pass())); |
} |
+void BlobDataBuilder::AppendFutureData(size_t length) { |
+ if (!length) |
+ return; |
+ scoped_ptr<DataElement> element(new DataElement()); |
+ element->SetToBytesDescription(length); |
+ items_.push_back(new BlobDataItem(element.Pass())); |
+} |
+ |
+bool BlobDataBuilder::PopulateFutureData(size_t index, |
+ const char* data, |
+ size_t offset, |
+ size_t length) { |
+ if (!length) |
+ return true; |
+ if (!data) |
+ return false; |
+ auto& item = items_.at(index); |
+ DataElement* element = item->data_element_ptr(); |
+ // On the first call, we are description, and allocate then. |
+ if (element->type() == DataElement::TYPE_BYTES_DESCRIPTION) { |
+ element->SetToAllocatedBytes(element->length()); |
+ } |
+ if (element->type() != DataElement::TYPE_BYTES) { |
+ LOG(ERROR) << "Invalid item type."; |
+ return false; |
+ } |
+ if (offset + length > element->length()) { |
+ LOG(ERROR) << "Invalid offset or length."; |
+ return false; |
+ } |
+ std::memcpy(element->mutable_bytes() + offset, data, length); |
+ return true; |
+} |
+ |
void BlobDataBuilder::AppendFile(const base::FilePath& file_path, |
uint64_t offset, |
uint64_t length, |
@@ -73,4 +145,22 @@ void BlobDataBuilder::AppendDiskCacheEntry( |
disk_cache_stream_index)); |
} |
+void BlobDataBuilder::Clear() { |
+ items_.clear(); |
+ content_disposition_.clear(); |
+ content_type_.clear(); |
+ uuid_.clear(); |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, const BlobDataBuilder& x) { |
+ os << "<BlobDataBuilder>{uuid: " << x.uuid() |
+ << ", content_type: " << x.content_type_ |
+ << ", content_disposition: " << x.content_disposition_ << ", items: ["; |
+ for (const auto& item : x.items_) { |
+ os << *item << ", "; |
+ } |
+ os << "]}"; |
+ return os; |
+} |
+ |
} // namespace storage |