Chromium Code Reviews| Index: content/child/blob_storage/blob_transport_controller.h |
| diff --git a/content/child/blob_storage/blob_transport_controller.h b/content/child/blob_storage/blob_transport_controller.h |
| index c9c62ce55ba69e36a4b5bcd6f7ddcc52c421057e..864770a3aa5bcc75bc9a69f858f86b77cc194dd1 100644 |
| --- a/content/child/blob_storage/blob_transport_controller.h |
| +++ b/content/child/blob_storage/blob_transport_controller.h |
| @@ -10,12 +10,15 @@ |
| #include <map> |
| #include <memory> |
| #include <string> |
| +#include <utility> |
| #include <vector> |
| +#include "base/callback_forward.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/shared_memory_handle.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "content/common/content_export.h" |
| #include "ipc/ipc_platform_file.h" |
| #include "storage/common/blob_storage/blob_storage_constants.h" |
| @@ -24,6 +27,7 @@ namespace base { |
| template <typename T> |
| struct DefaultLazyInstanceTraits; |
| class SingleThreadTaskRunner; |
| +class TaskRunner; |
| } |
| namespace storage { |
| @@ -33,6 +37,7 @@ struct BlobItemBytesResponse; |
| } |
| namespace IPC { |
| +class Message; |
| class Sender; |
| } |
| @@ -63,17 +68,20 @@ class CONTENT_EXPORT BlobTransportController { |
| static void InitiateBlobTransfer( |
| const std::string& uuid, |
| const std::string& content_type, |
| - std::unique_ptr<BlobConsolidation> consolidation, |
| + scoped_refptr<BlobConsolidation> consolidation, |
| scoped_refptr<ThreadSafeSender> sender, |
| base::SingleThreadTaskRunner* io_runner, |
| scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| - // This responds to the request using the sender. |
| + // This responds to the request using the |sender|. If we need to save files |
| + // then we we hold onto the sender to send the (possibly multiple) reponses |
| + // asynchronously. Use CancelAllBlobTransfers to stop usage of the |sender|. |
| void OnMemoryRequest( |
| const std::string& uuid, |
| const std::vector<storage::BlobItemBytesRequest>& requests, |
| std::vector<base::SharedMemoryHandle>* memory_handles, |
| const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| + base::TaskRunner* file_runner, |
| IPC::Sender* sender); |
| void OnCancel(const std::string& uuid, |
| @@ -85,13 +93,27 @@ class CONTENT_EXPORT BlobTransportController { |
| return blob_storage_.find(uuid) != blob_storage_.end(); |
| } |
| + // Invalidates all asynchronously running memory request handlers and clears |
| + // the internal state. If our map wasn't previously empty, then we call |
| + // ChildProcess::ReleaseProcess to release our previous reference. |
| + void CancelAllBlobTransfers(); |
| + |
| private: |
| + friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
| friend class BlobTransportControllerTest; |
| FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
| FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
| FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
| + FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Disk); |
| FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
| + enum class ResponsesStatus { |
| + BLOB_NOT_FOUND, |
| + SHARED_MEMORY_MAP_FAILED, |
| + PENDING_IO, |
| + SUCCESS |
| + }; |
| + |
| static void GetDescriptions(BlobConsolidation* consolidation, |
| size_t max_data_population, |
| std::vector<storage::DataElement>* out); |
| @@ -99,36 +121,25 @@ class CONTENT_EXPORT BlobTransportController { |
| BlobTransportController(); |
| ~BlobTransportController(); |
| - // Clears all internal state. If our map wasn't previously empty, then we call |
| - // ChildProcess::ReleaseProcess to release our previous reference. |
| - void ClearForTesting(); |
| - |
| - enum class ResponsesStatus { |
| - BLOB_NOT_FOUND, |
| - SHARED_MEMORY_MAP_FAILED, |
| - SUCCESS |
| - }; |
| - friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
| + void OnFileWriteComplete( |
| + IPC::Sender* sender, |
| + const std::string& uuid, |
| + const std::pair<std::vector<storage::BlobItemBytesResponse>, |
| + storage::IPCBlobCreationCancelCode>& result); |
| void StoreBlobDataForRequests( |
| const std::string& uuid, |
| - std::unique_ptr<BlobConsolidation> consolidation, |
| + scoped_refptr<BlobConsolidation> consolidation, |
| scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| - ResponsesStatus GetResponses( |
| - const std::string& uuid, |
| - const std::vector<storage::BlobItemBytesRequest>& requests, |
| - std::vector<base::SharedMemoryHandle>* memory_handles, |
| - const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| - std::vector<storage::BlobItemBytesResponse>* output); |
| - |
| // Deletes the consolidation, and if we removed the last consolidation from |
| // our map, we call ChildProcess::ReleaseProcess to release our previous |
|
michaeln
2016/04/28 00:16:57
comments describing aggregated process refcounting
dmurph
2016/05/09 19:55:47
Done.
|
| // reference. |
| void ReleaseBlobConsolidation(const std::string& uuid); |
| scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| - std::map<std::string, std::unique_ptr<BlobConsolidation>> blob_storage_; |
| + std::map<std::string, scoped_refptr<BlobConsolidation>> blob_storage_; |
| + base::WeakPtrFactory<BlobTransportController> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| }; |