| 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 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 7 | 8 |
| 8 namespace storage { | 9 namespace storage { |
| 9 | 10 |
| 10 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { | 11 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { |
| 11 } | 12 } |
| 12 BlobDataBuilder::~BlobDataBuilder() { | 13 BlobDataBuilder::~BlobDataBuilder() { |
| 13 } | 14 } |
| 14 | 15 |
| 15 void BlobDataBuilder::AppendData(const char* data, size_t length) { | 16 void BlobDataBuilder::AppendData(const char* data, size_t length) { |
| 16 DCHECK(length > 0); | 17 DCHECK(length > 0); |
| 17 scoped_ptr<DataElement> element(new DataElement()); | 18 scoped_ptr<DataElement> element(new DataElement()); |
| 18 element->SetToBytes(data, length); | 19 element->SetToBytes(data, length); |
| 19 items_.push_back(new BlobDataItem(element.Pass())); | 20 items_.push_back(new BlobDataItem(element.Pass())); |
| 20 } | 21 } |
| 21 | 22 |
| 22 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, | 23 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, |
| 23 uint64 offset, | 24 uint64_t offset, |
| 24 uint64 length, | 25 uint64_t length, |
| 25 const base::Time& expected_modification_time) { | 26 const base::Time& expected_modification_time) { |
| 26 DCHECK(length > 0); | 27 DCHECK(length > 0); |
| 27 scoped_ptr<DataElement> element(new DataElement()); | 28 scoped_ptr<DataElement> element(new DataElement()); |
| 28 element->SetToFilePathRange(file_path, offset, length, | 29 element->SetToFilePathRange(file_path, offset, length, |
| 29 expected_modification_time); | 30 expected_modification_time); |
| 30 items_.push_back(new BlobDataItem(element.Pass())); | 31 items_.push_back(new BlobDataItem(element.Pass())); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void BlobDataBuilder::AppendFile( | 34 void BlobDataBuilder::AppendFile( |
| 34 const base::FilePath& file_path, | 35 const base::FilePath& file_path, |
| 35 uint64 offset, | 36 uint64_t offset, |
| 36 uint64 length, | 37 uint64_t length, |
| 37 const base::Time& expected_modification_time, | 38 const base::Time& expected_modification_time, |
| 38 scoped_refptr<ShareableFileReference> shareable_file) { | 39 scoped_refptr<ShareableFileReference> shareable_file) { |
| 39 DCHECK(length > 0); | 40 DCHECK(length > 0); |
| 40 scoped_ptr<DataElement> element(new DataElement()); | 41 scoped_ptr<DataElement> element(new DataElement()); |
| 41 element->SetToFilePathRange(file_path, offset, length, | 42 element->SetToFilePathRange(file_path, offset, length, |
| 42 expected_modification_time); | 43 expected_modification_time); |
| 43 items_.push_back(new BlobDataItem(element.Pass(), shareable_file)); | 44 items_.push_back(new BlobDataItem(element.Pass(), shareable_file)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void BlobDataBuilder::AppendBlob(const std::string& uuid, | 47 void BlobDataBuilder::AppendBlob(const std::string& uuid, |
| 47 uint64 offset, | 48 uint64_t offset, |
| 48 uint64 length) { | 49 uint64_t length) { |
| 49 DCHECK_GT(length, 0ul); | 50 DCHECK_GT(length, 0ul); |
| 50 scoped_ptr<DataElement> element(new DataElement()); | 51 scoped_ptr<DataElement> element(new DataElement()); |
| 51 element->SetToBlobRange(uuid, offset, length); | 52 element->SetToBlobRange(uuid, offset, length); |
| 52 items_.push_back(new BlobDataItem(element.Pass())); | 53 items_.push_back(new BlobDataItem(element.Pass())); |
| 53 } | 54 } |
| 54 | 55 |
| 56 void BlobDataBuilder::AppendBlob(const std::string& uuid) { |
| 57 scoped_ptr<DataElement> element(new DataElement()); |
| 58 element->SetToBlob(uuid); |
| 59 items_.push_back(new BlobDataItem(element.Pass())); |
| 60 } |
| 61 |
| 55 void BlobDataBuilder::AppendFileSystemFile( | 62 void BlobDataBuilder::AppendFileSystemFile( |
| 56 const GURL& url, | 63 const GURL& url, |
| 57 uint64 offset, | 64 uint64_t offset, |
| 58 uint64 length, | 65 uint64_t length, |
| 59 const base::Time& expected_modification_time) { | 66 const base::Time& expected_modification_time) { |
| 60 DCHECK(length > 0); | 67 DCHECK(length > 0); |
| 61 scoped_ptr<DataElement> element(new DataElement()); | 68 scoped_ptr<DataElement> element(new DataElement()); |
| 62 element->SetToFileSystemUrlRange(url, offset, length, | 69 element->SetToFileSystemUrlRange(url, offset, length, |
| 63 expected_modification_time); | 70 expected_modification_time); |
| 64 items_.push_back(new BlobDataItem(element.Pass())); | 71 items_.push_back(new BlobDataItem(element.Pass())); |
| 65 } | 72 } |
| 66 | 73 |
| 67 size_t BlobDataBuilder::GetMemoryUsage() const { | |
| 68 int64 memory = 0; | |
| 69 for (const auto& data_item : items_) { | |
| 70 if (data_item->type() == DataElement::TYPE_BYTES) | |
| 71 memory += data_item->length(); | |
| 72 } | |
| 73 return memory; | |
| 74 } | |
| 75 | |
| 76 scoped_ptr<BlobDataSnapshot> BlobDataBuilder::BuildSnapshot() { | |
| 77 return scoped_ptr<BlobDataSnapshot>(new BlobDataSnapshot(uuid_, content_type_, | |
| 78 content_disposition_, | |
| 79 items_)).Pass(); | |
| 80 } | |
| 81 | |
| 82 } // namespace storage | 74 } // namespace storage |
| OLD | NEW |