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