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

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: Fixed layout tests, cleaned up test visibility 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"
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 InternalBlobData;
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
36 // there was an error, which is reported in the second argument.
37 using BlobConstructedCallback =
38 base::Callback<void(bool, IPCBlobCreationCancelCode)>;
39
40 enum class BlobState {
41 // The blob is pending transportation from the renderer. This is the default
42 // state on entry construction.
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 };
50
51 struct STORAGE_EXPORT Entry {
52 size_t refcount;
53 BlobState state;
54 std::vector<BlobConstructedCallback> build_completion_callbacks;
55
56 // Only applicable if the state == BROKEN.
57 IPCBlobCreationCancelCode broken_reason =
58 IPCBlobCreationCancelCode::UNKNOWN;
59
60 // data and data_builder are mutually exclusive.
61 std::unique_ptr<InternalBlobData> data;
62 std::unique_ptr<InternalBlobData::Builder> data_builder;
63
64 std::string content_type;
65 std::string content_disposition;
66
67 Entry() = delete;
68 Entry(int refcount, BlobState state);
69 ~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 };
76
77 BlobStorageRegistry(); 39 BlobStorageRegistry();
78 ~BlobStorageRegistry(); 40 ~BlobStorageRegistry();
79 41
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If 42 // 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. 43 // the blob is already in use, we return null.
82 Entry* CreateEntry(const std::string& uuid, 44 InternalBlobData* CreateEntry(const std::string& uuid,
83 const std::string& content_type, 45 const std::string& content_type,
84 const std::string& content_disposition); 46 const std::string& content_disposition);
85 47
86 // Removes the blob entry with the given uuid. This does not unmap any 48 // Removes the blob entry with the given uuid. This does not unmap any
87 // URLs that are pointing to this uuid. Returns if the entry existed. 49 // URLs that are pointing to this uuid. Returns if the entry existed.
88 bool DeleteEntry(const std::string& uuid); 50 bool DeleteEntry(const std::string& uuid);
89 51
90 bool HasEntry(const std::string& uuid) const; 52 bool HasEntry(const std::string& uuid) const;
91 53
92 // Gets the blob entry for the given uuid. Returns nullptr if the entry 54 // Gets the blob entry for the given uuid. Returns nullptr if the entry
93 // does not exist. 55 // does not exist.
94 Entry* GetEntry(const std::string& uuid); 56 InternalBlobData* GetEntry(const std::string& uuid);
95 const Entry* GetEntry(const std::string& uuid) const; 57 const InternalBlobData* GetEntry(const std::string& uuid) const;
96 58
97 // Creates a url mapping from blob uuid to the given url. Returns false if 59 // Creates a url mapping from blob uuid to the given url. Returns false if
98 // the uuid isn't mapped to an entry or if there already is a map for the URL. 60 // the uuid isn't mapped to an entry or if there already is a map for the URL.
99 bool CreateUrlMapping(const GURL& url, const std::string& uuid); 61 bool CreateUrlMapping(const GURL& url, const std::string& uuid);
100 62
101 // Removes the given URL mapping. Optionally populates a uuid string of the 63 // Removes the given URL mapping. Optionally populates a uuid string of the
102 // removed entry uuid. Returns false if the url isn't mapped. 64 // removed entry uuid. Returns false if the url isn't mapped.
103 bool DeleteURLMapping(const GURL& url, std::string* uuid); 65 bool DeleteURLMapping(const GURL& url, std::string* uuid);
104 66
105 // Returns if the url is mapped to a blob uuid. 67 // Returns if the url is mapped to a blob uuid.
106 bool IsURLMapped(const GURL& blob_url) const; 68 bool IsURLMapped(const GURL& blob_url) const;
107 69
108 // Returns the entry from the given url, and optionally populates the uuid for 70 // Returns the entry from the given url, and optionally populates the uuid for
109 // that entry. Returns a nullptr if the mapping or entry doesn't exist. 71 // that entry. Returns a nullptr if the mapping or entry doesn't exist.
110 Entry* GetEntryFromURL(const GURL& url, std::string* uuid); 72 InternalBlobData* GetEntryFromURL(const GURL& url, std::string* uuid);
111 73
112 size_t blob_count() const { return blob_map_.size(); } 74 size_t blob_count() const { return blob_map_.size(); }
113 size_t url_count() const { return url_to_uuid_.size(); } 75 size_t url_count() const { return url_to_uuid_.size(); }
114 76
115 private: 77 private:
116 friend class ViewBlobInternalsJob; 78 friend class ViewBlobInternalsJob;
117 using BlobMap = base::ScopedPtrHashMap<std::string, std::unique_ptr<Entry>>; 79 using BlobMap =
80 base::ScopedPtrHashMap<std::string, std::unique_ptr<InternalBlobData>>;
118 using URLMap = std::map<GURL, std::string>; 81 using URLMap = std::map<GURL, std::string>;
119 82
120 BlobMap blob_map_; 83 BlobMap blob_map_;
121 URLMap url_to_uuid_; 84 URLMap url_to_uuid_;
122 85
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); 86 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
124 }; 87 };
125 88
126 } // namespace storage 89 } // namespace storage
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 90 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698