Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 5 #ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| 6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 16 #include "base/callback_forward.h" | |
| 15 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 18 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/shared_memory_handle.h" | 20 #include "base/memory/shared_memory_handle.h" |
| 21 #include "base/memory/weak_ptr.h" | |
| 19 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
| 20 #include "ipc/ipc_platform_file.h" | 23 #include "ipc/ipc_platform_file.h" |
| 21 #include "storage/common/blob_storage/blob_storage_constants.h" | 24 #include "storage/common/blob_storage/blob_storage_constants.h" |
| 22 | 25 |
| 23 namespace base { | 26 namespace base { |
| 24 template <typename T> | 27 template <typename T> |
| 25 struct DefaultLazyInstanceTraits; | 28 struct DefaultLazyInstanceTraits; |
| 26 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 30 class TaskRunner; | |
| 27 } | 31 } |
| 28 | 32 |
| 29 namespace storage { | 33 namespace storage { |
| 30 class DataElement; | 34 class DataElement; |
| 31 struct BlobItemBytesRequest; | 35 struct BlobItemBytesRequest; |
| 32 struct BlobItemBytesResponse; | 36 struct BlobItemBytesResponse; |
| 33 } | 37 } |
| 34 | 38 |
| 35 namespace IPC { | 39 namespace IPC { |
| 40 class Message; | |
| 36 class Sender; | 41 class Sender; |
| 37 } | 42 } |
| 38 | 43 |
| 39 namespace content { | 44 namespace content { |
| 40 | 45 |
| 41 class BlobConsolidation; | 46 class BlobConsolidation; |
| 42 class ThreadSafeSender; | 47 class ThreadSafeSender; |
| 43 | 48 |
| 44 // This class is used to manage all the asynchronous transporation of blobs from | 49 // This class is used to manage all the asynchronous transporation of blobs from |
| 45 // the Renderer to the Browser process, where it's handling the Renderer side. | 50 // the Renderer to the Browser process, where it's handling the Renderer side. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 56 static BlobTransportController* GetInstance(); | 61 static BlobTransportController* GetInstance(); |
| 57 | 62 |
| 58 // This kicks off a blob transfer to the browser thread, which involves | 63 // This kicks off a blob transfer to the browser thread, which involves |
| 59 // sending an IPC message and storing the blob consolidation object. Designed | 64 // sending an IPC message and storing the blob consolidation object. Designed |
| 60 // to be called by the main thread or a worker thread. | 65 // to be called by the main thread or a worker thread. |
| 61 // This also calls ChildProcess::AddRefProcess to keep our process around | 66 // This also calls ChildProcess::AddRefProcess to keep our process around |
| 62 // while we transfer. | 67 // while we transfer. |
| 63 static void InitiateBlobTransfer( | 68 static void InitiateBlobTransfer( |
| 64 const std::string& uuid, | 69 const std::string& uuid, |
| 65 const std::string& content_type, | 70 const std::string& content_type, |
| 66 std::unique_ptr<BlobConsolidation> consolidation, | 71 scoped_refptr<BlobConsolidation> consolidation, |
| 67 scoped_refptr<ThreadSafeSender> sender, | 72 scoped_refptr<ThreadSafeSender> sender, |
| 68 base::SingleThreadTaskRunner* io_runner, | 73 base::SingleThreadTaskRunner* io_runner, |
| 69 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | 74 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| 70 | 75 |
| 71 // This responds to the request using the sender. | 76 // This responds to the request using the |sender|. If we need to save files |
| 77 // then we we hold onto the sender to send the (possibly multiple) reponses | |
| 78 // asynchronously. Use CancelAllBlobTransfers to stop usage of the |sender|. | |
| 72 void OnMemoryRequest( | 79 void OnMemoryRequest( |
| 73 const std::string& uuid, | 80 const std::string& uuid, |
| 74 const std::vector<storage::BlobItemBytesRequest>& requests, | 81 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 75 std::vector<base::SharedMemoryHandle>* memory_handles, | 82 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 76 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 83 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 84 base::TaskRunner* file_runner, | |
| 77 IPC::Sender* sender); | 85 IPC::Sender* sender); |
| 78 | 86 |
| 79 void OnCancel(const std::string& uuid, | 87 void OnCancel(const std::string& uuid, |
| 80 storage::IPCBlobCreationCancelCode code); | 88 storage::IPCBlobCreationCancelCode code); |
| 81 | 89 |
| 82 void OnDone(const std::string& uuid); | 90 void OnDone(const std::string& uuid); |
| 83 | 91 |
| 84 bool IsTransporting(const std::string& uuid) { | 92 bool IsTransporting(const std::string& uuid) { |
| 85 return blob_storage_.find(uuid) != blob_storage_.end(); | 93 return blob_storage_.find(uuid) != blob_storage_.end(); |
| 86 } | 94 } |
| 87 | 95 |
| 96 // Invalidates all asynchronously running memory request handlers and clears | |
| 97 // the internal state. If our map wasn't previously empty, then we call | |
| 98 // ChildProcess::ReleaseProcess to release our previous reference. | |
| 99 void CancelAllBlobTransfers(); | |
| 100 | |
| 88 private: | 101 private: |
| 102 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | |
| 89 friend class BlobTransportControllerTest; | 103 friend class BlobTransportControllerTest; |
| 90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | 104 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
| 91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | 105 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
| 92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | 106 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
| 107 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Disk); | |
| 93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | 108 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
| 94 | 109 |
| 110 enum class ResponsesStatus { | |
| 111 BLOB_NOT_FOUND, | |
| 112 SHARED_MEMORY_MAP_FAILED, | |
| 113 PENDING_IO, | |
| 114 SUCCESS | |
| 115 }; | |
| 116 | |
| 95 static void GetDescriptions(BlobConsolidation* consolidation, | 117 static void GetDescriptions(BlobConsolidation* consolidation, |
| 96 size_t max_data_population, | 118 size_t max_data_population, |
| 97 std::vector<storage::DataElement>* out); | 119 std::vector<storage::DataElement>* out); |
| 98 | 120 |
| 99 BlobTransportController(); | 121 BlobTransportController(); |
| 100 ~BlobTransportController(); | 122 ~BlobTransportController(); |
| 101 | 123 |
| 102 // Clears all internal state. If our map wasn't previously empty, then we call | 124 void OnFileWriteComplete( |
| 103 // ChildProcess::ReleaseProcess to release our previous reference. | 125 IPC::Sender* sender, |
| 104 void ClearForTesting(); | 126 const std::string& uuid, |
| 105 | 127 const std::pair<std::vector<storage::BlobItemBytesResponse>, |
| 106 enum class ResponsesStatus { | 128 storage::IPCBlobCreationCancelCode>& result); |
| 107 BLOB_NOT_FOUND, | |
| 108 SHARED_MEMORY_MAP_FAILED, | |
| 109 SUCCESS | |
| 110 }; | |
| 111 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | |
| 112 | 129 |
| 113 void StoreBlobDataForRequests( | 130 void StoreBlobDataForRequests( |
| 114 const std::string& uuid, | 131 const std::string& uuid, |
| 115 std::unique_ptr<BlobConsolidation> consolidation, | 132 scoped_refptr<BlobConsolidation> consolidation, |
| 116 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | 133 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| 117 | 134 |
| 118 ResponsesStatus GetResponses( | |
| 119 const std::string& uuid, | |
| 120 const std::vector<storage::BlobItemBytesRequest>& requests, | |
| 121 std::vector<base::SharedMemoryHandle>* memory_handles, | |
| 122 const std::vector<IPC::PlatformFileForTransit>& file_handles, | |
| 123 std::vector<storage::BlobItemBytesResponse>* output); | |
| 124 | |
| 125 // Deletes the consolidation, and if we removed the last consolidation from | 135 // Deletes the consolidation, and if we removed the last consolidation from |
| 126 // our map, we call ChildProcess::ReleaseProcess to release our previous | 136 // 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.
| |
| 127 // reference. | 137 // reference. |
| 128 void ReleaseBlobConsolidation(const std::string& uuid); | 138 void ReleaseBlobConsolidation(const std::string& uuid); |
| 129 | 139 |
| 130 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; | 140 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| 131 std::map<std::string, std::unique_ptr<BlobConsolidation>> blob_storage_; | 141 std::map<std::string, scoped_refptr<BlobConsolidation>> blob_storage_; |
| 142 base::WeakPtrFactory<BlobTransportController> weak_factory_; | |
| 132 | 143 |
| 133 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | 144 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| 134 }; | 145 }; |
| 135 | 146 |
| 136 } // namespace content | 147 } // namespace content |
| 137 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 148 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| OLD | NEW |