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 <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback_forward.h" | |
15 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/memory/shared_memory_handle.h" | 19 #include "base/memory/shared_memory_handle.h" |
19 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
20 #include "ipc/ipc_platform_file.h" | 21 #include "ipc/ipc_platform_file.h" |
21 #include "storage/common/blob_storage/blob_storage_constants.h" | 22 #include "storage/common/blob_storage/blob_storage_constants.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 template <typename T> | 25 template <typename T> |
25 struct DefaultLazyInstanceTraits; | 26 struct DefaultLazyInstanceTraits; |
26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
28 class TaskRunner; | |
27 } | 29 } |
28 | 30 |
29 namespace storage { | 31 namespace storage { |
30 class DataElement; | 32 class DataElement; |
31 struct BlobItemBytesRequest; | 33 struct BlobItemBytesRequest; |
32 struct BlobItemBytesResponse; | 34 struct BlobItemBytesResponse; |
33 } | 35 } |
34 | 36 |
35 namespace IPC { | 37 namespace IPC { |
36 class Sender; | 38 class Sender; |
37 } | 39 } |
38 | 40 |
39 namespace content { | 41 namespace content { |
40 | 42 |
41 class BlobConsolidation; | 43 class BlobConsolidation; |
42 class ThreadSafeSender; | 44 class ThreadSafeSender; |
43 | 45 |
44 // This class is used to manage all the asynchronous transporation of blobs from | 46 // 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. | 47 // the Renderer to the Browser process, where it's handling the Renderer side. |
46 // The function of this class is to: | 48 // The function of this class is to: |
47 // * Be a lazy singleton, | 49 // * Be a lazy singleton, |
48 // * hold all of the blob data that is being transported to the Browser process, | 50 // * hold all of the blob data that is being transported to the Browser process, |
49 // * create the blob item 'descriptions' for the browser, | 51 // * create the blob item 'descriptions' for the browser, |
50 // * include shortcut data in the descriptions, | 52 // * include shortcut data in the descriptions, |
51 // * generate responses to blob memory requests, and | 53 // * generate responses to blob memory requests, and |
52 // * send IPC responses. | 54 // * send IPC responses. |
53 // Must be used on the IO thread. | 55 // Must be used on the IO thread. |
54 class CONTENT_EXPORT BlobTransportController { | 56 class CONTENT_EXPORT BlobTransportController { |
55 public: | 57 public: |
58 using ResponseCallback = base::Callback<void( | |
59 const std::vector<storage::BlobItemBytesResponse>& /* responses */)>; | |
60 using CancelCallback = | |
61 base::Callback<void(storage::IPCBlobCreationCancelCode /* reason */)>; | |
62 | |
56 static BlobTransportController* GetInstance(); | 63 static BlobTransportController* GetInstance(); |
57 | 64 |
58 // This kicks off a blob transfer to the browser thread, which involves | 65 // This kicks off a blob transfer to the browser thread, which involves |
59 // sending an IPC message and storing the blob consolidation object. Designed | 66 // sending an IPC message and storing the blob consolidation object. Designed |
60 // to be called by the main thread or a worker thread. | 67 // to be called by the main thread or a worker thread. |
61 // This also calls ChildProcess::AddRefProcess to keep our process around | 68 // This also calls ChildProcess::AddRefProcess to keep our process around |
62 // while we transfer. | 69 // while we transfer. |
63 static void InitiateBlobTransfer( | 70 static void InitiateBlobTransfer( |
64 const std::string& uuid, | 71 const std::string& uuid, |
65 const std::string& content_type, | 72 const std::string& content_type, |
66 std::unique_ptr<BlobConsolidation> consolidation, | 73 scoped_refptr<BlobConsolidation> consolidation, |
67 scoped_refptr<ThreadSafeSender> sender, | 74 scoped_refptr<ThreadSafeSender> sender, |
68 base::SingleThreadTaskRunner* io_runner, | 75 base::SingleThreadTaskRunner* io_runner, |
69 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | 76 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
70 | 77 |
71 // This responds to the request using the sender. | 78 // This responds to the request using the sender. |
kinuko
2016/04/15 15:02:32
We should add a comment about async_xxxx_callback'
dmurph
2016/04/20 21:15:34
Done.
| |
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, |
77 IPC::Sender* sender); | 84 IPC::Sender* sender, |
85 scoped_refptr<base::TaskRunner> io_runner, | |
86 base::TaskRunner* file_runner, | |
87 const ResponseCallback& async_response_callback, | |
88 const CancelCallback& async_cancel_callback); | |
78 | 89 |
79 void OnCancel(const std::string& uuid, | 90 void OnCancel(const std::string& uuid, |
80 storage::IPCBlobCreationCancelCode code); | 91 storage::IPCBlobCreationCancelCode code); |
81 | 92 |
82 void OnDone(const std::string& uuid); | 93 void OnDone(const std::string& uuid); |
83 | 94 |
84 bool IsTransporting(const std::string& uuid) { | 95 bool IsTransporting(const std::string& uuid) { |
85 return blob_storage_.find(uuid) != blob_storage_.end(); | 96 return blob_storage_.find(uuid) != blob_storage_.end(); |
86 } | 97 } |
87 | 98 |
88 private: | 99 private: |
89 friend class BlobTransportControllerTest; | 100 friend class BlobTransportControllerTest; |
90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | 101 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | 102 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | 103 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
104 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Disk); | |
93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | 105 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
94 | 106 |
95 static void GetDescriptions(BlobConsolidation* consolidation, | 107 static void GetDescriptions(BlobConsolidation* consolidation, |
96 size_t max_data_population, | 108 size_t max_data_population, |
97 std::vector<storage::DataElement>* out); | 109 std::vector<storage::DataElement>* out); |
98 | 110 |
99 BlobTransportController(); | 111 BlobTransportController(); |
100 ~BlobTransportController(); | 112 ~BlobTransportController(); |
101 | 113 |
102 // Clears all internal state. If our map wasn't previously empty, then we call | 114 // Clears all internal state. If our map wasn't previously empty, then we call |
103 // ChildProcess::ReleaseProcess to release our previous reference. | 115 // ChildProcess::ReleaseProcess to release our previous reference. |
104 void ClearForTesting(); | 116 void ClearForTesting(); |
105 | 117 |
106 enum class ResponsesStatus { | 118 enum class ResponsesStatus { |
107 BLOB_NOT_FOUND, | 119 BLOB_NOT_FOUND, |
108 SHARED_MEMORY_MAP_FAILED, | 120 SHARED_MEMORY_MAP_FAILED, |
121 PENDING_IO, | |
109 SUCCESS | 122 SUCCESS |
110 }; | 123 }; |
111 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | 124 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
112 | 125 |
126 void CancelAsyncBlobTransfer(const CancelCallback& async_cancel_callback, | |
127 const std::string& uuid, | |
128 storage::IPCBlobCreationCancelCode code); | |
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( | 135 ResponsesStatus GetResponses( |
119 const std::string& uuid, | 136 const std::string& uuid, |
120 const std::vector<storage::BlobItemBytesRequest>& requests, | 137 const std::vector<storage::BlobItemBytesRequest>& requests, |
121 std::vector<base::SharedMemoryHandle>* memory_handles, | 138 std::vector<base::SharedMemoryHandle>* memory_handles, |
122 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 139 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
123 std::vector<storage::BlobItemBytesResponse>* output); | 140 std::vector<storage::BlobItemBytesResponse>* output, |
141 scoped_refptr<base::TaskRunner> io_runner, | |
142 base::TaskRunner* file_runner, | |
143 const ResponseCallback& response_callback, | |
144 const CancelCallback& error_callback); | |
124 | 145 |
125 // Deletes the consolidation, and if we removed the last consolidation from | 146 // Deletes the consolidation, and if we removed the last consolidation from |
126 // our map, we call ChildProcess::ReleaseProcess to release our previous | 147 // our map, we call ChildProcess::ReleaseProcess to release our previous |
127 // reference. | 148 // reference. |
128 void ReleaseBlobConsolidation(const std::string& uuid); | 149 void ReleaseBlobConsolidation(const std::string& uuid); |
129 | 150 |
130 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; | 151 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
131 std::map<std::string, std::unique_ptr<BlobConsolidation>> blob_storage_; | 152 std::map<std::string, scoped_refptr<BlobConsolidation>> blob_storage_; |
132 | 153 |
133 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | 154 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
134 }; | 155 }; |
135 | 156 |
136 } // namespace content | 157 } // namespace content |
137 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 158 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
OLD | NEW |