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" |
8 #include "storage/browser/blob/blob_storage_context.h" | |
7 | 9 |
8 namespace storage { | 10 namespace storage { |
9 | 11 |
12 BlobDataBuilder* BlobDataBuilder::Create(const std::string& uuid) { | |
13 return new BlobDataBuilder(uuid); | |
14 } | |
10 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { | 15 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { |
11 } | 16 } |
12 BlobDataBuilder::~BlobDataBuilder() { | 17 BlobDataBuilder::~BlobDataBuilder() { |
13 } | 18 } |
14 | 19 |
15 void BlobDataBuilder::AppendData(const char* data, size_t length) { | 20 BlobDataBuilder* BlobDataBuilder::AppendData(const char* data, size_t length) { |
16 DCHECK(length > 0); | 21 DCHECK(length > 0); |
17 scoped_ptr<DataElement> element(new DataElement()); | 22 scoped_ptr<DataElement> element(new DataElement()); |
18 element->SetToBytes(data, length); | 23 element->SetToBytes(data, length); |
19 items_.push_back(new BlobDataItem(element.Pass())); | 24 items_.push_back(new BlobDataItem(element.Pass())); |
25 return this; | |
20 } | 26 } |
21 | 27 |
22 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, | 28 BlobDataBuilder* BlobDataBuilder::AppendFile( |
23 uint64 offset, | 29 const base::FilePath& file_path, |
24 uint64 length, | 30 uint64 offset, |
25 const base::Time& expected_modification_time) { | 31 uint64 length, |
32 const base::Time& expected_modification_time) { | |
26 DCHECK(length > 0); | 33 DCHECK(length > 0); |
27 scoped_ptr<DataElement> element(new DataElement()); | 34 scoped_ptr<DataElement> element(new DataElement()); |
28 element->SetToFilePathRange(file_path, offset, length, | 35 element->SetToFilePathRange(file_path, offset, length, |
29 expected_modification_time); | 36 expected_modification_time); |
30 items_.push_back(new BlobDataItem(element.Pass())); | 37 items_.push_back(new BlobDataItem(element.Pass())); |
38 return this; | |
31 } | 39 } |
32 | 40 |
33 void BlobDataBuilder::AppendFile( | 41 BlobDataBuilder* BlobDataBuilder::AppendFile( |
34 const base::FilePath& file_path, | 42 const base::FilePath& file_path, |
35 uint64 offset, | 43 uint64 offset, |
36 uint64 length, | 44 uint64 length, |
37 const base::Time& expected_modification_time, | 45 const base::Time& expected_modification_time, |
38 scoped_refptr<ShareableFileReference> shareable_file) { | 46 scoped_refptr<ShareableFileReference> shareable_file) { |
39 DCHECK(length > 0); | 47 DCHECK(length > 0); |
40 scoped_ptr<DataElement> element(new DataElement()); | 48 scoped_ptr<DataElement> element(new DataElement()); |
41 element->SetToFilePathRange(file_path, offset, length, | 49 element->SetToFilePathRange(file_path, offset, length, |
42 expected_modification_time); | 50 expected_modification_time); |
43 items_.push_back(new BlobDataItem(element.Pass(), shareable_file)); | 51 items_.push_back(new BlobDataItem(element.Pass(), shareable_file)); |
52 return this; | |
44 } | 53 } |
45 | 54 |
46 void BlobDataBuilder::AppendBlob(const std::string& uuid, | 55 BlobDataBuilder* BlobDataBuilder::AppendBlob(const std::string& uuid, |
47 uint64 offset, | 56 uint64 offset, |
48 uint64 length) { | 57 uint64 length) { |
49 DCHECK_GT(length, 0ul); | 58 DCHECK_GT(length, 0ul); |
50 scoped_ptr<DataElement> element(new DataElement()); | 59 scoped_ptr<DataElement> element(new DataElement()); |
51 element->SetToBlobRange(uuid, offset, length); | 60 element->SetToBlobRange(uuid, offset, length); |
52 items_.push_back(new BlobDataItem(element.Pass())); | 61 items_.push_back(new BlobDataItem(element.Pass())); |
62 return this; | |
53 } | 63 } |
54 | 64 |
55 void BlobDataBuilder::AppendFileSystemFile( | 65 BlobDataBuilder* BlobDataBuilder::AppendBlob(const std::string& uuid) { |
66 scoped_ptr<DataElement> element(new DataElement()); | |
67 element->SetToBlob(uuid); | |
68 items_.push_back(new BlobDataItem(element.Pass())); | |
69 return this; | |
70 } | |
71 | |
72 BlobDataBuilder* BlobDataBuilder::AppendFileSystemFile( | |
56 const GURL& url, | 73 const GURL& url, |
57 uint64 offset, | 74 uint64 offset, |
58 uint64 length, | 75 uint64 length, |
59 const base::Time& expected_modification_time) { | 76 const base::Time& expected_modification_time) { |
60 DCHECK(length > 0); | 77 DCHECK(length > 0); |
61 scoped_ptr<DataElement> element(new DataElement()); | 78 scoped_ptr<DataElement> element(new DataElement()); |
62 element->SetToFileSystemUrlRange(url, offset, length, | 79 element->SetToFileSystemUrlRange(url, offset, length, |
63 expected_modification_time); | 80 expected_modification_time); |
64 items_.push_back(new BlobDataItem(element.Pass())); | 81 items_.push_back(new BlobDataItem(element.Pass())); |
82 return this; | |
83 } | |
84 | |
85 scoped_ptr<BlobDataBuilder> BlobDataBuilder::Clone() { | |
michaeln
2015/02/05 20:02:09
Is there a use case for Clone()?
dmurph
2015/02/06 01:32:30
Nope, removed. Left over from having the context
| |
86 scoped_ptr<BlobDataBuilder> other(new BlobDataBuilder(this->uuid_)); | |
87 other->content_type_ = this->content_type_; | |
88 other->content_disposition_ = this->content_disposition_; | |
89 other->items_.reserve(this->items_.size()); | |
90 for (const auto& data_item : items_) { | |
91 scoped_ptr<DataElement> element(new DataElement()); | |
92 *element = data_item->data_element(); | |
93 other->items_.push_back( | |
94 new BlobDataItem(element.Pass(), data_item->file_handle_)); | |
michaeln
2015/02/05 20:02:09
Why make a new item instead of letting the new bui
dmurph
2015/02/06 01:32:30
this was for a deep clone method, we don't need it
| |
95 } | |
96 return other.Pass(); | |
65 } | 97 } |
66 | 98 |
67 size_t BlobDataBuilder::GetMemoryUsage() const { | 99 size_t BlobDataBuilder::GetMemoryUsage() const { |
68 int64 memory = 0; | 100 int64 memory = 0; |
69 for (const auto& data_item : items_) { | 101 for (const auto& data_item : items_) { |
70 if (data_item->type() == DataElement::TYPE_BYTES) | 102 if (data_item->type() == DataElement::TYPE_BYTES) |
71 memory += data_item->length(); | 103 memory += data_item->length(); |
72 } | 104 } |
73 return memory; | 105 return memory; |
74 } | 106 } |
75 | 107 |
76 scoped_ptr<BlobDataSnapshot> BlobDataBuilder::BuildSnapshot() { | 108 scoped_ptr<BlobDataSnapshot> BlobDataBuilder::BuildSnapshot() { |
77 return scoped_ptr<BlobDataSnapshot>(new BlobDataSnapshot(uuid_, content_type_, | 109 return scoped_ptr<BlobDataSnapshot>(new BlobDataSnapshot(uuid_, content_type_, |
78 content_disposition_, | 110 content_disposition_, |
79 items_)).Pass(); | 111 items_)).Pass(); |
80 } | 112 } |
81 | 113 |
82 } // namespace storage | 114 } // namespace storage |
OLD | NEW |