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

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

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed layout tests, cleaned up test visibility Created 4 years, 5 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/internal_blob_data.h
diff --git a/storage/browser/blob/internal_blob_data.h b/storage/browser/blob/internal_blob_data.h
index 65db2f3cdc322fe85a8c01e275d2c988601b95e9..ce3f54e8c85342c94f00aac24277c3d68ae66238 100644
--- a/storage/browser/blob/internal_blob_data.h
+++ b/storage/browser/blob/internal_blob_data.h
@@ -11,70 +11,113 @@
#include <string>
#include <vector>
+#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "storage/browser/blob/shareable_blob_data_item.h"
+#include "storage/browser/blob/blob_memory_controller.h"
+#include "storage/browser/storage_browser_export.h"
namespace storage {
+class BlobDataHandle;
+class ShareableBlobDataItem;
class ViewBlobInternalsJob;
-// This class represents a blob in the BlobStorageContext. It is constructed
-// using the internal Builder class.
-class InternalBlobData {
+// This class represents a blob. We export this only for unit tests.
+class STORAGE_EXPORT InternalBlobData {
public:
+ struct STORAGE_EXPORT ItemCopyEntry {
+ ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
+ size_t source_item_offset,
+ scoped_refptr<ShareableBlobDataItem> dest_item);
+ ~ItemCopyEntry();
+ ItemCopyEntry(const ItemCopyEntry&);
+
+ scoped_refptr<ShareableBlobDataItem> source_item;
+ size_t source_item_offset = 0;
+ scoped_refptr<ShareableBlobDataItem> dest_item;
+ };
+
+ struct STORAGE_EXPORT BuildingState {
+ BuildingState();
+ ~BuildingState();
+
+ // Stored if the BlobDataBuilder we're given to construct has pending data,
+ // and we need to tell the user when to start populating this data.
+ BlobStatusCallback ready_for_user_population_callback;
+ bool waiting_for_user_population = false;
+
+ // Stores all blobs that we're depending on for building. This keeps the
+ // blobs alive while we build our blob.
+ std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
+ size_t dependent_blobs_building = 0;
+
+ // We change our status to PENDING_MEMORY_QUOTA when we populate this. If
+ // we need to cancel before our quota callback is triggered, then we use
+ // this entry to cancel our request in the memory controller.
+ BlobMemoryController::PendingConstructionEntry pending_copies_memory_entry;
+
+ // These are copies from a referenced blob item to our blob items. Some of
+ // these entries may have changed from bytes to files if they were paged.
+ std::vector<ItemCopyEntry> copies;
+
+ std::vector<BlobStatusCallback> build_completion_callbacks;
+ };
+
+ InternalBlobData(const std::string& content_type,
+ const std::string& content_disposition);
~InternalBlobData();
- protected:
- friend class BlobStorageContext;
- friend class BlobStorageRegistry;
- friend class ViewBlobInternalsJob;
+ // Appends the given shared blob data item to this object. We add |my_uuid|
+ // to the shareable item's uuid set.
+ void AppendSharedBlobItem(const std::string& my_uuid,
+ scoped_refptr<ShareableBlobDataItem> item);
// Removes the given blob uuid from the internal ShareableBlobDataItems.
// This is called when this blob is being destroyed.
void RemoveBlobFromShareableItems(const std::string& blob_uuid);
- const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const;
-
// Gets the memory used by this blob that is not shared by other blobs. This
// also doesn't count duplicate items.
size_t GetUnsharedMemoryUsage() const;
- // Gets the memory used by this blob. Total memory includes memory of items
- // possibly shared with other blobs, or items that appear multiple times in
- // this blob. Unshared memory is memory used by this blob that is not shared
- // by other blobs.
- void GetMemoryUsage(size_t* total_memory, size_t* unshared_memory);
+ BlobStatus status() const { return status_; }
- private:
- friend class Builder;
- InternalBlobData();
+ size_t refcount() const { return refcount_; }
- std::string content_type_;
- std::string content_disposition_;
- std::vector<scoped_refptr<ShareableBlobDataItem>> items_;
+ const std::string& content_type() const { return content_type_; }
- class Builder {
- public:
- Builder();
- ~Builder();
+ const std::string& content_disposition() const {
+ return content_disposition_;
+ }
- void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item);
+ // Total size of this blob in bytes.
+ uint64_t total_size() const { return size_; };
- // Gets the memory used by this builder that is not shared with other blobs.
- size_t GetNonsharedMemoryUsage() const;
+ const std::vector<uint64_t>& offsets() const { return offsets_; }
- // Removes the given blob uuid from the internal ShareableBlobDataItems.
- // This is called on destruction of the blob if we're still building it.
- void RemoveBlobFromShareableItems(const std::string& blob_uuid);
+ const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const;
- // The builder is invalid after calling this method.
- std::unique_ptr<::storage::InternalBlobData> Build();
+ private:
+ friend class BlobStorageContext;
- private:
- std::unique_ptr<::storage::InternalBlobData> data_;
+ BlobStatus status_ = BlobStatus::PENDING_MEMORY_REQUEST;
+ size_t refcount_ = 0;
- DISALLOW_COPY_AND_ASSIGN(Builder);
- };
+ // Metadata.
+ std::string content_type_;
+ std::string content_disposition_;
+
+ std::vector<scoped_refptr<ShareableBlobDataItem>> items_;
+
+ // Size in bytes. IFF we're a single file then this can be uint64_max.
+ uint64_t size_ = 0;
+
+ // Only populated if len(items_) > 1. Used for binary search.
+ // Since the offset of the first item is always 0, we exclude this.
+ std::vector<uint64_t> offsets_;
+
+ // Only populated if our status is PENDING_*.
+ std::unique_ptr<BuildingState> building_state_;
DISALLOW_COPY_AND_ASSIGN(InternalBlobData);
};

Powered by Google App Engine
This is Rietveld 408576698