OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "storage/browser/blob/blob_data_item.h" | 13 #include "storage/browser/blob/blob_data_item.h" |
14 #include "storage/browser/blob/blob_data_snapshot.h" | 14 #include "storage/browser/blob/blob_data_snapshot.h" |
15 #include "storage/browser/storage_browser_export.h" | 15 #include "storage/browser/storage_browser_export.h" |
16 | 16 |
17 namespace storage { | 17 namespace storage { |
18 class BlobStorageContext; | 18 class BlobStorageContext; |
19 | 19 |
20 class STORAGE_EXPORT BlobDataBuilder { | 20 class STORAGE_EXPORT BlobDataBuilder { |
21 public: | 21 public: |
22 explicit BlobDataBuilder(const std::string& uuid); | 22 explicit BlobDataBuilder(const std::string& uuid); |
23 virtual ~BlobDataBuilder(); | 23 ~BlobDataBuilder(); |
24 | 24 |
25 const std::string& uuid() const { return uuid_; } | 25 const std::string& uuid() const { return uuid_; } |
26 | 26 |
27 void AppendData(const std::string& data) { | 27 // For builder-style use. |
michaeln
2015/02/05 20:02:09
We generally don't use this pattern in chromium so
dmurph
2015/02/06 01:32:30
Removed
| |
28 static BlobDataBuilder* Create(const std::string& uuid); | |
29 | |
30 BlobDataBuilder* AppendData(const std::string& data) { | |
28 AppendData(data.c_str(), data.size()); | 31 AppendData(data.c_str(), data.size()); |
32 return this; | |
29 } | 33 } |
30 | 34 |
31 void AppendData(const char* data, size_t length); | 35 BlobDataBuilder* AppendData(const char* data, size_t length); |
32 | 36 |
33 void AppendFile(const base::FilePath& file_path, | 37 BlobDataBuilder* AppendFile(const base::FilePath& file_path, |
34 uint64 offset, | 38 uint64 offset, |
35 uint64 length, | 39 uint64 length, |
36 const base::Time& expected_modification_time); | 40 const base::Time& expected_modification_time); |
37 | 41 |
38 void AppendFile(const base::FilePath& file_path, | 42 BlobDataBuilder* AppendFile( |
39 uint64 offset, | 43 const base::FilePath& file_path, |
40 uint64 length, | 44 uint64 offset, |
41 const base::Time& expected_modification_time, | 45 uint64 length, |
42 scoped_refptr<ShareableFileReference> shareable_file); | 46 const base::Time& expected_modification_time, |
47 scoped_refptr<ShareableFileReference> shareable_file); | |
43 | 48 |
44 void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); | 49 BlobDataBuilder* AppendBlob(const std::string& uuid, |
45 void AppendFileSystemFile(const GURL& url, | 50 uint64 offset, |
46 uint64 offset, | 51 uint64 length); |
47 uint64 length, | |
48 const base::Time& expected_modification_time); | |
49 | 52 |
50 void set_content_type(const std::string& content_type) { | 53 BlobDataBuilder* AppendBlob(const std::string& uuid); |
54 | |
55 BlobDataBuilder* AppendFileSystemFile( | |
56 const GURL& url, | |
57 uint64 offset, | |
58 uint64 length, | |
59 const base::Time& expected_modification_time); | |
60 | |
61 BlobDataBuilder* set_content_type(const std::string& content_type) { | |
51 content_type_ = content_type; | 62 content_type_ = content_type; |
63 return this; | |
52 } | 64 } |
53 | 65 |
54 void set_content_disposition(const std::string& content_disposition) { | 66 BlobDataBuilder* set_content_disposition( |
67 const std::string& content_disposition) { | |
55 content_disposition_ = content_disposition; | 68 content_disposition_ = content_disposition; |
69 return this; | |
56 } | 70 } |
57 | 71 |
72 // Does a deep clone of this builder. Necessary for cleaning creating | |
73 // multiple blobs with the same builder. | |
74 scoped_ptr<BlobDataBuilder> Clone(); | |
75 | |
58 size_t GetMemoryUsage() const; | 76 size_t GetMemoryUsage() const; |
59 | 77 |
60 scoped_ptr<BlobDataSnapshot> BuildSnapshot(); | 78 scoped_ptr<BlobDataSnapshot> BuildSnapshot(); |
61 | 79 |
62 private: | 80 private: |
63 friend class BlobStorageContext; | 81 friend class BlobStorageContext; |
64 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); | 82 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); |
65 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); | 83 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); |
66 | 84 |
67 std::string uuid_; | 85 std::string uuid_; |
(...skipping 23 matching lines...) Expand all Loading... | |
91 if (a.content_type() != b.content_type_) { | 109 if (a.content_type() != b.content_type_) { |
92 return false; | 110 return false; |
93 } | 111 } |
94 if (a.content_disposition() != b.content_disposition_) { | 112 if (a.content_disposition() != b.content_disposition_) { |
95 return false; | 113 return false; |
96 } | 114 } |
97 if (a.items().size() != b.items_.size()) { | 115 if (a.items().size() != b.items_.size()) { |
98 return false; | 116 return false; |
99 } | 117 } |
100 for (size_t i = 0; i < a.items().size(); ++i) { | 118 for (size_t i = 0; i < a.items().size(); ++i) { |
101 if (*(a.items()[i]) != *(b.items_[i])) { | 119 if (*(a.items()[i]) != *(b.items_[i])) |
102 return false; | 120 return false; |
103 } | |
104 } | 121 } |
105 return true; | 122 return true; |
106 } | 123 } |
107 | 124 |
108 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { | 125 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { |
109 return !(a == b); | 126 return !(a == b); |
110 } | 127 } |
111 | 128 |
112 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { | 129 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { |
113 return !(a == b); | 130 return !(a == b); |
114 } | 131 } |
115 #endif // defined(UNIT_TEST) | 132 #endif // defined(UNIT_TEST) |
116 | 133 |
117 } // namespace storage | 134 } // namespace storage |
118 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 135 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
OLD | NEW |