Chromium Code Reviews| 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 #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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <ostream> | 10 #include <ostream> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "storage/browser/blob/blob_data_item.h" | 17 #include "storage/browser/blob/blob_data_item.h" |
| 18 #include "storage/browser/blob/blob_data_snapshot.h" | 18 #include "storage/browser/blob/blob_data_snapshot.h" |
| 19 #include "storage/browser/blob/shareable_file_reference.h" | |
| 19 #include "storage/browser/storage_browser_export.h" | 20 #include "storage/browser/storage_browser_export.h" |
| 20 | 21 |
| 21 namespace disk_cache { | 22 namespace disk_cache { |
| 22 class Entry; | 23 class Entry; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace storage { | 26 namespace storage { |
| 26 class BlobStorageContext; | 27 class BlobStorageContext; |
| 27 class ShareableFileReference; | 28 class ShareableFileReference; |
| 28 | 29 |
| 30 // This class is used to build blobs. It also facilitates the operation of | |
| 31 // 'pending' data, where the user knows the size and existence of a file or | |
| 32 // bytes item, but we don't have the memory or file yet. See AppendFuture* and | |
| 33 // PopulateFuture* methods for more description. Use | |
| 34 // BlobDataHandle::GetBlobStatus to check for an error after creating the blob. | |
| 29 class STORAGE_EXPORT BlobDataBuilder { | 35 class STORAGE_EXPORT BlobDataBuilder { |
| 30 public: | 36 public: |
| 31 using DataHandle = BlobDataItem::DataHandle; | 37 using DataHandle = BlobDataItem::DataHandle; |
| 38 // Visible for tesing. | |
| 39 static const char kFutureFileName[]; | |
| 32 | 40 |
| 33 // This is the filename used for the temporary file items added by | 41 // Returns if the given item was created by AppendFutureFile. |
| 34 // AppendFutureFile. | 42 static bool IsFutureFileItem(const DataElement& element); |
| 35 const static char kAppendFutureFileTemporaryFileName[]; | 43 // Returns |file_id| given to AppendFutureFile. |
| 44 static uint64_t GetFutureFileID(const DataElement& element); | |
| 36 | 45 |
| 37 explicit BlobDataBuilder(const std::string& uuid); | 46 explicit BlobDataBuilder(const std::string& uuid); |
| 38 ~BlobDataBuilder(); | 47 ~BlobDataBuilder(); |
| 39 | 48 |
| 40 const std::string& uuid() const { return uuid_; } | 49 const std::string& uuid() const { return uuid_; } |
| 41 | 50 |
| 42 // Validates the data element that was sent over IPC, and copies the data if | 51 // Validates the data element that was sent over IPC, and copies the data if |
| 43 // it's a 'bytes' element. Data elements of BYTES_DESCRIPTION or | 52 // it's a 'bytes' element. Data elements of BYTES_DESCRIPTION or |
| 44 // DISK_CACHE_ENTRY types are not valid IPC data element types, and cannot be | 53 // DISK_CACHE_ENTRY types are not valid IPC data element types, and cannot be |
| 45 // given to this method. | 54 // given to this method. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 66 // * The offset and length are valid, and | 75 // * The offset and length are valid, and |
| 67 // * data is a valid pointer. | 76 // * data is a valid pointer. |
| 68 bool PopulateFutureData(size_t index, | 77 bool PopulateFutureData(size_t index, |
| 69 const char* data, | 78 const char* data, |
| 70 size_t offset, | 79 size_t offset, |
| 71 size_t length); | 80 size_t length); |
| 72 | 81 |
| 73 // Adds an item that is flagged for future data population. Use | 82 // Adds an item that is flagged for future data population. Use |
| 74 // 'PopulateFutureFile' to set the file path and expected modification time | 83 // 'PopulateFutureFile' to set the file path and expected modification time |
| 75 // of this file. Returns the index of the item (to be used in | 84 // of this file. Returns the index of the item (to be used in |
| 76 // PopulateFutureFile). The temporary filename used by this method is | 85 // PopulateFutureFile). |length| cannot be 0. |
| 77 // kAppendFutureFileTemporaryFileName. |length| cannot be 0. | 86 // |file_id| corresponds to the file handle index used to store this item, |
| 78 size_t AppendFutureFile(uint64_t offset, uint64_t length); | 87 // which needs to be unique on a per-builder bases. Multiple items can have |
| 88 // the same id (as they would be at diffeent offsets in the file). This is | |
| 89 // used by the BlobMemoryController class to determine the number and size of | |
| 90 // files it needs to create for a blob. | |
| 91 size_t AppendFutureFile(uint64_t offset, uint64_t length, uint64_t file_id); | |
| 79 | 92 |
| 80 // Populates a part of an item previously allocated with AppendFutureFile. | 93 // Populates a part of an item previously allocated with AppendFutureFile. |
| 81 // Returns true if: | 94 // Returns true if: |
| 82 // * The item was created by using AppendFutureFile and | 95 // * The item was created by using AppendFutureFile and |
| 83 // * The filepath is valid. | 96 // * The filepath is valid. |
| 84 bool PopulateFutureFile( | 97 bool PopulateFutureFile( |
| 85 size_t index, | 98 size_t index, |
| 86 const scoped_refptr<ShareableFileReference>& file_reference, | 99 const scoped_refptr<ShareableFileReference>& file_reference, |
| 87 const base::Time& expected_modification_time); | 100 const base::Time& expected_modification_time); |
| 88 | 101 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 99 void AppendBlob(const std::string& uuid); | 112 void AppendBlob(const std::string& uuid); |
| 100 | 113 |
| 101 void AppendFileSystemFile(const GURL& url, | 114 void AppendFileSystemFile(const GURL& url, |
| 102 uint64_t offset, | 115 uint64_t offset, |
| 103 uint64_t length, | 116 uint64_t length, |
| 104 const base::Time& expected_modification_time); | 117 const base::Time& expected_modification_time); |
| 105 | 118 |
| 106 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle, | 119 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle, |
| 107 disk_cache::Entry* disk_cache_entry, | 120 disk_cache::Entry* disk_cache_entry, |
| 108 int disk_cache_stream_index); | 121 int disk_cache_stream_index); |
| 122 | |
| 109 // The content of the side data is accessible with BlobReader::ReadSideData(). | 123 // The content of the side data is accessible with BlobReader::ReadSideData(). |
| 110 void AppendDiskCacheEntryWithSideData( | 124 void AppendDiskCacheEntryWithSideData( |
| 111 const scoped_refptr<DataHandle>& data_handle, | 125 const scoped_refptr<DataHandle>& data_handle, |
| 112 disk_cache::Entry* disk_cache_entry, | 126 disk_cache::Entry* disk_cache_entry, |
| 113 int disk_cache_stream_index, | 127 int disk_cache_stream_index, |
| 114 int disk_cache_side_stream_index); | 128 int disk_cache_side_stream_index); |
| 115 | 129 |
| 116 void set_content_type(const std::string& content_type) { | 130 void set_content_type(const std::string& content_type) { |
| 117 content_type_ = content_type; | 131 content_type_ = content_type; |
| 118 } | 132 } |
| 119 | 133 |
| 120 void set_content_disposition(const std::string& content_disposition) { | 134 void set_content_disposition(const std::string& content_disposition) { |
| 121 content_disposition_ = content_disposition; | 135 content_disposition_ = content_disposition; |
| 122 } | 136 } |
| 123 | 137 |
| 124 void Clear(); | 138 void Clear(); |
| 125 | 139 |
| 126 private: | 140 private: |
| 141 friend class BlobAsyncBuilderHostTest; | |
|
pwnall
2016/09/21 09:03:35
This isn't a fault introduced in this CL... but th
dmurph
2016/09/21 23:45:52
That operator is supposed to be public. Let me kno
| |
| 142 friend class BlobMemoryControllerTest; | |
| 143 friend struct BlobFlattener; | |
| 127 friend class BlobStorageContext; | 144 friend class BlobStorageContext; |
| 128 friend class BlobAsyncBuilderHostTest; | 145 FRIEND_TEST_ALL_PREFIXES(BlobStorageContextTest, BuildBlobFuzzy); |
| 129 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); | 146 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); |
| 130 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); | 147 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); |
| 131 friend STORAGE_EXPORT void PrintTo(const BlobDataBuilder& x, | 148 friend STORAGE_EXPORT void PrintTo(const BlobDataBuilder& x, |
| 132 ::std::ostream* os); | 149 ::std::ostream* os); |
| 133 | 150 |
| 134 std::string uuid_; | 151 std::string uuid_; |
| 135 std::string content_type_; | 152 std::string content_type_; |
| 136 std::string content_disposition_; | 153 std::string content_disposition_; |
| 137 std::vector<scoped_refptr<BlobDataItem>> items_; | 154 std::vector<scoped_refptr<BlobDataItem>> items_; |
| 138 | 155 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } | 201 } |
| 185 | 202 |
| 186 inline bool operator!=(const BlobDataBuilder& a, const BlobDataSnapshot& b) { | 203 inline bool operator!=(const BlobDataBuilder& a, const BlobDataSnapshot& b) { |
| 187 return b != a; | 204 return b != a; |
| 188 } | 205 } |
| 189 | 206 |
| 190 #endif // defined(UNIT_TEST) | 207 #endif // defined(UNIT_TEST) |
| 191 | 208 |
| 192 } // namespace storage | 209 } // namespace storage |
| 193 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ | 210 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ |
| OLD | NEW |