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 2ebfe89e454b094b5bab1b27ca80013021351831..46a300f3502557c613129c9a603fcf240859cc59 100644 |
--- a/storage/browser/blob/blob_data_builder.cc |
+++ b/storage/browser/blob/blob_data_builder.cc |
@@ -11,6 +11,9 @@ |
#include "storage/browser/blob/shareable_file_reference.h" |
namespace storage { |
+namespace { |
+const char* kFuturePopulatingFilePath = "kFakeFilenameToBeChanged"; |
+} |
BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { |
} |
@@ -65,6 +68,7 @@ bool BlobDataBuilder::PopulateFutureData(size_t index, |
const char* data, |
size_t offset, |
size_t length) { |
+ DCHECK_LT(index, items_.size()); |
DCHECK(data); |
DataElement* element = items_.at(index)->data_element_ptr(); |
@@ -93,6 +97,43 @@ bool BlobDataBuilder::PopulateFutureData(size_t index, |
return true; |
} |
+size_t BlobDataBuilder::AppendFutureFile(uint64_t offset, uint64_t length) { |
+ CHECK_NE(length, 0ull); |
+ scoped_ptr<DataElement> element(new DataElement()); |
+ element->SetToFilePathRange( |
+ base::FilePath::FromUTF8Unsafe(std::string(kFuturePopulatingFilePath)), |
+ offset, length, base::Time()); |
+ items_.push_back(new BlobDataItem(element.Pass())); |
+ return items_.size() - 1; |
+} |
+ |
+bool BlobDataBuilder::PopulateFutureFile( |
+ size_t index, |
+ const scoped_refptr<ShareableFileReference>& file_reference, |
+ const base::Time& expected_modification_time) { |
+ DCHECK_LT(index, items_.size()); |
+ DataElement* old_element = items_.at(index)->data_element_ptr(); |
+ |
+ if (old_element->type() != DataElement::TYPE_FILE) { |
+ DVLOG(1) << "Invalid item type."; |
+ return false; |
+ } else if (old_element->path().AsUTF8Unsafe() != |
+ std::string(kFuturePopulatingFilePath)) { |
+ DVLOG(1) << "Item not created by AppendFutureFile"; |
+ return false; |
+ } |
+ uint64_t length = old_element->length(); |
+ uint64_t offset = old_element->offset(); |
+ // We null this out as it is about to be invalid after we set the vector item |
+ // to a different BlobDataItem |
+ old_element = nullptr; |
michaeln
2015/11/21 00:59:46
Not sure you need to do this or comment about it,
dmurph
2015/11/23 20:07:02
Done.
|
+ scoped_ptr<DataElement> element(new DataElement()); |
+ element->SetToFilePathRange(file_reference->path(), offset, length, |
+ expected_modification_time); |
+ items_[index] = new BlobDataItem(element.Pass(), file_reference); |
+ return true; |
+} |
+ |
void BlobDataBuilder::AppendFile(const base::FilePath& file_path, |
uint64_t offset, |
uint64_t length, |