OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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_STORAGE_REGISTRY_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ |
6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
16 #include "base/containers/scoped_ptr_hash_map.h" | 16 #include "base/containers/scoped_ptr_hash_map.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "storage/browser/blob/blob_data_handle.h" | |
19 #include "storage/browser/blob/blob_memory_controller.h" | |
18 #include "storage/browser/blob/internal_blob_data.h" | 20 #include "storage/browser/blob/internal_blob_data.h" |
19 #include "storage/browser/storage_browser_export.h" | 21 #include "storage/browser/storage_browser_export.h" |
20 #include "storage/common/blob_storage/blob_storage_constants.h" | 22 #include "storage/common/blob_storage/blob_storage_constants.h" |
21 | 23 |
22 class GURL; | 24 class GURL; |
23 | 25 |
24 namespace storage { | 26 namespace storage { |
25 | 27 |
26 // This class stores the blob data in the various states of construction, as | 28 // This class stores the blob data in the various states of construction, as |
27 // well as URL mappings to blob uuids. | 29 // well as URL mappings to blob uuids. |
28 // Implementation notes: | 30 // Implementation notes: |
29 // * There is no implicit refcounting in this class, except for setting the | 31 // * There is no implicit refcounting in this class, except for setting the |
30 // refcount to 1 on registration. | 32 // refcount to 1 on registration. |
31 // * When removing a uuid registration, we do not check for URL mappings to that | 33 // * When removing a uuid registration, we do not check for URL mappings to that |
32 // uuid. The user must keep track of these. | 34 // uuid. The user must keep track of these. |
33 class STORAGE_EXPORT BlobStorageRegistry { | 35 class STORAGE_EXPORT BlobStorageRegistry { |
34 public: | 36 public: |
35 // True means the blob was constructed successfully, and false means that | 37 struct STORAGE_EXPORT ItemCopyEntry { |
36 // there was an error, which is reported in the second argument. | 38 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item, |
37 using BlobConstructedCallback = | 39 size_t source_item_offset, |
38 base::Callback<void(bool, IPCBlobCreationCancelCode)>; | 40 scoped_refptr<ShareableBlobDataItem> dest_item); |
41 ~ItemCopyEntry(); | |
42 ItemCopyEntry(const ItemCopyEntry&); | |
39 | 43 |
40 enum class BlobState { | 44 scoped_refptr<ShareableBlobDataItem> source_item; |
41 // The blob is pending transportation from the renderer. This is the default | 45 size_t source_item_offset = 0; |
42 // state on entry construction. | 46 scoped_refptr<ShareableBlobDataItem> dest_item; |
43 PENDING, | |
44 // The blob is complete and can be read from. | |
45 COMPLETE, | |
46 // The blob is broken and no longer holds data. This happens when there was | |
47 // a problem constructing the blob, or we've run out of memory. | |
48 BROKEN | |
49 }; | 47 }; |
50 | 48 |
51 struct STORAGE_EXPORT Entry { | 49 struct STORAGE_EXPORT Entry { |
52 size_t refcount; | 50 size_t refcount = 0; |
53 BlobState state; | 51 BlobStatus status = BlobStatus::PENDING; |
54 std::vector<BlobConstructedCallback> build_completion_callbacks; | 52 std::vector<BlobStatusCallback> build_completion_callbacks; |
55 | 53 |
56 // Only applicable if the state == BROKEN. | 54 // Blob items. During construction these can be |
Marijn Kruisselbrink
2016/07/12 21:33:07
"these can be"?
dmurph
2016/07/14 01:04:31
Done.
| |
57 IPCBlobCreationCancelCode broken_reason = | 55 InternalBlobData data; |
58 IPCBlobCreationCancelCode::UNKNOWN; | 56 bool waiting_until_user_population = false; |
57 BlobStatusCallback ready_for_user_population_callback; | |
59 | 58 |
60 // data and data_builder are mutually exclusive. | 59 // Metadata |
61 std::unique_ptr<InternalBlobData> data; | |
62 std::unique_ptr<InternalBlobData::Builder> data_builder; | |
63 | |
64 std::string content_type; | 60 std::string content_type; |
65 std::string content_disposition; | 61 std::string content_disposition; |
66 | 62 |
67 Entry() = delete; | 63 // If the blob is destructed, we don't decrease memory in our manager unless |
68 Entry(int refcount, BlobState state); | 64 // this is true. |
65 bool memory_accounted_for = false; | |
66 bool can_fit = true; | |
67 BlobMemoryController::PendingConstructionEntry pending_copies_memory_entry; | |
68 // These are copies from a referenced blob item to our blob items. Some of | |
69 // these entries may have changed from bytes to files if they were paged. | |
70 // We must handle this case. | |
71 std::vector<ItemCopyEntry> copies; | |
72 | |
73 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; | |
74 size_t dependent_blobs_building = 0; | |
75 | |
76 Entry(); | |
69 ~Entry(); | 77 ~Entry(); |
70 | |
71 // Performs a test-and-set on the state of the given blob. If the state | |
72 // isn't as expected, we return false. Otherwise we set the new state and | |
73 // return true. | |
74 bool TestAndSetState(BlobState expected, BlobState set); | |
75 }; | 78 }; |
76 | 79 |
77 BlobStorageRegistry(); | 80 BlobStorageRegistry(); |
78 ~BlobStorageRegistry(); | 81 ~BlobStorageRegistry(); |
79 | 82 |
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If | 83 // Creates the blob entry with a refcount of 1 and a state of PENDING. If |
81 // the blob is already in use, we return null. | 84 // the blob is already in use, we return null. |
82 Entry* CreateEntry(const std::string& uuid, | 85 Entry* CreateEntry(const std::string& uuid, |
83 const std::string& content_type, | 86 const std::string& content_type, |
84 const std::string& content_disposition); | 87 const std::string& content_disposition); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 using URLMap = std::map<GURL, std::string>; | 121 using URLMap = std::map<GURL, std::string>; |
119 | 122 |
120 BlobMap blob_map_; | 123 BlobMap blob_map_; |
121 URLMap url_to_uuid_; | 124 URLMap url_to_uuid_; |
122 | 125 |
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); | 126 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); |
124 }; | 127 }; |
125 | 128 |
126 } // namespace storage | 129 } // namespace storage |
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ | 130 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ |
OLD | NEW |