| Index: storage/browser/blob/blob_async_builder_host.h
|
| diff --git a/storage/browser/blob/blob_async_builder_host.h b/storage/browser/blob/blob_async_builder_host.h
|
| index 0e4a0d4bded6e19112aa872db2dc9cec49eda8cb..e16a434d08df6f81d502f68354863b236605ab73 100644
|
| --- a/storage/browser/blob/blob_async_builder_host.h
|
| +++ b/storage/browser/blob/blob_async_builder_host.h
|
| @@ -5,6 +5,7 @@
|
| #ifndef STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_
|
| #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_
|
|
|
| +#include <list>
|
| #include <map>
|
| #include <string>
|
| #include <vector>
|
| @@ -14,8 +15,10 @@
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/shared_memory_handle.h"
|
| +#include "base/memory/weak_ptr.h"
|
| #include "storage/browser/blob/blob_async_transport_strategy.h"
|
| #include "storage/browser/blob/blob_data_builder.h"
|
| +#include "storage/browser/blob/blob_memory_controller.h"
|
| #include "storage/browser/storage_browser_export.h"
|
| #include "storage/common/blob_storage/blob_item_bytes_request.h"
|
| #include "storage/common/blob_storage/blob_item_bytes_response.h"
|
| @@ -27,6 +30,8 @@ class SharedMemory;
|
| }
|
|
|
| namespace storage {
|
| +class BlobMemoryController;
|
| +class ShareableFileReference;
|
|
|
| // This class holds all blobs that are currently being built asynchronously for
|
| // a child process. It sends memory request, cancel, and done messages through
|
| @@ -54,7 +59,7 @@ class STORAGE_EXPORT BlobAsyncBuilderHost {
|
| const std::string& uuid,
|
| const std::string& type,
|
| const std::vector<DataElement>& descriptions,
|
| - size_t memory_available,
|
| + BlobMemoryController* memory_controller,
|
| const base::Callback<
|
| void(const std::vector<storage::BlobItemBytesRequest>&,
|
| const std::vector<base::SharedMemoryHandle>&,
|
| @@ -76,51 +81,84 @@ class STORAGE_EXPORT BlobAsyncBuilderHost {
|
| // For testing use only. Must be called before StartBuildingBlob.
|
| void SetMemoryConstantsForTesting(size_t max_ipc_memory_size,
|
| size_t max_shared_memory_size,
|
| - uint64_t max_file_size) {
|
| + uint64_t max_file_size,
|
| + size_t in_flight_space) {
|
| max_ipc_memory_size_ = max_ipc_memory_size;
|
| max_shared_memory_size_ = max_shared_memory_size;
|
| max_file_size_ = max_file_size;
|
| + in_flight_space_ = in_flight_space;
|
| }
|
|
|
| private:
|
| + struct BlobBuildingState;
|
| struct BlobBuildingState {
|
| - BlobBuildingState();
|
| + explicit BlobBuildingState(const std::string& uuid);
|
| ~BlobBuildingState();
|
|
|
| std::string type;
|
| BlobAsyncTransportStrategy transport_strategy;
|
| - size_t next_request;
|
| - size_t num_fulfilled_requests;
|
| + BlobDataBuilder builder;
|
| + std::vector<bool> request_received;
|
| + size_t next_request = 0;
|
| + size_t num_fulfilled_requests = 0;
|
| + bool requests_started = false;
|
| +
|
| + base::Callback<void(
|
| + const std::vector<storage::BlobItemBytesRequest>&,
|
| + const std::vector<base::SharedMemoryHandle>&,
|
| + const std::vector<scoped_refptr<ShareableFileReference>>&)>
|
| + request_memory_callback;
|
| + base::Callback<void(const BlobDataBuilder&)> done_callback;
|
| + base::Callback<void(IPCBlobCreationCancelCode)> cancel_callback;
|
| +
|
| + // Shared memory bookkeeping.
|
| scoped_ptr<base::SharedMemory> shared_memory_block;
|
| // This is the number of requests that have been sent to populate the above
|
| // shared data. We won't ask for more data in shared memory until all
|
| // requests have been responded to.
|
| - size_t num_shared_memory_requests;
|
| + size_t num_shared_memory_requests = 0;
|
| // Only relevant if num_shared_memory_requests is > 0
|
| - size_t current_shared_memory_handle_index;
|
| + size_t current_shared_memory_handle_index = 0;
|
|
|
| - base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
|
| - const std::vector<base::SharedMemoryHandle>&,
|
| - const std::vector<uint64_t>&)> request_memory_callback;
|
| - base::Callback<void(const BlobDataBuilder&)> done_callback;
|
| - base::Callback<void(IPCBlobCreationCancelCode)> cancel_callback;
|
| + // File bookkeeping.
|
| + std::vector<BlobMemoryController::FileCreationInfo> files_created;
|
| };
|
|
|
| typedef std::map<std::string, scoped_ptr<BlobBuildingState>> AsyncBlobMap;
|
|
|
| - // This is the 'main loop' of our memory requests to the renderer.
|
| + // This is used as a callback to the memory manager. This starts the sending
|
| + // of requests to the renderer. It also does all file creation for file
|
| + // handles.
|
| + void StartRequestingBlobAndCreateFileHandles(
|
| + const std::string& uuid,
|
| + base::WeakPtr<BlobMemoryController> memory_controller,
|
| + bool can_request);
|
| +
|
| + // This is the 'main loop' for sending requests for the given blob. This
|
| + // includes logic for handling IPC and shared memory requests.
|
| void ContinueBlobMemoryRequests(const std::string& uuid);
|
|
|
| + // This is called from the memory manager when it has created a file for us.
|
| + void FileCreatedForBlob(
|
| + const std::string& uuid,
|
| + size_t handle_index,
|
| + const BlobMemoryController::FileCreationInfo& creation_info);
|
| +
|
| void CancelAndCleanup(const std::string& uuid,
|
| IPCBlobCreationCancelCode code);
|
| void DoneAndCleanup(const std::string& uuid);
|
|
|
| AsyncBlobMap async_blob_map_;
|
|
|
| + size_t requesting_memory_size_ = 0;
|
| +
|
| // Here for testing.
|
| size_t max_ipc_memory_size_ = kBlobStorageIPCThresholdBytes;
|
| size_t max_shared_memory_size_ = kBlobStorageMaxSharedMemoryBytes;
|
| uint64_t max_file_size_ = kBlobStorageMaxFileSizeBytes;
|
| + size_t in_flight_space_ = kBlobStorageInFlightMemory;
|
| +
|
| + base::WeakPtrFactory<BlobAsyncBuilderHost> weak_ptr_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(BlobAsyncBuilderHost);
|
| };
|
|
|