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..dac489bd9f46fa76338d10c0d863a0624596058b 100644 |
| --- a/content/child/blob_storage/blob_transport_controller.h |
| +++ b/content/child/blob_storage/blob_transport_controller.h |
| @@ -12,6 +12,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/callback_forward.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| @@ -24,6 +25,7 @@ namespace base { |
| template <typename T> |
| struct DefaultLazyInstanceTraits; |
| class SingleThreadTaskRunner; |
| +class TaskRunner; |
| } |
| namespace storage { |
| @@ -33,6 +35,7 @@ struct BlobItemBytesResponse; |
| } |
| namespace IPC { |
| +class Message; |
| class Sender; |
| } |
| @@ -53,6 +56,8 @@ class ThreadSafeSender; |
| // Must be used on the IO thread. |
| class CONTENT_EXPORT BlobTransportController { |
| public: |
| + using IPCSender = base::Callback<void(std::unique_ptr<IPC::Message>)>; |
| + |
| static BlobTransportController* GetInstance(); |
| // This kicks off a blob transfer to the browser thread, which involves |
| @@ -63,18 +68,21 @@ 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 |ipc_sender| callback. If we need |
| + // to save files then the call will happen asynchronously. |
|
michaeln
2016/04/21 18:51:43
maybe also mention that a single call to OnMemoryR
|
| 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, |
| - IPC::Sender* sender); |
| + scoped_refptr<base::TaskRunner> io_runner, |
|
michaeln
2016/04/21 01:58:41
this method can only be called on the io thread so
dmurph
2016/04/22 22:37:10
Done.
|
| + base::TaskRunner* file_runner, |
| + const IPCSender& ipc_sender); |
|
michaeln
2016/04/21 01:58:41
we generally use the IPC::Sender interface for thi
dmurph
2016/04/22 22:37:10
Done.
|
| void OnCancel(const std::string& uuid, |
| storage::IPCBlobCreationCancelCode code); |
| @@ -86,12 +94,26 @@ class CONTENT_EXPORT BlobTransportController { |
| } |
| 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); |
| + using ResponseCallback = base::Callback<void( |
| + const std::vector<storage::BlobItemBytesResponse>& /* responses */)>; |
| + using CancelCallback = |
| + base::Callback<void(storage::IPCBlobCreationCancelCode /* reason */)>; |
| + |
| + 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); |
| @@ -103,16 +125,19 @@ class CONTENT_EXPORT BlobTransportController { |
| // 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 SendResponses( |
| + const IPCSender& ipc_sender, |
| + const std::string& uuid, |
| + const std::vector<storage::BlobItemBytesResponse>& responses); |
| + |
| + void SendCancelAndReleaseConsolidation( |
| + const IPCSender& ipc_sender, |
| + const std::string& uuid, |
| + storage::IPCBlobCreationCancelCode reason); |
| void StoreBlobDataForRequests( |
| const std::string& uuid, |
| - std::unique_ptr<BlobConsolidation> consolidation, |
| + scoped_refptr<BlobConsolidation> consolidation, |
| scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| ResponsesStatus GetResponses( |
| @@ -120,7 +145,11 @@ class CONTENT_EXPORT BlobTransportController { |
| const std::vector<storage::BlobItemBytesRequest>& requests, |
| std::vector<base::SharedMemoryHandle>* memory_handles, |
| const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| - std::vector<storage::BlobItemBytesResponse>* output); |
| + std::vector<storage::BlobItemBytesResponse>* output, |
| + scoped_refptr<base::TaskRunner> io_runner, |
|
michaeln
2016/04/21 01:58:41
io_runner may not needed here for the same reason
dmurph
2016/04/22 22:37:10
Done.
|
| + base::TaskRunner* file_runner, |
| + const ResponseCallback& response_callback, |
| + const CancelCallback& error_callback); |
|
michaeln
2016/04/21 01:58:41
ditto IPC::Sender
Since IPC::Sender would be a ra
kinuko
2016/04/21 07:54:34
Btw-- why don't we use ThreadSafeSender here and e
dmurph
2016/04/22 22:37:10
I don't have a thread safe version, I just have th
|
| // Deletes the consolidation, and if we removed the last consolidation from |
| // our map, we call ChildProcess::ReleaseProcess to release our previous |
| @@ -128,7 +157,7 @@ class CONTENT_EXPORT BlobTransportController { |
| 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_; |
| DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| }; |