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

Unified Diff: storage/browser/blob/blob_storage_context.h

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments Created 5 years 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_context.h
diff --git a/storage/browser/blob/blob_storage_context.h b/storage/browser/blob/blob_storage_context.h
index eba8abea16e9efa6852b78f3646335120360def4..38ec3e5bcd983d3d7950fe85f48d7f845e602277 100644
--- a/storage/browser/blob/blob_storage_context.h
+++ b/storage/browser/blob/blob_storage_context.h
@@ -9,14 +9,14 @@
#include <string>
#include <vector>
+#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "storage/browser/blob/blob_data_handle.h"
-#include "storage/browser/blob/blob_data_item.h"
-#include "storage/browser/blob/blob_data_snapshot.h"
+#include "storage/browser/blob/blob_storage_registry.h"
#include "storage/browser/blob/internal_blob_data.h"
-#include "storage/browser/blob/shareable_blob_data_item.h"
#include "storage/browser/storage_browser_export.h"
+#include "storage/common/blob_storage/blob_storage_constants.h"
#include "storage/common/data_element.h"
class GURL;
@@ -27,13 +27,16 @@ class Time;
}
namespace content {
+class BlobStorageContextTest;
class BlobStorageHost;
}
namespace storage {
class BlobDataBuilder;
-class InternalBlobData;
+class BlobDataItem;
+class BlobDataSnapshot;
+class ShareableBlobDataItem;
// This class handles the logistics of blob Storage within the browser process,
// and maintains a mapping from blob uuid to the data. The class is single
@@ -65,53 +68,47 @@ class STORAGE_EXPORT BlobStorageContext
void RevokePublicBlobURL(const GURL& url);
size_t memory_usage() const { return memory_usage_; }
- size_t blob_count() const { return blob_map_.size(); }
+ size_t memory_available() const {
+ return kBlobStorageMaxMemoryUsage - memory_usage_;
+ }
+
+ const BlobStorageRegistry& registry() { return registry_; }
private:
+ typedef BlobStorageRegistry::Entry BlobRegistryEntry;
friend class content::BlobStorageHost;
+ friend class content::BlobStorageContextTest;
friend class BlobDataHandle::BlobDataHandleShared;
friend class ViewBlobInternalsJob;
- enum EntryFlags {
- EXCEEDED_MEMORY = 1 << 1,
- };
-
- struct BlobMapEntry {
- int refcount;
- int flags;
- // data and data_builder are mutually exclusive.
- scoped_ptr<InternalBlobData> data;
- scoped_ptr<InternalBlobData::Builder> data_builder;
-
- BlobMapEntry();
- BlobMapEntry(int refcount, InternalBlobData::Builder* data);
- ~BlobMapEntry();
-
- bool IsBeingBuilt();
- };
+ void BuildAndStoreBlob(const BlobDataBuilder& external_builder);
- typedef std::map<std::string, BlobMapEntry*> BlobMap;
- typedef std::map<GURL, std::string> BlobURLMap;
-
- // Called by BlobDataHandle.
+ // #### Called by BlobDataHandle ####
scoped_ptr<BlobDataSnapshot> CreateSnapshot(const std::string& uuid);
+ bool IsBeingBuilt(const std::string& uuid) const;
+ // Returns if construction was successful.
+ void RunOnConstructionComplete(const std::string& uuid,
+ const base::Callback<void(bool)>& done);
+ // ##################################
kinuko 2015/12/13 08:41:45 nit: as was discussed we generally prefer not usin
dmurph 2015/12/18 03:22:50 Done.
// ### Methods called by BlobStorageHost ###
- void StartBuildingBlob(const std::string& uuid);
- void AppendBlobDataItem(const std::string& uuid,
- const DataElement& data_item);
- void FinishBuildingBlob(const std::string& uuid, const std::string& type);
- void CancelBuildingBlob(const std::string& uuid);
+ void RegisterBlobUUID(const std::string& uuid);
+ bool MaybeStartAsyncBlobTransfer(const std::string& uuid);
+ void FinishAsyncBlobTransfer(
+ base::Closure done,
+ base::Callback<void(storage::IPCBlobCreationCancelCode)> cancel,
+ const storage::BlobDataBuilder& builder);
+ void CancelAsyncBlobTransfer(
+ const std::string& uuid,
+ base::Callback<void(storage::IPCBlobCreationCancelCode)> cancel,
+ storage::IPCBlobCreationCancelCode code);
+ bool CleanupCanceledAsyncBlobTransfer(const std::string& uuid);
void IncrementBlobRefCount(const std::string& uuid);
void DecrementBlobRefCount(const std::string& uuid);
// #########################################
// Flags the entry for exceeding memory, and resets the builder.
- void BlobEntryExceededMemory(BlobMapEntry* entry);
-
- // Allocates memory to hold the given data element and copies the data over.
- scoped_refptr<BlobDataItem> AllocateBlobItem(const std::string& uuid,
- const DataElement& data_item);
+ void BlobEntryExceededMemory(BlobRegistryEntry* entry);
// Appends the given blob item to the blob builder. The new blob
// retains ownership of data_item if applicable, and returns false if there
@@ -120,6 +117,12 @@ class STORAGE_EXPORT BlobStorageContext
scoped_refptr<BlobDataItem> data_item,
InternalBlobData::Builder* target_blob_data);
+ // Allocates a shareable blob data item, with blob references resolved. If
+ // there isn't enough memory, then a nullptr is returned.
+ scoped_refptr<ShareableBlobDataItem> AllocateShareableBlobDataItem(
+ const std::string& target_blob_uuid,
+ scoped_refptr<BlobDataItem> data_item);
+
// Deconstructs the blob and appends it's contents to the target blob. Items
// are shared if possible, and copied if the given offset and length
// have to split an item.
@@ -129,12 +132,7 @@ class STORAGE_EXPORT BlobStorageContext
uint64_t length,
InternalBlobData::Builder* target_blob_data);
- bool IsInUse(const std::string& uuid);
- bool IsBeingBuilt(const std::string& uuid);
- bool IsUrlRegistered(const GURL& blob_url);
-
- BlobMap blob_map_;
- BlobURLMap public_blob_urls_;
+ BlobStorageRegistry registry_;
// Used to keep track of how much memory is being utilized for blob data,
// we count only the items of TYPE_DATA which are held in memory and not

Powered by Google App Engine
This is Rietveld 408576698