Chromium Code Reviews| 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..0b3c529cda7f9a84376d3e22f93805c731e7a103 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"; |
|
kinuko
2015/11/25 16:08:17
nit: const char kFuturePopulatingFilePath[] = ...
dmurph
2015/11/25 21:16:30
Done. I like the static class member idea.
|
| +} |
| 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,40 @@ 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(); |
| + 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, |