Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..20e57b461c5891b7d91d7b09bdd30ac5c89e3cb6 |
| --- /dev/null |
| +++ b/storage/browser/blob/blob_async_builder_host.h |
| @@ -0,0 +1,119 @@ |
| +// 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_ASYNC_BUILDER_HOST_H_ |
| +#define STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_ |
| + |
| +#include <storage/browser/blob/blob_async_transport_strategy.h> |
|
kinuko
2015/11/17 14:51:41
Looking a bit unusual?
Use "" instead of <> and h
dmurph
2015/11/17 20:40:19
Whoops, eclipse artifact.
michaeln
2015/11/17 21:55:28
should this include be listed below?
|
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/shared_memory_handle.h" |
| +#include "ipc/ipc_platform_file.h" |
| +#include "storage/browser/blob/blob_data_builder.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" |
| +#include "storage/common/blob_storage/blob_storage_constants.h" |
| +#include "storage/common/data_element.h" |
| + |
| +namespace base { |
| +class SharedMemory; |
| +} |
| + |
| +namespace storage { |
| + |
| +// This class holds all blobs that are currently being built asynchronously, and |
|
michaeln
2015/11/17 21:55:28
Is the intent to have one-per child process or one
dmurph
2015/11/19 02:06:17
One per child process.
|
| +// sends memory request, cancel, and done messages through the given callbacks. |
| +// This also includes handling 'shortcut' logic, where the host will use the |
| +// initial data in the description instead of requesting for data if we have |
| +// enough immediate space. |
| +class STORAGE_EXPORT BlobAsyncBuilderHost { |
| + public: |
| + BlobAsyncBuilderHost(); |
| + virtual ~BlobAsyncBuilderHost(); |
| + |
| + // Note: The builder given to the 'done' callback is destructed immediately |
| + // after the callback is run. |
| + void BuildBlobAsync( |
| + const std::string& uuid, |
| + const std::string& type, |
| + const std::vector<DataElement>& descriptions, |
| + size_t memory_available, |
| + base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&, |
| + const std::vector<base::SharedMemoryHandle>&, |
| + const std::vector<IPC::PlatformFileForTransit>&)> |
| + request_memory, |
| + base::Callback<void(BlobDataBuilder*)> done, |
| + base::Callback<void(IPCBlobCreationCancelCode)> cancel); |
| + |
| + void OnMemoryResponses(const std::string& uuid, |
| + const std::vector<BlobItemBytesResponse> responses); |
|
kinuko
2015/11/17 14:51:42
const ref
dmurph
2015/11/17 20:40:19
Done.
|
| + |
| + // This erases the blob building state. |
| + void StopBuildingBlob(const std::string& uuid); |
| + |
| + size_t blob_building_count() { return async_blob_map_.size(); } |
|
kinuko
2015/11/17 14:51:41
nit: could be a const method
dmurph
2015/11/17 20:40:19
Done.
|
| + |
| + // For testing use only. Must be called before BuildBlobAsync. |
| + void SetMemoryConstants(size_t max_ipc_memory_size, |
|
kinuko
2015/11/17 14:51:41
nit: add 'ForTesting' for test-only methods (so th
dmurph
2015/11/17 20:40:19
Done.
|
| + size_t max_shared_memory_size, |
| + uint64_t max_file_size, |
| + size_t max_blob_in_memory_size) { |
| + max_ipc_memory_size_ = max_ipc_memory_size; |
| + max_shared_memory_size_ = max_shared_memory_size; |
| + max_file_size_ = max_file_size; |
| + max_blob_in_memory_size_ = max_blob_in_memory_size; |
| + } |
| + |
| + private: |
| + struct BlobBuildingState { |
| + BlobBuildingState(); |
| + ~BlobBuildingState(); |
| + |
| + std::string type; |
| + BlobAsyncTransportStrategy transport_strategy; |
| + size_t next_request; |
| + size_t num_fulfilled_requests; |
| + 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; |
| + // Only relevant if num_shared_memory_requests is > 0 |
| + size_t current_shared_memory_handle_index; |
| + |
| + base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&, |
| + const std::vector<base::SharedMemoryHandle>&, |
| + const std::vector<IPC::PlatformFileForTransit>&)> |
| + request_memory; |
| + base::Callback<void(IPCBlobCreationCancelCode)> cancel; |
| + base::Callback<void(BlobDataBuilder*)> done; |
|
kinuko
2015/11/17 14:51:41
nit: would be nice if these are in the same order
dmurph
2015/11/17 20:40:19
Done.
|
| + }; |
| + |
| + typedef std::map<std::string, BlobBuildingState*> AsyncBlobMap; |
| + |
| + void ContinueBlobMemoryRequests(const std::string& uuid); |
| + |
| + void CancelAndCleanup(const std::string& uuid, |
| + IPCBlobCreationCancelCode code); |
| + void DoneAndCleanup(const std::string& uuid); |
| + |
| + AsyncBlobMap async_blob_map_; |
| + |
| + // Here for testing. |
| + size_t max_ipc_memory_size_; |
| + size_t max_shared_memory_size_; |
| + uint64_t max_file_size_; |
| + size_t max_blob_in_memory_size_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlobAsyncBuilderHost); |
| +}; |
| + |
| +} // namespace storage |
| +#endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_ |