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

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: correction Created 5 years, 2 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 #include <vector>
11
12 #include "base/callback_forward.h"
13 #include "base/macros.h"
14 #include "storage/browser/blob/internal_blob_data.h"
15 #include "storage/browser/storage_browser_export.h"
16
17 class GURL;
18
19 namespace storage {
20
21 // This class stores the blob data in the various states of construction, as
22 // well as URL mappings to blob uuids.
23 // Implementation notes:
24 // * There is no implicit refcounting in this class, except for setting the
25 // refcount to 1 on registration.
26 // * When removing a uuid registration, we do not check for URL mappings to that
27 // uuid. The user must keep track of these.
28 class STORAGE_EXPORT BlobStorageRegistry {
29 public:
30 enum class BlobState {
31 UNKNOWN = 0,
michaeln 2015/10/12 19:50:13 Thnx for flattening the helpers out. I think ther
dmurph 2015/10/12 20:08:28 This is a protection against uninitialized entries
michaeln 2015/10/12 22:17:14 Is it common to start the first value at 1 instead
32 // First the renderer reserves the uuid.
33 RESERVED,
34 // Second, we are asynchronously transporting data to the browser.
35 ASYNC_TRANSPORTATION,
36 // Third, we construct the blob when we have all of the data.
37 CONSTRUCTION,
38 // Finally, the blob is built.
39 ACTIVE
40 };
41 enum Flags { EXCEEDED_MEMORY = 1 << 1 };
kinuko 2015/10/12 14:34:58 Looks like this one's no longer (or at least not f
dmurph 2015/10/12 20:08:28 Whoops, yeah, I didn't remove it.
42
43 struct Entry {
44 size_t refcount;
45 BlobState state;
46 std::vector<base::Callback<void(bool)>> construction_complete_callbacks;
47
48 // Flags
49 bool exceeded_memory;
kinuko 2015/10/12 14:34:58 at this point this bool is not really used either?
dmurph 2015/10/12 20:08:28 This bool is definitely used right now (instead of
50
51 // data and data_builder are mutually exclusive.
52 scoped_ptr<InternalBlobData> data;
53 scoped_ptr<InternalBlobData::Builder> data_builder;
54
55 Entry(int refcount, BlobState state);
kinuko 2015/10/12 14:34:58 maybe should we delete default constructor? (Entry
dmurph 2015/10/12 20:08:28 Done.
56 ~Entry();
57
58 // Performs a test-and-set on the state of the given blob. If the state
59 // isn't as expected, we return false. Otherwise we set the new state and
60 // return true.
61 bool TestAndSetState(BlobState expected, BlobState set);
62 };
63
64 BlobStorageRegistry();
65 ~BlobStorageRegistry();
66
67 // Creates the blob entry with a refcount of 1 and a state of RESERVED. If
68 // the blob is already in use, we return null.
69 Entry* CreateEntry(const std::string& uuid);
70
71 // Removes the blob entry with the given uuid. This does not unmap any
72 // URLs that are pointing to this uuid. Returns if the entry existed.
73 bool DeleteEntry(const std::string& uuid);
74
75 // Returns if the uuid is mapped to an entry.
76 bool HasEntry(const std::string& uuid) const;
kinuko 2015/10/12 14:34:58 feels a bit duplicated with GetEntry?
dmurph 2015/10/12 20:08:28 Removed.
77
78 // Gets the blob entry for the given uuid. Returns nullptr if the entry
79 // does not exist.
80 Entry* GetEntry(const std::string& uuid) const;
kinuko 2015/10/12 14:34:58 returning a non-const pointer to internal map from
michaeln 2015/10/12 19:50:13 ooops, i suggested this in a earlier comment, i ma
dmurph 2015/10/12 20:08:28 Done.
81
82 // Creates a url mapping from blob uuid to the given url. Returns false if
83 // the uuid isn't mapped to an entry or if there already is a map for the URL.
84 bool CreateUrlMapping(const GURL& url, const std::string& uuid);
85
86 // Removes the given URL mapping. Optionally populates a uuid string of the
87 // removed entry uuid. Returns false if the url isn't mapped.
88 bool DeleteURLMapping(const GURL& url, std::string* uuid);
89
90 // Returns if the url is mapped to a blob uuid.
91 bool IsURLMapped(const GURL& blob_url) const;
92
93 // Returns the entry from the given url, and optionally populates the uuid for
94 // that entry. Returns a nullptr if the mapping or entry doesn't exist.
95 Entry* GetEntryFromURL(const GURL& url, std::string* uuid) const;
96
97 size_t blob_count() const { return blob_map_.size(); }
98 size_t url_count() const { return url_to_uuid_.size(); }
99
100 private:
101 typedef std::map<std::string, Entry*> BlobMap;
michaeln 2015/10/12 19:50:13 we might want to use ScopedPtrHashMap instead, wdy
dmurph 2015/10/12 20:08:28 Sure.
102 typedef std::map<GURL, std::string> URLMap;
kinuko 2015/10/12 14:34:58 nit: prefer using rather than typedef
dmurph 2015/10/12 20:08:28 Done.
103
104 BlobMap blob_map_;
105 URLMap url_to_uuid_;
106
107 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
108 };
109
110 } // namespace storage
111 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698