| Index: storage/browser/blob/blob_transport_strategy.h
|
| diff --git a/storage/browser/blob/blob_transport_strategy.h b/storage/browser/blob/blob_transport_strategy.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..82044eb9eae4c90e67b6de9e3992ae41895f0b91
|
| --- /dev/null
|
| +++ b/storage/browser/blob/blob_transport_strategy.h
|
| @@ -0,0 +1,128 @@
|
| +// Copyright 2015 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_TRANSPORT_STRATEGY_H_
|
| +#define STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_STRATEGY_H_
|
| +
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| +#include "storage/browser/storage_browser_export.h"
|
| +#include "storage/common/data_element.h"
|
| +#include "storage/common/fileapi/blob_item_bytes_request.h"
|
| +
|
| +namespace storage {
|
| +
|
| +// This class determines and stores the strategy for asynchronously transporting
|
| +// memory from the renderer to the browser. This involves two transformations:
|
| +// 1. Transforming the data storage to be efficient in-transport. This can
|
| +// mean that data is consolidated from cross-blob or cross-file boundaries
|
| +// in the blob in a common block of shared memory or a file.
|
| +// 2. Transforming the transport data into the browser storage representation.
|
| +// This can simply mirror the renderer representation, or it can be instead
|
| +// pointing to transport representation with offsets and sizes.
|
| +//
|
| +// The initial implementation of this is simple, but the protocol allows any
|
| +// sort of flexibility, as everything has an offset and size specified.
|
| +class STORAGE_EXPORT BlobTransportStrategy {
|
| + public:
|
| + enum Mode { MODE_UNKNOWN = 0, MODE_NO_DISK, MODE_DISK };
|
| +
|
| + enum Error {
|
| + ERROR_NONE = 0,
|
| + ERROR_TOO_LARGE, // This item can't fit in disk or memory
|
| + ERROR_INVALID_PARAMS
|
| + };
|
| +
|
| + struct MemoryItemRequest {
|
| + size_t browser_item_index;
|
| + size_t browser_item_offset;
|
| + BlobItemBytesRequest message;
|
| + };
|
| +
|
| + BlobTransportStrategy();
|
| + virtual ~BlobTransportStrategy();
|
| +
|
| + // Determines the requests, file handles, and memory handles for the given
|
| + // system state and blob description. Can be called multiple times to reset
|
| + // the object.
|
| + //
|
| + // mode: The transportation mode, either MODE_NO_DISK or MODE_DISK. NO_DISK
|
| + // means that we won't transport files over disk.
|
| + // max_ipc_memory_size: Maximum amount of memory that we can include in our
|
| + // IPC message.
|
| + // max_shared_memory_size: Maximum amount of memory we can store
|
| + // in a shared memory block.
|
| + // max_file_size: Maximum amount of memory we can store in a file.
|
| + // max_blob_in_memory_size: Maximum size of a blob before it skips being
|
| + // stored in memory and goes straight to a file.
|
| + // disk_space_left: The amount of disk space left.
|
| + // memory_left: The amount of memory left in our memory cache.
|
| + void Initialize(Mode mode,
|
| + size_t max_ipc_memory_size,
|
| + size_t max_shared_memory_size,
|
| + uint64_t max_file_size,
|
| + size_t max_blob_in_memory_size,
|
| + uint64_t disk_space_left,
|
| + size_t memory_left,
|
| + const std::vector<DataElement>& blob_item_infos);
|
| +
|
| + const std::vector<uint64_t>& file_handles() const { return file_handles_; }
|
| +
|
| + const std::vector<size_t>& shared_memory_handles() const {
|
| + return shared_memory_handles_;
|
| + }
|
| +
|
| + const std::vector<MemoryItemRequest>& requests() const { return requests_; }
|
| +
|
| + Error error() const { return error_; }
|
| +
|
| + private:
|
| + // This iterates of the data elements and segments the 'bytes' data into
|
| + // the smallest number of segments given the max_segment_size.
|
| + // The callback describes either:
|
| + // * A non-memory item
|
| + // * A partition of a bytes element which will be populated into a given
|
| + // segment and segment offset.
|
| + // The function signature of the template functor is:
|
| + // void(DataElement::Type /*element_type*/,
|
| + // size_t /*element_index*/,
|
| + // SizeType /*element_offset*/,
|
| + // size_t /*segment_index*/,
|
| + // SizeType /*segment_offset*/,
|
| + // SizeType /*size*/)
|
| + //
|
| + // element: A DataElement from the |items| vector. The callback is called
|
| + // for every single element in the vector (multiple times
|
| + // if the element needs to be split up)
|
| + // segment: A memory segment, with a maximum size of |max_segment_size|.
|
| + //
|
| + // Assumptions: All memory items are consolidated. As in, there are no two
|
| + // 'bytes' items next to eachother.
|
| + template <typename ForEachFunctor, typename SizeType>
|
| + static void ForEachWithSegment(const std::vector<DataElement>& items,
|
| + SizeType max_segment_size,
|
| + ForEachFunctor function);
|
| +
|
| + // This populates the |segment_sizes| vector with the sizes of the segments
|
| + // that will be used in the transport strategy.
|
| + template <typename SizeType>
|
| + static void CreateHandleSizes(SizeType total_memory_size,
|
| + SizeType max_segment_size,
|
| + std::vector<SizeType>* segment_sizes);
|
| +
|
| + Error error_;
|
| +
|
| + std::vector<uint64_t> file_handles_;
|
| + std::vector<size_t> shared_memory_handles_;
|
| +
|
| + std::vector<MemoryItemRequest> requests_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BlobTransportStrategy);
|
| +};
|
| +
|
| +} // namespace storage
|
| +
|
| +#endif // STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_STRATEGY_H_
|
| +
|
|
|