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_memory_controller.h" | |
18 #include "storage/browser/blob/internal_blob_data.h" | 19 #include "storage/browser/blob/internal_blob_data.h" |
19 #include "storage/browser/storage_browser_export.h" | 20 #include "storage/browser/storage_browser_export.h" |
20 #include "storage/common/blob_storage/blob_storage_constants.h" | 21 #include "storage/common/blob_storage/blob_storage_constants.h" |
21 | 22 |
22 class GURL; | 23 class GURL; |
23 | 24 |
24 namespace storage { | 25 namespace storage { |
26 class BlobDataHandle; | |
27 class ShareableBlobDataItem; | |
25 | 28 |
26 // This class stores the blob data in the various states of construction, as | 29 // This class stores the blob data in the various states of construction, as |
27 // well as URL mappings to blob uuids. | 30 // well as URL mappings to blob uuids. |
28 // Implementation notes: | 31 // Implementation notes: |
29 // * There is no implicit refcounting in this class, except for setting the | 32 // * There is no implicit refcounting in this class, except for setting the |
30 // refcount to 1 on registration. | 33 // refcount to 1 on registration. |
31 // * When removing a uuid registration, we do not check for URL mappings to that | 34 // * When removing a uuid registration, we do not check for URL mappings to that |
32 // uuid. The user must keep track of these. | 35 // uuid. The user must keep track of these. |
33 class STORAGE_EXPORT BlobStorageRegistry { | 36 class STORAGE_EXPORT BlobStorageRegistry { |
34 public: | 37 public: |
35 // True means the blob was constructed successfully, and false means that | 38 struct STORAGE_EXPORT ItemCopyEntry { |
36 // there was an error, which is reported in the second argument. | 39 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item, |
37 using BlobConstructedCallback = | 40 size_t source_item_offset, |
38 base::Callback<void(bool, IPCBlobCreationCancelCode)>; | 41 scoped_refptr<ShareableBlobDataItem> dest_item); |
42 ~ItemCopyEntry(); | |
43 ItemCopyEntry(const ItemCopyEntry&); | |
39 | 44 |
40 enum class BlobState { | 45 scoped_refptr<ShareableBlobDataItem> source_item; |
michaeln
2016/07/15 02:12:08
i'd rather to retain the distinction between state
dmurph
2016/07/15 20:18:16
Hm... But we're pretty much always needing both. I
| |
41 // The blob is pending transportation from the renderer. This is the default | 46 size_t source_item_offset = 0; |
42 // state on entry construction. | 47 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 }; | 48 }; |
50 | 49 |
51 struct STORAGE_EXPORT Entry { | 50 struct STORAGE_EXPORT Entry { |
michaeln
2016/07/15 02:12:08
I think it might help if there were a more clear d
dmurph
2016/07/15 20:18:16
Hm... what if we separated out these structs into
| |
52 size_t refcount; | 51 size_t refcount = 0; |
53 BlobState state; | 52 BlobStatus status = BlobStatus::PENDING; |
54 std::vector<BlobConstructedCallback> build_completion_callbacks; | 53 std::vector<BlobStatusCallback> build_completion_callbacks; |
55 | 54 |
56 // Only applicable if the state == BROKEN. | 55 // Blob items. During construction these can be TYPE_BYTES_DESCRIPTION, and |
57 IPCBlobCreationCancelCode broken_reason = | 56 // some files might be 'future' files (see BlobDataBuilder). This will never |
58 IPCBlobCreationCancelCode::UNKNOWN; | 57 // contain blob item references. |
58 InternalBlobData data; | |
59 bool waiting_until_user_population = false; | |
michaeln
2016/07/15 02:12:08
Can create a larger number of BlobStatus values to
dmurph
2016/07/15 20:18:16
Huh. This simplifies a little bit, let me know wha
| |
60 BlobStatusCallback ready_for_user_population_callback; | |
59 | 61 |
60 // data and data_builder are mutually exclusive. | 62 // Metadata |
61 std::unique_ptr<InternalBlobData> data; | |
62 std::unique_ptr<InternalBlobData::Builder> data_builder; | |
63 | |
64 std::string content_type; | 63 std::string content_type; |
65 std::string content_disposition; | 64 std::string content_disposition; |
66 | 65 |
67 Entry() = delete; | 66 // If the blob is destructed, we don't decrease memory in our manager unless |
68 Entry(int refcount, BlobState state); | 67 // this is true. |
68 bool memory_accounted_for = false; | |
69 bool can_fit = true; | |
70 BlobMemoryController::PendingConstructionEntry pending_copies_memory_entry; | |
71 // These are copies from a referenced blob item to our blob items. Some of | |
72 // these entries may have changed from bytes to files if they were paged. | |
73 // We must handle this case. | |
74 std::vector<ItemCopyEntry> copies; | |
75 | |
76 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; | |
77 size_t dependent_blobs_building = 0; | |
78 | |
79 Entry(); | |
69 ~Entry(); | 80 ~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 }; | 81 }; |
76 | 82 |
77 BlobStorageRegistry(); | 83 BlobStorageRegistry(); |
78 ~BlobStorageRegistry(); | 84 ~BlobStorageRegistry(); |
79 | 85 |
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If | 86 // 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. | 87 // the blob is already in use, we return null. |
82 Entry* CreateEntry(const std::string& uuid, | 88 Entry* CreateEntry(const std::string& uuid, |
83 const std::string& content_type, | 89 const std::string& content_type, |
84 const std::string& content_disposition); | 90 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>; | 124 using URLMap = std::map<GURL, std::string>; |
119 | 125 |
120 BlobMap blob_map_; | 126 BlobMap blob_map_; |
121 URLMap url_to_uuid_; | 127 URLMap url_to_uuid_; |
122 | 128 |
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); | 129 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); |
124 }; | 130 }; |
125 | 131 |
126 } // namespace storage | 132 } // namespace storage |
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ | 133 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ |
OLD | NEW |