Chromium Code Reviews| 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 322a4c62c1bf1c234fe239a2f6dd80d49b1919f8..1c670ffd91a506bd60cc94a3ccc32a1633c8a7ce 100644 |
| --- a/storage/browser/blob/blob_storage_context.h |
| +++ b/storage/browser/blob/blob_storage_context.h |
| @@ -7,12 +7,15 @@ |
| #include <map> |
| #include <string> |
| +#include <vector> |
| #include "base/memory/ref_counted.h" |
| -#include "base/memory/scoped_ptr.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/internal_blob_data.h" |
| +#include "storage/browser/blob/shareable_blob_data_item.h" |
| #include "storage/browser/storage_browser_export.h" |
| #include "storage/common/data_element.h" |
| @@ -29,8 +32,8 @@ class BlobStorageHost; |
| namespace storage { |
| -class BlobDataHandle; |
| class BlobDataBuilder; |
| +class InternalBlobData; |
| // 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 |
| @@ -47,12 +50,19 @@ class STORAGE_EXPORT BlobStorageContext |
| // Useful for coining blobs from within the browser process. If the |
| // blob cannot be added due to memory consumption, returns NULL. |
| - scoped_ptr<BlobDataHandle> AddFinishedBlob(const BlobDataBuilder& blob_data); |
| + // A builder should not be used twice to create blobs, as the internal |
| + // resources are refcounted instead of copied for memory efficiency. |
| + // To cleanly use a builder multiple times, please call Clone() on the |
| + // builder, or even better for memory savings, clear the builder and append |
| + // the previously constructed blob. |
| + scoped_ptr<BlobDataHandle> AddFinishedBlob(BlobDataBuilder* builder); |
| // Useful for coining blob urls from within the browser process. |
| bool RegisterPublicBlobURL(const GURL& url, const std::string& uuid); |
| void RevokePublicBlobURL(const GURL& url); |
| + size_t memory_usage() const { return memory_usage_; } |
| + |
| private: |
| friend class content::BlobStorageHost; |
| friend class BlobDataHandle::BlobDataHandleShared; |
| @@ -66,11 +76,11 @@ class STORAGE_EXPORT BlobStorageContext |
| int refcount; |
| int flags; |
| // data and data_builder are mutually exclusive. |
| - scoped_ptr<BlobDataSnapshot> data; |
| - scoped_ptr<BlobDataBuilder> data_builder; |
| + scoped_ptr<InternalBlobData> data; |
| + scoped_ptr<InternalBlobData::Builder> data_builder; |
| BlobMapEntry(); |
| - BlobMapEntry(int refcount, BlobDataBuilder* data); |
| + BlobMapEntry(int refcount, InternalBlobData::Builder* data); |
| ~BlobMapEntry(); |
| bool IsBeingBuilt(); |
| @@ -82,6 +92,7 @@ class STORAGE_EXPORT BlobStorageContext |
| // Called by BlobDataHandle. |
| scoped_ptr<BlobDataSnapshot> CreateSnapshot(const std::string& uuid); |
| + // ### Methods called by BlobStorageHost ### |
| void StartBuildingBlob(const std::string& uuid); |
| void AppendBlobDataItem(const std::string& uuid, |
| const DataElement& data_item); |
| @@ -89,24 +100,30 @@ class STORAGE_EXPORT BlobStorageContext |
| void CancelBuildingBlob(const std::string& uuid); |
| void IncrementBlobRefCount(const std::string& uuid); |
| void DecrementBlobRefCount(const std::string& uuid); |
| - |
| - bool ExpandStorageItems(BlobDataBuilder* target_blob_data, |
| - const BlobDataSnapshot& src_blob_data, |
| - uint64 offset, |
| - uint64 length); |
| - bool AppendBytesItem(BlobDataBuilder* target_blob_data, |
| - const char* data, |
| - int64 length); |
| - void AppendFileItem(BlobDataBuilder* target_blob_data, |
| - const base::FilePath& file_path, |
| - uint64 offset, |
| - uint64 length, |
| - const base::Time& expected_modification_time); |
| - void AppendFileSystemFileItem(BlobDataBuilder* target_blob_data, |
| - const GURL& url, |
| - uint64 offset, |
| - uint64 length, |
| - const base::Time& expected_modification_time); |
| + // ######################################### |
| + |
| + // 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); |
| + |
| + // Appends the given blob item to the blob builder. The new blob |
| + // retains ownership of data_item if applicable, and returns false if there |
| + // wasn't enough memory to hold the item. |
| + bool AppendAllocatedBlobItem(const std::string& target_blob_uuid, |
| + InternalBlobData::Builder* target_blob_data, |
| + 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. |
| + bool AppendBlob(const std::string& target_blob_uuid, |
| + InternalBlobData::Builder* target_blob_data, |
|
Alexei Svitkine (slow)
2015/02/10 16:05:05
Modifiable parameters should be last per the style
dmurph
2015/02/10 22:17:47
Done.
|
| + const InternalBlobData& blob, |
| + size_t offset, |
| + size_t length); |
| bool IsInUse(const std::string& uuid); |
| bool IsBeingBuilt(const std::string& uuid); |
| @@ -118,7 +135,7 @@ class STORAGE_EXPORT BlobStorageContext |
| // 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 |
| // items of TYPE_FILE. |
| - int64 memory_usage_; |
| + size_t memory_usage_; |
| DISALLOW_COPY_AND_ASSIGN(BlobStorageContext); |
| }; |