| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/browser/blob/blob_data_builder.h" | 5 #include "storage/browser/blob/blob_data_builder.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "storage/browser/blob/shareable_file_reference.h" | 8 #include "storage/browser/blob/shareable_file_reference.h" |
| 9 | 9 |
| 10 namespace storage { | 10 namespace storage { |
| 11 | 11 |
| 12 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { | 12 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { |
| 13 } | 13 } |
| 14 BlobDataBuilder::~BlobDataBuilder() { | 14 BlobDataBuilder::~BlobDataBuilder() { |
| 15 } | 15 } |
| 16 | 16 |
| 17 void BlobDataBuilder::AppendData(const char* data, size_t length) { | 17 void BlobDataBuilder::AppendData(const char* data, size_t length) { |
| 18 DCHECK(length > 0); | |
| 19 scoped_ptr<DataElement> element(new DataElement()); | 18 scoped_ptr<DataElement> element(new DataElement()); |
| 20 element->SetToBytes(data, length); | 19 element->SetToBytes(data, length); |
| 21 items_.push_back(new BlobDataItem(element.Pass())); | 20 items_.push_back(new BlobDataItem(element.Pass())); |
| 22 } | 21 } |
| 23 | 22 |
| 24 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, | 23 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, |
| 25 uint64_t offset, | 24 uint64_t offset, |
| 26 uint64_t length, | 25 uint64_t length, |
| 27 const base::Time& expected_modification_time) { | 26 const base::Time& expected_modification_time) { |
| 28 DCHECK(length > 0); | |
| 29 scoped_ptr<DataElement> element(new DataElement()); | 27 scoped_ptr<DataElement> element(new DataElement()); |
| 30 element->SetToFilePathRange(file_path, offset, length, | 28 element->SetToFilePathRange(file_path, offset, length, |
| 31 expected_modification_time); | 29 expected_modification_time); |
| 32 items_.push_back( | 30 items_.push_back( |
| 33 new BlobDataItem(element.Pass(), ShareableFileReference::Get(file_path))); | 31 new BlobDataItem(element.Pass(), ShareableFileReference::Get(file_path))); |
| 34 } | 32 } |
| 35 | 33 |
| 36 void BlobDataBuilder::AppendBlob(const std::string& uuid, | 34 void BlobDataBuilder::AppendBlob(const std::string& uuid, |
| 37 uint64_t offset, | 35 uint64_t offset, |
| 38 uint64_t length) { | 36 uint64_t length) { |
| 39 DCHECK_GT(length, 0ul); | |
| 40 scoped_ptr<DataElement> element(new DataElement()); | 37 scoped_ptr<DataElement> element(new DataElement()); |
| 41 element->SetToBlobRange(uuid, offset, length); | 38 element->SetToBlobRange(uuid, offset, length); |
| 42 items_.push_back(new BlobDataItem(element.Pass())); | 39 items_.push_back(new BlobDataItem(element.Pass())); |
| 43 } | 40 } |
| 44 | 41 |
| 45 void BlobDataBuilder::AppendBlob(const std::string& uuid) { | 42 void BlobDataBuilder::AppendBlob(const std::string& uuid) { |
| 46 scoped_ptr<DataElement> element(new DataElement()); | 43 scoped_ptr<DataElement> element(new DataElement()); |
| 47 element->SetToBlob(uuid); | 44 element->SetToBlob(uuid); |
| 48 items_.push_back(new BlobDataItem(element.Pass())); | 45 items_.push_back(new BlobDataItem(element.Pass())); |
| 49 } | 46 } |
| 50 | 47 |
| 51 void BlobDataBuilder::AppendFileSystemFile( | 48 void BlobDataBuilder::AppendFileSystemFile( |
| 52 const GURL& url, | 49 const GURL& url, |
| 53 uint64_t offset, | 50 uint64_t offset, |
| 54 uint64_t length, | 51 uint64_t length, |
| 55 const base::Time& expected_modification_time) { | 52 const base::Time& expected_modification_time) { |
| 56 DCHECK(length > 0); | |
| 57 scoped_ptr<DataElement> element(new DataElement()); | 53 scoped_ptr<DataElement> element(new DataElement()); |
| 58 element->SetToFileSystemUrlRange(url, offset, length, | 54 element->SetToFileSystemUrlRange(url, offset, length, |
| 59 expected_modification_time); | 55 expected_modification_time); |
| 60 items_.push_back(new BlobDataItem(element.Pass())); | 56 items_.push_back(new BlobDataItem(element.Pass())); |
| 61 } | 57 } |
| 62 | 58 |
| 63 } // namespace storage | 59 } // namespace storage |
| OLD | NEW |