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

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

Issue 1287303002: [BlobAsync] Patch 1: BlobStorageRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "storage/browser/blob/internal_blob_data.h"
14 #include "storage/browser/storage_browser_export.h"
15
16 class GURL;
17
18 namespace storage {
19
20 // This class stores the blob data in the various states of construction, as
21 // well as URL mappings to blob uuids.
22 // Implementation notes:
23 // * There is no implicit refcounting in this class, except for setting the
24 // refcount to 1 on registration.
25 // * When removing a uuid registration, we do not check for URL mappings to that
26 // uuid. The user must keep track of these.
27 class STORAGE_EXPORT BlobStorageRegistry {
michaeln 2015/08/18 02:25:46 Terminology nit that i think may be worth reconcil
dmurph 2015/09/15 00:54:34 Hm. I thought 'Registry' did a pretty good job of
28 public:
29 enum class BlobState {
30 UNKNOWN = 0,
31 // First the renderer reserves the uuid.
32 RESERVED,
33 // Second, the we are asynchronously transporting data to the browser.
kinuko 2015/08/14 10:12:18 nit: 'the we' -> 'we'
dmurph 2015/09/15 00:54:34 Done.
34 ASYNC_TRANSPORTATION,
35 // Third, we construct the blob when we have all of the data
kinuko 2015/08/14 10:12:18 nit: period at the end of comments
dmurph 2015/09/15 00:54:34 Done.
36 CONSTRUCTION,
37 // Finally, the blob is built.
38 ACTIVE
39 };
40 enum BlobFlags { EXCEEDED_MEMORY = 1 << 1 };
kinuko 2015/08/14 10:12:19 nit: I'd call this just Flags, or rename the follo
dmurph 2015/09/15 00:54:34 Done.
41
42 struct BlobRegistryEntry {
michaeln 2015/08/18 02:25:46 since we're in a class named BlobRegistry the pref
dmurph 2015/09/15 00:54:34 Sounds great, done.
43 size_t refcount;
44 BlobState state;
45 int flags;
46 std::vector<base::Callback<void(bool)>> construction_complete_callbacks;
47
48 // data and data_builder are mutually exclusive.
49 scoped_ptr<InternalBlobData> data;
50 scoped_ptr<InternalBlobData::Builder> data_builder;
51
52 BlobRegistryEntry(int refcount, BlobState state);
53 ~BlobRegistryEntry();
54
55 bool IsFlagSet(int flag);
56 void SetFlag(int flag);
57 void UnsetFlag(int flag);
kinuko 2015/08/14 10:12:18 No one's calling these for now? If so I'd just dro
dmurph 2015/09/15 00:54:34 No one is calling anything in this patch haha. Th
58 };
59
60 BlobStorageRegistry();
61 virtual ~BlobStorageRegistry();
62
63 // Registers the blob entry with a refcount of 1 and a state of RESERVED. If
64 // the blob is already in use, we return null.
65 BlobRegistryEntry* RegisterBlobUUID(const std::string& uuid);
michaeln 2015/08/18 02:25:47 Here's a stab not applying 'register' as a verb to
dmurph 2015/09/15 00:54:34 Sounds good.
66
67 // Removes the blob entry with the given uuid. This does not unregister any
68 // URLs that are pointing to this uuid. Returns if the entry existed.
69 bool RemoveBlobEntry(const std::string& uuid);
70
71 // Returns if the uuid is currently registered.
72 bool IsUUIDRegistered(const std::string& uuid) const;
73
74 // Gets the blob entry for the given uuid. Returns nullptr if the entry
75 // does not exist.
76 BlobRegistryEntry* GetBlobEntry(const std::string& uuid);
77
78 // Gets the state for the given uuid. Returns BlobState::UNKNOWN if the entry
79 // does not exist.
kinuko 2015/08/14 10:12:18 Just returning UNKNOWN doesn't tell if it exists o
michaeln 2015/08/18 02:25:47 Is this helper really needed at all? If i understa
dmurph 2015/09/15 00:54:34 So this actually helps me avoid an extra map looku
michaeln 2015/10/09 02:16:14 Personally, i'm not a fan of the convenience metho
80 BlobState GetBlobState(const std::string& uuid) const;
81
82 // Performs a test-and-set on the state of the given blob. If the blob doesn't
83 // exist, or the state isn't as expected, we return false. Otherwise we set
84 // the new state and return true.
85 bool TestAndSetState(const std::string& uuid,
michaeln 2015/08/18 02:25:47 This helper could go on the Entry class itself.
dmurph 2015/09/15 00:54:34 It's more useful like this currently, as it remove
86 BlobState expected,
87 BlobState set);
88
89 // Registers a url mapping from blob uuid to the given url. Returns false if
90 // the uuid isn't registered or if there already is a map for the URL.
91 bool RegisterURLMapping(const GURL& url, const std::string& uuid);
92
93 // Removes the given URL mapping. Optionally populates a uuid string of the
94 // removed entry uuid. Returns false if the url isn't mapped.
95 bool RemoveURLMapping(const GURL& url, std::string* uuid);
96
97 // Returns if the url is mapped to a blob uuid.
98 bool IsURLMapped(const GURL& blob_url) const;
99
100 // Returns the entry from the given url, and optionally populates the uuid for
101 // that entry. Returns a nullptr if the mapping or entry doesn't exist.
102 BlobRegistryEntry* GetBlobEntryFromURL(const GURL& url, std::string* uuid);
103
104 size_t blob_count() const { return blob_map_.size(); }
105 size_t url_count() const { return url_to_uuid_.size(); }
106
107 private:
108 friend class ViewBlobInternalsJob;
kinuko 2015/08/14 10:12:19 nit: this friend's not necessary yet?
dmurph 2015/09/15 00:54:34 Not yet....
109 typedef std::map<std::string, BlobRegistryEntry*> BlobMap;
110 typedef std::map<GURL, std::string> URLMap;
111
112 BlobMap blob_map_;
113 URLMap url_to_uuid_;
114
115 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
116 };
117
118 } // namespace storage
119 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698