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

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

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: compile fix Created 4 years, 1 month 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 "storage/browser/blob/internal_blob_data.h" 18 #include "base/optional.h"
19 #include "storage/browser/storage_browser_export.h" 19 #include "storage/browser/storage_browser_export.h"
20 #include "storage/common/blob_storage/blob_storage_constants.h" 20 #include "storage/common/blob_storage/blob_storage_constants.h"
21 21
22 class GURL; 22 class GURL;
23 23
24 namespace storage { 24 namespace storage {
25 class BlobDataHandle;
26 class InternalBlobData;
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
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 {
michaeln 2016/10/28 19:38:29 maybe rename InternalBlobData to BlobEntry
dmurph 2016/10/28 22:13:56 Done.
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(); 38 BlobStorageRegistry();
78 ~BlobStorageRegistry(); 39 ~BlobStorageRegistry();
79 40
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If 41 // 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. 42 // the blob is already in use, we return null.
82 Entry* CreateEntry(const std::string& uuid, 43 InternalBlobData* CreateEntry(const std::string& uuid,
michaeln 2016/10/28 19:38:29 naming, CreateEntry/GetEntry methods should return
dmurph 2016/10/28 22:13:56 Done.
83 const std::string& content_type, 44 const std::string& content_type,
84 const std::string& content_disposition); 45 const std::string& content_disposition);
85 46
86 // Removes the blob entry with the given uuid. This does not unmap any 47 // 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. 48 // URLs that are pointing to this uuid. Returns if the entry existed.
88 bool DeleteEntry(const std::string& uuid); 49 bool DeleteEntry(const std::string& uuid);
89 50
90 bool HasEntry(const std::string& uuid) const; 51 bool HasEntry(const std::string& uuid) const;
91 52
92 // Gets the blob entry for the given uuid. Returns nullptr if the entry 53 // Gets the blob entry for the given uuid. Returns nullptr if the entry
93 // does not exist. 54 // does not exist.
94 Entry* GetEntry(const std::string& uuid); 55 InternalBlobData* GetEntry(const std::string& uuid);
95 const Entry* GetEntry(const std::string& uuid) const; 56 const InternalBlobData* GetEntry(const std::string& uuid) const;
96 57
97 // Creates a url mapping from blob uuid to the given url. Returns false if 58 // 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. 59 // 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); 60 bool CreateUrlMapping(const GURL& url, const std::string& uuid);
100 61
101 // Removes the given URL mapping. Optionally populates a uuid string of the 62 // Removes the given URL mapping. Optionally populates a uuid string of the
102 // removed entry uuid. Returns false if the url isn't mapped. 63 // removed entry uuid. Returns false if the url isn't mapped.
103 bool DeleteURLMapping(const GURL& url, std::string* uuid); 64 bool DeleteURLMapping(const GURL& url, std::string* uuid);
104 65
105 // Returns if the url is mapped to a blob uuid. 66 // Returns if the url is mapped to a blob uuid.
106 bool IsURLMapped(const GURL& blob_url) const; 67 bool IsURLMapped(const GURL& blob_url) const;
107 68
108 // Returns the entry from the given url, and optionally populates the uuid for 69 // 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. 70 // that entry. Returns a nullptr if the mapping or entry doesn't exist.
110 Entry* GetEntryFromURL(const GURL& url, std::string* uuid); 71 InternalBlobData* GetEntryFromURL(const GURL& url, std::string* uuid);
111 72
112 size_t blob_count() const { return blob_map_.size(); } 73 size_t blob_count() const { return blob_map_.size(); }
113 size_t url_count() const { return url_to_uuid_.size(); } 74 size_t url_count() const { return url_to_uuid_.size(); }
114 75
115 private: 76 private:
116 friend class ViewBlobInternalsJob; 77 friend class ViewBlobInternalsJob;
117 using BlobMap = base::ScopedPtrHashMap<std::string, std::unique_ptr<Entry>>; 78 using BlobMap =
79 base::ScopedPtrHashMap<std::string, std::unique_ptr<InternalBlobData>>;
118 using URLMap = std::map<GURL, std::string>; 80 using URLMap = std::map<GURL, std::string>;
119 81
120 BlobMap blob_map_; 82 BlobMap blob_map_;
121 URLMap url_to_uuid_; 83 URLMap url_to_uuid_;
122 84
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); 85 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
124 }; 86 };
125 87
126 } // namespace storage 88 } // namespace storage
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 89 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698