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

Unified 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: comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: storage/browser/blob/blob_storage_registry.h
diff --git a/storage/browser/blob/blob_storage_registry.h b/storage/browser/blob/blob_storage_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..88f383cb8d87b79e637245be4a7388b5f0988d30
--- /dev/null
+++ b/storage/browser/blob/blob_storage_registry.h
@@ -0,0 +1,118 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
+#define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
+
+#include <map>
+#include <string>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "storage/browser/blob/internal_blob_data.h"
+#include "storage/browser/storage_browser_export.h"
+
+class GURL;
+
+namespace storage {
+
+// This class stores the blob data in the various states of construction, as
+// well as URL mappings to blob uuids.
+// Implementation notes:
+// * There is no implicit refcounting in this class, except for setting the
+// refcount to 1 on registration.
+// * When removing a uuid registration, we do not check for URL mappings to that
+// uuid. The user must keep track of these.
+class STORAGE_EXPORT BlobStorageRegistry {
+ public:
+ enum class BlobState {
+ UNKNOWN = 0,
+ // First the renderer reserves the uuid.
+ RESERVED,
+ // Second, we are asynchronously transporting data to the browser.
+ ASYNC_TRANSPORTATION,
+ // Third, we construct the blob when we have all of the data.
+ CONSTRUCTION,
+ // Finally, the blob is built.
+ ACTIVE
+ };
+ enum Flags { EXCEEDED_MEMORY = 1 << 1 };
+
+ struct Entry {
+ size_t refcount;
+ BlobState state;
+ int flags;
+ std::vector<base::Callback<void(bool)>> construction_complete_callbacks;
+
+ // data and data_builder are mutually exclusive.
+ scoped_ptr<InternalBlobData> data;
+ scoped_ptr<InternalBlobData::Builder> data_builder;
+
+ Entry(int refcount, BlobState state);
+ ~Entry();
+
+ bool IsFlagSet(int flag) { return ((flags & flag) != 0); }
michaeln 2015/10/09 02:16:14 could be const
dmurph 2015/10/10 00:11:33 Removed instead, as per other comment.
+ void SetFlag(int flag);
+ void UnsetFlag(int flag);
michaeln 2015/10/09 02:16:14 these could all be inlined as oneliners
dmurph 2015/10/10 00:11:33 Removed instead, as per other comment.
+ };
+
+ BlobStorageRegistry();
+ virtual ~BlobStorageRegistry();
michaeln 2015/10/09 02:16:14 are there subclasses? if not then nix virtual
dmurph 2015/10/10 00:11:33 Done.
+
+ // Creates the blob entry with a refcount of 1 and a state of RESERVED. If
+ // the blob is already in use, we return null.
+ Entry* CreateEntry(const std::string& uuid);
+
+ // Removes the blob entry with the given uuid. This does not unmap any
+ // URLs that are pointing to this uuid. Returns if the entry existed.
+ bool DeleteEntry(const std::string& uuid);
+
+ // Returns if the uuid is mapped to an entry.
+ bool HasEntry(const std::string& uuid) const;
michaeln 2015/10/09 02:16:14 not really needed given GetEntry()
dmurph 2015/10/10 00:11:33 Done.
+
+ // Gets the blob entry for the given uuid. Returns nullptr if the entry
+ // does not exist.
+ Entry* GetBlobEntry(const std::string& uuid);
michaeln 2015/10/09 02:16:14 nit: GetEntry to harmonize with Create/Delete/Has
dmurph 2015/10/10 00:11:33 Done.
+
+ // Gets the state for the given uuid. Returns BlobState::UNKNOWN if the entry
+ // does not exist.
+ BlobState GetBlobState(const std::string& uuid) const;
+
+ // Performs a test-and-set on the state of the given blob. If the blob doesn't
+ // exist, or the state isn't as expected, we return false. Otherwise we set
+ // the new state and return true.
+ bool TestAndSetState(const std::string& uuid,
+ BlobState expected,
+ BlobState set);
+
+ // Creates a url mapping from blob uuid to the given url. Returns false if
+ // the uuid isn't mapped to an entry or if there already is a map for the URL.
+ bool CreateUrlMapping(const GURL& url, const std::string& uuid);
+
+ // Removes the given URL mapping. Optionally populates a uuid string of the
+ // removed entry uuid. Returns false if the url isn't mapped.
+ bool DeleteURLMapping(const GURL& url, std::string* uuid);
+
+ // Returns if the url is mapped to a blob uuid.
+ bool IsURLMapped(const GURL& blob_url) const;
+
+ // Returns the entry from the given url, and optionally populates the uuid for
+ // that entry. Returns a nullptr if the mapping or entry doesn't exist.
+ Entry* GetBlobEntryFromURL(const GURL& url, std::string* uuid);
michaeln 2015/10/09 02:16:14 nit: ditto GetEntryFromURL naming
dmurph 2015/10/10 00:11:33 Done.
+
+ size_t blob_count() const { return blob_map_.size(); }
+ size_t url_count() const { return url_to_uuid_.size(); }
+
+ private:
+ typedef std::map<std::string, Entry*> BlobMap;
+ typedef std::map<GURL, std::string> URLMap;
+
+ BlobMap blob_map_;
+ URLMap url_to_uuid_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
+};
+
+} // namespace storage
+#endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698