Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: storage/browser/blob/blob_data_builder.h

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined BlobSlice & BlobFlattener files, more comments, a little cleanup. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kAppendFutureFileTemporaryFileName[];
michaeln 2016/08/15 22:44:44 please use shorter symbols, kFutureFileName[]
dmurph 2016/08/19 00:18:32 Done.
32 40
33 // This is the filename used for the temporary file items added by 41 // Use this function to tell if an item was added using AppendFutureFile.
34 // AppendFutureFile. 42 static bool IsTemporaryFileItem(const DataElement& element);
michaeln 2016/08/15 22:44:44 please use consistent terminology, "future" or "te
dmurph 2016/08/19 00:18:32 Done.
35 const static char kAppendFutureFileTemporaryFileName[]; 43 // Generated from |file_id| given in AppendFutureFile.
michaeln 2016/08/15 22:44:44 what does this function do? oh?
dmurph 2016/08/19 00:18:32 Done.
44 static std::string GetTemporaryFileID(const DataElement& element);
michaeln 2016/08/15 22:44:44 there's mysteriousness around file_ids and future
dmurph 2016/08/19 00:18:32 Done.
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
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| should correspond to the file handle 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. This is used by the
88 // BlobMemoryController class to determine the number and size of files it
89 // needs to create for a blob.
90 size_t AppendFutureFile(uint64_t offset,
91 uint64_t length,
92 const std::string& file_id);
79 93
80 // Populates a part of an item previously allocated with AppendFutureFile. 94 // Populates a part of an item previously allocated with AppendFutureFile.
81 // Returns true if: 95 // Returns true if:
82 // * The item was created by using AppendFutureFile and 96 // * The item was created by using AppendFutureFile and
83 // * The filepath is valid. 97 // * The filepath is valid.
84 bool PopulateFutureFile( 98 bool PopulateFutureFile(
85 size_t index, 99 size_t index,
86 const scoped_refptr<ShareableFileReference>& file_reference, 100 const scoped_refptr<ShareableFileReference>& file_reference,
87 const base::Time& expected_modification_time); 101 const base::Time& expected_modification_time);
88 102
(...skipping 10 matching lines...) Expand all
99 void AppendBlob(const std::string& uuid); 113 void AppendBlob(const std::string& uuid);
100 114
101 void AppendFileSystemFile(const GURL& url, 115 void AppendFileSystemFile(const GURL& url,
102 uint64_t offset, 116 uint64_t offset,
103 uint64_t length, 117 uint64_t length,
104 const base::Time& expected_modification_time); 118 const base::Time& expected_modification_time);
105 119
106 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle, 120 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle,
107 disk_cache::Entry* disk_cache_entry, 121 disk_cache::Entry* disk_cache_entry,
108 int disk_cache_stream_index); 122 int disk_cache_stream_index);
123
109 // The content of the side data is accessible with BlobReader::ReadSideData(). 124 // The content of the side data is accessible with BlobReader::ReadSideData().
110 void AppendDiskCacheEntryWithSideData( 125 void AppendDiskCacheEntryWithSideData(
111 const scoped_refptr<DataHandle>& data_handle, 126 const scoped_refptr<DataHandle>& data_handle,
112 disk_cache::Entry* disk_cache_entry, 127 disk_cache::Entry* disk_cache_entry,
113 int disk_cache_stream_index, 128 int disk_cache_stream_index,
114 int disk_cache_side_stream_index); 129 int disk_cache_side_stream_index);
115 130
116 void set_content_type(const std::string& content_type) { 131 void set_content_type(const std::string& content_type) {
117 content_type_ = content_type; 132 content_type_ = content_type;
118 } 133 }
119 134
120 void set_content_disposition(const std::string& content_disposition) { 135 void set_content_disposition(const std::string& content_disposition) {
121 content_disposition_ = content_disposition; 136 content_disposition_ = content_disposition;
122 } 137 }
123 138
124 void Clear(); 139 void Clear();
125 140
126 private: 141 private:
142 friend class BlobAsyncBuilderHostTest;
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698