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

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

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined BlobSlice & BlobFlattener files, more comments, a little cleanup. 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/blob_flattener.h
diff --git a/storage/browser/blob/blob_flattener.h b/storage/browser/blob/blob_flattener.h
new file mode 100644
index 0000000000000000000000000000000000000000..8c0295ba019d88aa792b1ad7667dda7c68236f41
--- /dev/null
+++ b/storage/browser/blob/blob_flattener.h
@@ -0,0 +1,95 @@
+// Copyright 2016 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_FLATTENER_H_
+#define STORAGE_BROWSER_BLOB_BLOB_FLATTENER_H_
+
+#include <map>
+#include <string>
+#include <utility>
+
+#include "base/macros.h"
+#include "base/numerics/safe_math.h"
+#include "storage/browser/blob/blob_storage_registry.h"
+#include "storage/browser/blob/internal_blob_data.h"
+#include "storage/browser/storage_browser_export.h"
+
+namespace storage {
+class BlobDataBuilder;
+class InternalBlobData;
+class ShareableBlobDataItem;
+
+// The class takes an input BlobDataBuilder and turns it into our
+// InternalBlobData representation. This includes 'flattening' out blob
+// references by extracting the ShareableBlobDataItem slice from the reference
+// and including those items instead. The resulting flattened blob (both regular
+// items and items from other blobs) is put into the |output_blob|. We keep
+// track of edge cases like partial slicing on data or pending file entries,
+// and calculate the total & required memory for this blob.
+//
+// This class is only used once while building a blob, and is ephemeral in the
+// blob construction (the data is immediately consumed and then it gets
+// destructed).
+struct STORAGE_EXPORT BlobFlattener {
+ BlobFlattener(const BlobDataBuilder& input_builder,
+ InternalBlobData* output_blob,
+ BlobStorageRegistry* registry);
+ ~BlobFlattener();
+
+ // This can be:
+ // * DONE if we're populated and don't need quota.
+ // * PENDING if there's pending data that the user needs to
+ // populate. This also means we need to request quota.
+ // * INVALID_CONSTRUCTION_ARGUMENTS if we have invalid input, or
+ // * REFERENCED_BLOB_BROKEN if one of the referenced blobs is broken or we
+ // reference ourself.
+ BlobStatus status = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS;
+
+ // This is the total size of the blob, including all memory, files, etc.
+ base::CheckedNumeric<uint64_t> total_size;
+
+ // This contains all blobs referenced.
+ std::vector<std::pair<std::string, InternalBlobData*>> dependent_blobs;
+
+ // This is the total amount of quota space needed transporting this blob.
+ base::CheckedNumeric<uint64_t> transport_quota_needed;
+ std::vector<ShareableBlobDataItem*> transport_pending_items;
+
+ // Total amount of space needed for copying depending blob items.
+ base::CheckedNumeric<uint64_t> copy_quota_needed;
+ std::vector<ShareableBlobDataItem*> copy_pending_items;
+
+ // These record all future copies we'll need to do from referenced blobs. This
+ // happens when we do a partial slice from a pending data or file item.
+ std::vector<InternalBlobData::ItemCopyEntry> copies;
+};
+
+// This class handles the cases where the slice partially intersects with
+// either a data item (which we want to copy instead of share when it's partial
+// intersection) or a 'future file item', which isn't populated yet in the
+// source blob so we need to copy it over later when it's completed.
+struct STORAGE_EXPORT BlobSlice {
+ BlobSlice(const InternalBlobData& source,
+ uint64_t slice_offset,
+ uint64_t slice_size);
+ ~BlobSlice();
+
+ // The is the amount of memory we'll be copying from the source blob, as we
+ // can't share a partial data item. This can happen on the first and/or last
+ // item our slice is intersecting.
+ size_t copying_memory_size = 0;
+
+ size_t first_item_slice_offset = 0;
+ // Populated if our first slice item is a temporary item that we'll copy to
+ // later from this |first_source_item|, at offset |first_item_slice_offset|.
+ scoped_refptr<ShareableBlobDataItem> first_source_item;
+ // Populated if our last slice item is a temporary item that we'll copy to
+ // later from this |last_source_item|.
+ scoped_refptr<ShareableBlobDataItem> last_source_item;
+
+ std::vector<scoped_refptr<ShareableBlobDataItem>> dest_items;
+};
+
+} // namespace storage
+#endif // STORAGE_BROWSER_BLOB_BLOB_FLATTENER_H_

Powered by Google App Engine
This is Rietveld 408576698