OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_FLATTENER_H_ |
| 6 #define STORAGE_BROWSER_BLOB_BLOB_FLATTENER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/numerics/safe_math.h" |
| 14 #include "storage/browser/blob/blob_storage_registry.h" |
| 15 #include "storage/browser/blob/internal_blob_data.h" |
| 16 #include "storage/browser/storage_browser_export.h" |
| 17 |
| 18 namespace storage { |
| 19 class BlobDataBuilder; |
| 20 class InternalBlobData; |
| 21 class ShareableBlobDataItem; |
| 22 |
| 23 // The class takes an input BlobDataBuilder and turns it into our |
| 24 // InternalBlobData representation. This includes 'flattening' out blob |
| 25 // references by extracting the ShareableBlobDataItem slice from the reference |
| 26 // and including those items instead. The resulting flattened blob (both regular |
| 27 // items and items from other blobs) is put into the |output_blob|. We keep |
| 28 // track of edge cases like partial slicing on data or pending file entries, |
| 29 // and calculate the total & required memory for this blob. |
| 30 // |
| 31 // This class is only used once while building a blob, and is ephemeral in the |
| 32 // blob construction (the data is immediately consumed and then it gets |
| 33 // destructed). |
| 34 struct STORAGE_EXPORT BlobFlattener { |
| 35 BlobFlattener(const BlobDataBuilder& input_builder, |
| 36 InternalBlobData* output_blob, |
| 37 BlobStorageRegistry* registry); |
| 38 ~BlobFlattener(); |
| 39 |
| 40 // This can be: |
| 41 // * DONE if we're populated and don't need quota. |
| 42 // * PENDING if there's pending data that the user needs to |
| 43 // populate. This also means we need to request quota. |
| 44 // * INVALID_CONSTRUCTION_ARGUMENTS if we have invalid input, or |
| 45 // * REFERENCED_BLOB_BROKEN if one of the referenced blobs is broken or we |
| 46 // reference ourself. |
| 47 BlobStatus status = BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS; |
| 48 |
| 49 // This is the total size of the blob, including all memory, files, etc. |
| 50 base::CheckedNumeric<uint64_t> total_size; |
| 51 |
| 52 // This contains all blobs referenced. |
| 53 std::vector<std::pair<std::string, InternalBlobData*>> dependent_blobs; |
| 54 |
| 55 // This is the total amount of quota space needed transporting this blob. |
| 56 base::CheckedNumeric<uint64_t> transport_quota_needed; |
| 57 std::vector<ShareableBlobDataItem*> transport_pending_items; |
| 58 |
| 59 // Total amount of space needed for copying depending blob items. |
| 60 base::CheckedNumeric<uint64_t> copy_quota_needed; |
| 61 std::vector<ShareableBlobDataItem*> copy_pending_items; |
| 62 |
| 63 // These record all future copies we'll need to do from referenced blobs. This |
| 64 // happens when we do a partial slice from a pending data or file item. |
| 65 std::vector<InternalBlobData::ItemCopyEntry> copies; |
| 66 }; |
| 67 |
| 68 // This class handles the cases where the slice partially intersects with |
| 69 // either a data item (which we want to copy instead of share when it's partial |
| 70 // intersection) or a 'future file item', which isn't populated yet in the |
| 71 // source blob so we need to copy it over later when it's completed. |
| 72 struct STORAGE_EXPORT BlobSlice { |
| 73 BlobSlice(const InternalBlobData& source, |
| 74 uint64_t slice_offset, |
| 75 uint64_t slice_size); |
| 76 ~BlobSlice(); |
| 77 |
| 78 // The is the amount of memory we'll be copying from the source blob, as we |
| 79 // can't share a partial data item. This can happen on the first and/or last |
| 80 // item our slice is intersecting. |
| 81 size_t copying_memory_size = 0; |
| 82 |
| 83 size_t first_item_slice_offset = 0; |
| 84 // Populated if our first slice item is a temporary item that we'll copy to |
| 85 // later from this |first_source_item|, at offset |first_item_slice_offset|. |
| 86 scoped_refptr<ShareableBlobDataItem> first_source_item; |
| 87 // Populated if our last slice item is a temporary item that we'll copy to |
| 88 // later from this |last_source_item|. |
| 89 scoped_refptr<ShareableBlobDataItem> last_source_item; |
| 90 |
| 91 std::vector<scoped_refptr<ShareableBlobDataItem>> dest_items; |
| 92 }; |
| 93 |
| 94 } // namespace storage |
| 95 #endif // STORAGE_BROWSER_BLOB_BLOB_FLATTENER_H_ |
OLD | NEW |