OLD | NEW |
---|---|
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 Loading... | |
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 // We are single threaded and should only be used on the IO thread. In Chromium |
pwnall
2016/12/01 01:12:14
"We are single threaded" -> "The class is not thre
dmurph
2016/12/01 20:40:59
Done.
| |
50 // there is one instance per profile. | 51 // there is one 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 // We enable disk support if |file_runner| isn't null. | |
pwnall
2016/12/01 01:12:14
We enable disk support -> disk support is enabled.
dmurph
2016/12/01 20:40:59
Done.
| |
59 BlobStorageContext(const 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 Loading... | |
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 |
155 // This is the total size of the blob, including all memory, files, etc. | 162 // This is the total size of the blob, including all memory, files, etc. |
156 uint64_t total_size = 0; | 163 uint64_t total_size = 0; |
157 // Total memory size of the blob (not including files, etc). | 164 // Total memory size of the blob (not including files, etc). |
158 uint64_t total_memory_size = 0; | 165 uint64_t total_memory_size = 0; |
159 | 166 |
160 std::vector<std::pair<std::string, BlobEntry*>> dependent_blobs; | 167 std::vector<std::pair<std::string, BlobEntry*>> dependent_blobs; |
161 | 168 |
162 uint64_t memory_quota_needed = 0; | 169 TransportQuotaType transport_quota_type = TransportQuotaType::MEMORY; |
163 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_memory_items; | 170 uint64_t transport_quota_needed = 0; |
171 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_transport_items; | |
172 // Hold a separate vector of pointers to declare them as populated. | |
173 std::vector<ShareableBlobDataItem*> transport_items; | |
164 | 174 |
165 std::vector<ShareableBlobDataItem*> transport_items; | 175 // Copy quota is always memory quota. |
176 uint64_t copy_quota_needed = 0; | |
177 std::vector<scoped_refptr<ShareableBlobDataItem>> pending_copy_items; | |
166 | 178 |
167 // These record all future copies we'll need to do from referenced blobs. | 179 // These record all future copies we'll need to do from referenced blobs. |
168 // This | 180 // This |
169 // happens when we do a partial slice from a pending data or file item. | 181 // happens when we do a partial slice from a pending data or file item. |
170 std::vector<BlobEntry::ItemCopyEntry> copies; | 182 std::vector<BlobEntry::ItemCopyEntry> copies; |
171 | 183 |
172 private: | 184 private: |
173 DISALLOW_COPY_AND_ASSIGN(BlobFlattener); | 185 DISALLOW_COPY_AND_ASSIGN(BlobFlattener); |
174 }; | 186 }; |
175 | 187 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 void NotifyTransportCompleteInternal(BlobEntry* entry); | 240 void NotifyTransportCompleteInternal(BlobEntry* entry); |
229 | 241 |
230 void CancelBuildingBlobInternal(BlobEntry* entry, BlobStatus reason); | 242 void CancelBuildingBlobInternal(BlobEntry* entry, BlobStatus reason); |
231 | 243 |
232 void FinishBuilding(BlobEntry* entry); | 244 void FinishBuilding(BlobEntry* entry); |
233 | 245 |
234 void RequestTransport( | 246 void RequestTransport( |
235 BlobEntry* entry, | 247 BlobEntry* entry, |
236 std::vector<BlobMemoryController::FileCreationInfo> files); | 248 std::vector<BlobMemoryController::FileCreationInfo> files); |
237 | 249 |
238 void OnEnoughSizeForMemory(const std::string& uuid, bool can_fit); | 250 void OnEnoughSpaceForTransportByFiles( |
251 const std::string& uuid, | |
252 bool can_fit, | |
253 std::vector<BlobMemoryController::FileCreationInfo> files); | |
254 | |
255 void OnEnoughSpaceForTransportByMemory(const std::string& uuid, bool can_fit); | |
256 | |
257 void OnEnoughSpaceForCopies(const std::string& uuid, bool can_fit); | |
239 | 258 |
240 void OnDependentBlobFinished(const std::string& owning_blob_uuid, | 259 void OnDependentBlobFinished(const std::string& owning_blob_uuid, |
241 BlobStatus reason); | 260 BlobStatus reason); |
242 | 261 |
243 void ClearAndFreeMemory(BlobEntry* entry); | 262 void ClearAndFreeMemory(BlobEntry* entry); |
244 | 263 |
245 BlobStorageRegistry registry_; | 264 BlobStorageRegistry registry_; |
246 BlobMemoryController memory_controller_; | 265 BlobMemoryController memory_controller_; |
247 base::WeakPtrFactory<BlobStorageContext> ptr_factory_; | 266 base::WeakPtrFactory<BlobStorageContext> ptr_factory_; |
248 | 267 |
249 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext); | 268 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext); |
250 }; | 269 }; |
251 | 270 |
252 } // namespace storage | 271 } // namespace storage |
253 | 272 |
254 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_ | 273 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_ |
OLD | NEW |