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

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

Issue 2516713002: [BlobStorage] Implementing disk. (Closed)
Patch Set: removed cleanup check, as mac doesn't run out event loops Created 4 years 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
« no previous file with comments | « storage/browser/blob/blob_reader.cc ('k') | storage/browser/blob/blob_storage_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_STORAGE_CONTEXT_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 namespace base { 30 namespace base {
31 class FilePath; 31 class FilePath;
32 class Time; 32 class Time;
33 class TaskRunner; 33 class TaskRunner;
34 } 34 }
35 35
36 namespace content { 36 namespace content {
37 class BlobDispatcherHost; 37 class BlobDispatcherHost;
38 class BlobDispatcherHostTest; 38 class BlobDispatcherHostTest;
39 class BlobStorageBrowserTest;
39 } 40 }
40 41
41 namespace storage { 42 namespace storage {
42 class BlobDataBuilder; 43 class BlobDataBuilder;
43 class BlobDataHandle; 44 class BlobDataHandle;
44 class BlobDataItem; 45 class BlobDataItem;
45 class BlobDataSnapshot; 46 class BlobDataSnapshot;
46 class ShareableBlobDataItem; 47 class ShareableBlobDataItem;
47 48
48 // This class handles the logistics of blob storage within the browser process. 49 // This class handles the logistics of blob storage within the browser process.
49 // We are single threaded and should only be used on the IO thread. In Chromium 50 // This class is not threadsafe, access on IO thread. In Chromium there is one
50 // there is one instance per profile. 51 // instance per profile.
51 class STORAGE_EXPORT BlobStorageContext { 52 class STORAGE_EXPORT BlobStorageContext {
52 public: 53 public:
53 using TransportAllowedCallback = BlobEntry::TransportAllowedCallback; 54 using TransportAllowedCallback = BlobEntry::TransportAllowedCallback;
54 55
55 // Initializes the context without disk support. 56 // Initializes the context without disk support.
56 BlobStorageContext(); 57 BlobStorageContext();
58 // Disk support is enabled if |file_runner| isn't null.
59 BlobStorageContext(base::FilePath storage_directory,
60 scoped_refptr<base::TaskRunner> file_runner);
57 ~BlobStorageContext(); 61 ~BlobStorageContext();
58 62
59 std::unique_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid); 63 std::unique_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid);
60 std::unique_ptr<BlobDataHandle> GetBlobDataFromPublicURL(const GURL& url); 64 std::unique_ptr<BlobDataHandle> GetBlobDataFromPublicURL(const GURL& url);
61 65
62 // Always returns a handle to a blob. Use BlobStatus::GetBlobStatus() and 66 // Always returns a handle to a blob. Use BlobStatus::GetBlobStatus() and
63 // BlobStatus::RunOnConstructionComplete(callback) to determine construction 67 // BlobStatus::RunOnConstructionComplete(callback) to determine construction
64 // completion and possible errors. 68 // completion and possible errors.
65 std::unique_ptr<BlobDataHandle> AddFinishedBlob( 69 std::unique_ptr<BlobDataHandle> AddFinishedBlob(
66 const BlobDataBuilder& builder); 70 const BlobDataBuilder& builder);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 122
119 const BlobMemoryController& memory_controller() { return memory_controller_; } 123 const BlobMemoryController& memory_controller() { return memory_controller_; }
120 124
121 base::WeakPtr<BlobStorageContext> AsWeakPtr() { 125 base::WeakPtr<BlobStorageContext> AsWeakPtr() {
122 return ptr_factory_.GetWeakPtr(); 126 return ptr_factory_.GetWeakPtr();
123 } 127 }
124 128
125 protected: 129 protected:
126 friend class content::BlobDispatcherHost; 130 friend class content::BlobDispatcherHost;
127 friend class content::BlobDispatcherHostTest; 131 friend class content::BlobDispatcherHostTest;
132 friend class content::BlobStorageBrowserTest;
128 friend class BlobTransportHost; 133 friend class BlobTransportHost;
129 friend class BlobTransportHostTest; 134 friend class BlobTransportHostTest;
130 friend class BlobDataHandle; 135 friend class BlobDataHandle;
131 friend class BlobDataHandle::BlobDataHandleShared; 136 friend class BlobDataHandle::BlobDataHandleShared;
132 friend class BlobFlattenerTest; 137 friend class BlobFlattenerTest;
133 friend class BlobSliceTest; 138 friend class BlobSliceTest;
134 friend class BlobStorageContextTest; 139 friend class BlobStorageContextTest;
135 140
141 enum class TransportQuotaType { MEMORY, FILE };
142
136 // Transforms a BlobDataBuilder into a BlobEntry with no blob references. 143 // Transforms a BlobDataBuilder into a BlobEntry with no blob references.
137 // BlobSlice is used to flatten out these references. Records the total size 144 // BlobSlice is used to flatten out these references. Records the total size
138 // and items for memory and file quota requests. 145 // and items for memory and file quota requests.
139 // Exposed in the header file for testing. 146 // Exposed in the header file for testing.
140 struct STORAGE_EXPORT BlobFlattener { 147 struct STORAGE_EXPORT BlobFlattener {
141 BlobFlattener(const BlobDataBuilder& input_builder, 148 BlobFlattener(const BlobDataBuilder& input_builder,
142 BlobEntry* output_blob, 149 BlobEntry* output_blob,
143 BlobStorageRegistry* registry); 150 BlobStorageRegistry* registry);
144 ~BlobFlattener(); 151 ~BlobFlattener();
145 152
146 // This can be: 153 // This can be:
147 // * PENDING_QUOTA if we need memory quota, if we're populated and don't 154 // * PENDING_QUOTA if we need memory quota, if we're populated and don't
148 // need quota. 155 // need quota.
149 // * PENDING_INTERNALS if we're waiting on dependent blobs or we're done. 156 // * PENDING_INTERNALS if we're waiting on dependent blobs or we're done.
150 // * INVALID_CONSTRUCTION_ARGUMENTS if we have invalid input. 157 // * INVALID_CONSTRUCTION_ARGUMENTS if we have invalid input.
151 // * REFERENCED_BLOB_BROKEN if one of the referenced blobs is broken or we 158 // * REFERENCED_BLOB_BROKEN if one of the referenced blobs is broken or we
152 // reference ourself. 159 // reference ourself.
153 BlobStatus status = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; 160 BlobStatus status = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS;
154 161
162 bool contains_unpopulated_transport_items = false;
163
155 // This is the total size of the blob, including all memory, files, etc. 164 // This is the total size of the blob, including all memory, files, etc.
156 uint64_t total_size = 0; 165 uint64_t total_size = 0;
157 // Total memory size of the blob (not including files, etc). 166 // Total memory size of the blob (not including files, etc).
158 uint64_t total_memory_size = 0; 167 uint64_t total_memory_size = 0;
159 168
160 std::vector<std::pair<std::string, BlobEntry*>> dependent_blobs; 169 std::vector<std::pair<std::string, BlobEntry*>> dependent_blobs;
161 170
162 uint64_t memory_quota_needed = 0; 171 TransportQuotaType transport_quota_type = TransportQuotaType::MEMORY;
163 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_memory_items; 172 uint64_t transport_quota_needed = 0;
164 173 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_transport_items;
174 // Hold a separate vector of pointers to declare them as populated.
165 std::vector<ShareableBlobDataItem*> transport_items; 175 std::vector<ShareableBlobDataItem*> transport_items;
166 176
177 // Copy quota is always memory quota.
178 uint64_t copy_quota_needed = 0;
179 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_copy_items;
180
167 // These record all future copies we'll need to do from referenced blobs. 181 // These record all future copies we'll need to do from referenced blobs.
168 // This 182 // This happens when we do a partial slice from a pending data or file
169 // happens when we do a partial slice from a pending data or file item. 183 // item.
170 std::vector<BlobEntry::ItemCopyEntry> copies; 184 std::vector<BlobEntry::ItemCopyEntry> copies;
171 185
172 private: 186 private:
173 DISALLOW_COPY_AND_ASSIGN(BlobFlattener); 187 DISALLOW_COPY_AND_ASSIGN(BlobFlattener);
174 }; 188 };
175 189
176 // Used when a blob reference has a size and offset. Records the source items 190 // Used when a blob reference has a size and offset. Records the source items
177 // and memory we need to copy if either side of slice intersects an item. 191 // and memory we need to copy if either side of slice intersects an item.
178 // Exposed in the header file for testing. 192 // Exposed in the header file for testing.
179 struct STORAGE_EXPORT BlobSlice { 193 struct STORAGE_EXPORT BlobSlice {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 void NotifyTransportCompleteInternal(BlobEntry* entry); 242 void NotifyTransportCompleteInternal(BlobEntry* entry);
229 243
230 void CancelBuildingBlobInternal(BlobEntry* entry, BlobStatus reason); 244 void CancelBuildingBlobInternal(BlobEntry* entry, BlobStatus reason);
231 245
232 void FinishBuilding(BlobEntry* entry); 246 void FinishBuilding(BlobEntry* entry);
233 247
234 void RequestTransport( 248 void RequestTransport(
235 BlobEntry* entry, 249 BlobEntry* entry,
236 std::vector<BlobMemoryController::FileCreationInfo> files); 250 std::vector<BlobMemoryController::FileCreationInfo> files);
237 251
238 void OnEnoughSizeForMemory(const std::string& uuid, bool can_fit); 252 // The files array is empty for memory quota request responses.
253 void OnEnoughSpaceForTransport(
254 const std::string& uuid,
255 std::vector<BlobMemoryController::FileCreationInfo> files,
256 bool can_fit);
257
258 void OnEnoughSpaceForCopies(const std::string& uuid, bool can_fit);
239 259
240 void OnDependentBlobFinished(const std::string& owning_blob_uuid, 260 void OnDependentBlobFinished(const std::string& owning_blob_uuid,
241 BlobStatus reason); 261 BlobStatus reason);
242 262
243 void ClearAndFreeMemory(BlobEntry* entry); 263 void ClearAndFreeMemory(BlobEntry* entry);
244 264
245 BlobStorageRegistry registry_; 265 BlobStorageRegistry registry_;
246 BlobMemoryController memory_controller_; 266 BlobMemoryController memory_controller_;
247 base::WeakPtrFactory<BlobStorageContext> ptr_factory_; 267 base::WeakPtrFactory<BlobStorageContext> ptr_factory_;
248 268
249 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext); 269 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext);
250 }; 270 };
251 271
252 } // namespace storage 272 } // namespace storage
253 273
254 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_ 274 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_reader.cc ('k') | storage/browser/blob/blob_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698