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

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

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: format and hopefully windows fix Created 4 years, 2 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 testing.
39 static base::FilePath GetFutureFileItemPath(uint64_t file_id);
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
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 // Data for multiple items can be stored in the same 'future' file, just at
78 size_t AppendFutureFile(uint64_t offset, uint64_t length); 87 // different offsets and lengths. The |file_id| is used to differentiate
88 // between different 'future' files that will be used to store data for these
89 // items.
90 size_t AppendFutureFile(uint64_t offset, uint64_t length, uint64_t file_id);
79 91
80 // Populates a part of an item previously allocated with AppendFutureFile. 92 // Populates a part of an item previously allocated with AppendFutureFile.
81 // Returns true if: 93 // Returns true if:
82 // * The item was created by using AppendFutureFile and 94 // * The item was created by using AppendFutureFile and
83 // * The filepath is valid. 95 // * The filepath is valid.
84 bool PopulateFutureFile( 96 bool PopulateFutureFile(
85 size_t index, 97 size_t index,
86 const scoped_refptr<ShareableFileReference>& file_reference, 98 const scoped_refptr<ShareableFileReference>& file_reference,
87 const base::Time& expected_modification_time); 99 const base::Time& expected_modification_time);
88 100
(...skipping 10 matching lines...) Expand all
99 void AppendBlob(const std::string& uuid); 111 void AppendBlob(const std::string& uuid);
100 112
101 void AppendFileSystemFile(const GURL& url, 113 void AppendFileSystemFile(const GURL& url,
102 uint64_t offset, 114 uint64_t offset,
103 uint64_t length, 115 uint64_t length,
104 const base::Time& expected_modification_time); 116 const base::Time& expected_modification_time);
105 117
106 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle, 118 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle,
107 disk_cache::Entry* disk_cache_entry, 119 disk_cache::Entry* disk_cache_entry,
108 int disk_cache_stream_index); 120 int disk_cache_stream_index);
121
109 // The content of the side data is accessible with BlobReader::ReadSideData(). 122 // The content of the side data is accessible with BlobReader::ReadSideData().
110 void AppendDiskCacheEntryWithSideData( 123 void AppendDiskCacheEntryWithSideData(
111 const scoped_refptr<DataHandle>& data_handle, 124 const scoped_refptr<DataHandle>& data_handle,
112 disk_cache::Entry* disk_cache_entry, 125 disk_cache::Entry* disk_cache_entry,
113 int disk_cache_stream_index, 126 int disk_cache_stream_index,
114 int disk_cache_side_stream_index); 127 int disk_cache_side_stream_index);
115 128
116 void set_content_type(const std::string& content_type) { 129 void set_content_type(const std::string& content_type) {
117 content_type_ = content_type; 130 content_type_ = content_type;
118 } 131 }
119 132
120 void set_content_disposition(const std::string& content_disposition) { 133 void set_content_disposition(const std::string& content_disposition) {
121 content_disposition_ = content_disposition; 134 content_disposition_ = content_disposition;
122 } 135 }
123 136
124 void Clear(); 137 void Clear();
125 138
126 private: 139 private:
140 friend class BlobMemoryControllerTest;
127 friend class BlobStorageContext; 141 friend class BlobStorageContext;
128 friend class BlobAsyncBuilderHostTest;
129 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); 142 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b);
130 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); 143 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b);
131 friend STORAGE_EXPORT void PrintTo(const BlobDataBuilder& x, 144 friend STORAGE_EXPORT void PrintTo(const BlobDataBuilder& x,
132 ::std::ostream* os); 145 ::std::ostream* os);
146 FRIEND_TEST_ALL_PREFIXES(BlobDataBuilderTest, TestFutureFiles);
147 FRIEND_TEST_ALL_PREFIXES(BlobStorageContextTest, BuildBlobFuzzy);
133 148
134 std::string uuid_; 149 std::string uuid_;
135 std::string content_type_; 150 std::string content_type_;
136 std::string content_disposition_; 151 std::string content_disposition_;
137 std::vector<scoped_refptr<BlobDataItem>> items_; 152 std::vector<scoped_refptr<BlobDataItem>> items_;
138 153
139 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder); 154 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder);
140 }; 155 };
141 156
142 #if defined(UNIT_TEST) 157 #if defined(UNIT_TEST)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 199 }
185 200
186 inline bool operator!=(const BlobDataBuilder& a, const BlobDataSnapshot& b) { 201 inline bool operator!=(const BlobDataBuilder& a, const BlobDataSnapshot& b) {
187 return b != a; 202 return b != a;
188 } 203 }
189 204
190 #endif // defined(UNIT_TEST) 205 #endif // defined(UNIT_TEST)
191 206
192 } // namespace storage 207 } // namespace storage
193 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 208 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698