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

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

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finished comments, added new pending enum state Created 4 years, 5 months 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
OLDNEW
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 "base/optional.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 {
27 class BlobDataHandle;
28 class ShareableBlobDataItem;
25 29
26 // This class stores the blob data in the various states of construction, as 30 // This class stores the blob data in the various states of construction, as
27 // well as URL mappings to blob uuids. 31 // well as URL mappings to blob uuids.
28 // Implementation notes: 32 // Implementation notes:
29 // * There is no implicit refcounting in this class, except for setting the 33 // * There is no implicit refcounting in this class, except for setting the
30 // refcount to 1 on registration. 34 // refcount to 1 on registration.
31 // * When removing a uuid registration, we do not check for URL mappings to that 35 // * When removing a uuid registration, we do not check for URL mappings to that
32 // uuid. The user must keep track of these. 36 // uuid. The user must keep track of these.
33 class STORAGE_EXPORT BlobStorageRegistry { 37 class STORAGE_EXPORT BlobStorageRegistry {
34 public: 38 public:
35 // True means the blob was constructed successfully, and false means that 39 struct STORAGE_EXPORT ItemCopyEntry {
36 // there was an error, which is reported in the second argument. 40 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
37 using BlobConstructedCallback = 41 size_t source_item_offset,
38 base::Callback<void(bool, IPCBlobCreationCancelCode)>; 42 scoped_refptr<ShareableBlobDataItem> dest_item);
43 ~ItemCopyEntry();
44 ItemCopyEntry(const ItemCopyEntry&);
39 45
40 enum class BlobState { 46 scoped_refptr<ShareableBlobDataItem> source_item;
41 // The blob is pending transportation from the renderer. This is the default 47 size_t source_item_offset = 0;
42 // state on entry construction. 48 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 }; 49 };
50 50
51 struct STORAGE_EXPORT Entry { 51 struct STORAGE_EXPORT Entry {
kinuko 2016/07/17 16:15:47 Hmm, this entry has become so complex now... :( T
dmurph 2016/07/19 02:26:28 I moved stuff out of here and into InternalBlobDat
52 size_t refcount; 52 size_t refcount = 0;
53 BlobState state; 53 BlobStatus status = BlobStatus::PENDING_MEMORY_QUOTA;
54 std::vector<BlobConstructedCallback> build_completion_callbacks; 54 std::vector<BlobStatusCallback> build_completion_callbacks;
55 55
56 // Only applicable if the state == BROKEN. 56 // Blob items. During construction these can be TYPE_BYTES_DESCRIPTION, and
57 IPCBlobCreationCancelCode broken_reason = 57 // some files might be 'future' files (see BlobDataBuilder). This will never
58 IPCBlobCreationCancelCode::UNKNOWN; 58 // contain blob item references.
59 InternalBlobData data;
60 bool waiting_until_user_population = false;
kinuko 2016/07/17 16:15:47 Now we have PENDING_DATA_POPULATION status do we s
dmurph 2016/07/19 02:26:28 removed.
61 BlobStatusCallback ready_for_user_population_callback;
59 62
60 // data and data_builder are mutually exclusive. 63 // Metadata
61 std::unique_ptr<InternalBlobData> data;
62 std::unique_ptr<InternalBlobData::Builder> data_builder;
63
64 std::string content_type; 64 std::string content_type;
65 std::string content_disposition; 65 std::string content_disposition;
66 66
67 Entry() = delete; 67 base::Optional<BlobMemoryController::PendingConstructionEntry>
68 Entry(int refcount, BlobState state); 68 pending_copies_memory_entry;
69
70 // These are copies from a referenced blob item to our blob items. Some of
71 // these entries may have changed from bytes to files if they were paged.
72 // We must handle this case.
73 std::vector<ItemCopyEntry> copies;
74
75 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
76 size_t dependent_blobs_building = 0;
77
78 Entry();
69 ~Entry(); 79 ~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 }; 80 };
76 81
77 BlobStorageRegistry(); 82 BlobStorageRegistry();
78 ~BlobStorageRegistry(); 83 ~BlobStorageRegistry();
79 84
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If 85 // 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. 86 // the blob is already in use, we return null.
82 Entry* CreateEntry(const std::string& uuid, 87 Entry* CreateEntry(const std::string& uuid,
83 const std::string& content_type, 88 const std::string& content_type,
84 const std::string& content_disposition); 89 const std::string& content_disposition);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 using URLMap = std::map<GURL, std::string>; 123 using URLMap = std::map<GURL, std::string>;
119 124
120 BlobMap blob_map_; 125 BlobMap blob_map_;
121 URLMap url_to_uuid_; 126 URLMap url_to_uuid_;
122 127
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); 128 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
124 }; 129 };
125 130
126 } // namespace storage 131 } // namespace storage
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 132 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698