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> |
(...skipping 21 matching lines...) Expand all Loading... | |
32 struct BlobItemBytesResponse; | 32 struct BlobItemBytesResponse; |
33 } | 33 } |
34 | 34 |
35 namespace IPC { | 35 namespace IPC { |
36 class Sender; | 36 class Sender; |
37 } | 37 } |
38 | 38 |
39 namespace content { | 39 namespace content { |
40 | 40 |
41 class BlobConsolidation; | 41 class BlobConsolidation; |
42 class ThreadSafeSender; | |
42 | 43 |
43 // This class is used to manage all the asynchronous transporation of blobs from | 44 // This class is used to manage all the asynchronous transporation of blobs from |
44 // the Renderer to the Browser process, where it's handling the Renderer side. | 45 // the Renderer to the Browser process, where it's handling the Renderer side. |
45 // The function of this class is to: | 46 // The function of this class is to: |
46 // * Be a lazy singleton, | 47 // * Be a lazy singleton, |
47 // * hold all of the blob data that is being transported to the Browser process, | 48 // * hold all of the blob data that is being transported to the Browser process, |
48 // * create the blob item 'descriptions' for the browser, | 49 // * create the blob item 'descriptions' for the browser, |
49 // * include shortcut data in the descriptions, | 50 // * include shortcut data in the descriptions, |
50 // * generate responses to blob memory requests, and | 51 // * generate responses to blob memory requests, and |
51 // * send IPC responses. | 52 // * send IPC responses. |
52 // Must be used on the IO thread. | 53 // Must be used on the IO thread. |
53 class CONTENT_EXPORT BlobTransportController { | 54 class CONTENT_EXPORT BlobTransportController { |
54 public: | 55 public: |
55 static BlobTransportController* GetInstance(); | 56 static BlobTransportController* GetInstance(); |
56 | 57 |
57 // This kicks off a blob transfer to the browser thread, which involves | 58 // This kicks off a blob transfer to the browser thread, which involves |
58 // sending an IPC message and storing the blob consolidation object. | 59 // sending an IPC message and storing the blob consolidation object. Designed |
59 // If we have no pending blobs, we also call ChildProcess::AddRefProcess to | 60 // to be called by any thread. |
60 // keep our process around while we transfer. This will be decremented when | 61 // This also calls ChildProcess::AddRefProcess to keep our process around |
61 // we finish our last pending transfer (when our map is empty). | 62 // while we transfer. |
62 void InitiateBlobTransfer( | 63 static void InitiateBlobTransfer( |
63 const std::string& uuid, | 64 const std::string& uuid, |
64 scoped_ptr<BlobConsolidation> consolidation, | 65 scoped_ptr<BlobConsolidation> consolidation, |
65 IPC::Sender* sender, | 66 scoped_refptr<ThreadSafeSender> sender, |
67 const scoped_refptr<base::SingleThreadTaskRunner>& io_runner, | |
michaeln
2016/04/05 00:18:04
i think per the new guidelines, you could/should u
dmurph
2016/04/05 00:32:04
Ah, yeah, I think I just need the pointer.
| |
66 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | 68 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
67 | 69 |
68 // This responds to the request using the sender. | 70 // This responds to the request using the sender. |
69 void OnMemoryRequest( | 71 void OnMemoryRequest( |
70 const std::string& uuid, | 72 const std::string& uuid, |
71 const std::vector<storage::BlobItemBytesRequest>& requests, | 73 const std::vector<storage::BlobItemBytesRequest>& requests, |
72 std::vector<base::SharedMemoryHandle>* memory_handles, | 74 std::vector<base::SharedMemoryHandle>* memory_handles, |
73 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 75 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
74 IPC::Sender* sender); | 76 IPC::Sender* sender); |
75 | 77 |
76 void OnCancel(const std::string& uuid, | 78 void OnCancel(const std::string& uuid, |
77 storage::IPCBlobCreationCancelCode code); | 79 storage::IPCBlobCreationCancelCode code); |
78 | 80 |
79 void OnDone(const std::string& uuid); | 81 void OnDone(const std::string& uuid); |
80 | 82 |
81 | |
82 bool IsTransporting(const std::string& uuid) { | 83 bool IsTransporting(const std::string& uuid) { |
83 return blob_storage_.find(uuid) != blob_storage_.end(); | 84 return blob_storage_.find(uuid) != blob_storage_.end(); |
84 } | 85 } |
85 | 86 |
86 ~BlobTransportController(); | |
87 | |
88 private: | 87 private: |
89 friend class BlobTransportControllerTest; | 88 friend class BlobTransportControllerTest; |
90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | 89 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | 90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | 91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | 92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
94 | 93 |
94 static void GetDescriptions(BlobConsolidation* consolidation, | |
95 size_t max_data_population, | |
96 std::vector<storage::DataElement>* out); | |
97 | |
98 BlobTransportController(); | |
99 ~BlobTransportController(); | |
100 | |
95 // Clears all internal state. If our map wasn't previously empty, then we call | 101 // Clears all internal state. If our map wasn't previously empty, then we call |
96 // ChildProcess::ReleaseProcess to release our previous reference. | 102 // ChildProcess::ReleaseProcess to release our previous reference. |
97 void ClearForTesting(); | 103 void ClearForTesting(); |
98 | 104 |
99 enum class ResponsesStatus { | 105 enum class ResponsesStatus { |
100 BLOB_NOT_FOUND, | 106 BLOB_NOT_FOUND, |
101 SHARED_MEMORY_MAP_FAILED, | 107 SHARED_MEMORY_MAP_FAILED, |
102 SUCCESS | 108 SUCCESS |
103 }; | 109 }; |
104 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | 110 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
105 | 111 |
106 BlobTransportController(); | 112 void InitiateBlobTransferOnIOThread( |
107 | 113 const std::string& uuid, |
108 void GetDescriptions(BlobConsolidation* consolidation, | 114 scoped_ptr<BlobConsolidation> consolidation, |
109 size_t max_data_population, | 115 scoped_refptr<ThreadSafeSender> sender, |
110 std::vector<storage::DataElement>* out); | 116 bool sent_descriptions, |
117 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | |
111 | 118 |
112 ResponsesStatus GetResponses( | 119 ResponsesStatus GetResponses( |
113 const std::string& uuid, | 120 const std::string& uuid, |
114 const std::vector<storage::BlobItemBytesRequest>& requests, | 121 const std::vector<storage::BlobItemBytesRequest>& requests, |
115 std::vector<base::SharedMemoryHandle>* memory_handles, | 122 std::vector<base::SharedMemoryHandle>* memory_handles, |
116 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 123 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
117 std::vector<storage::BlobItemBytesResponse>* output); | 124 std::vector<storage::BlobItemBytesResponse>* output); |
118 | 125 |
119 // Deletes the consolidation, and if we removed the last consolidation from | 126 // Deletes the consolidation, and if we removed the last consolidation from |
120 // our map, we call ChildProcess::ReleaseProcess to release our previous | 127 // our map, we call ChildProcess::ReleaseProcess to release our previous |
121 // reference. | 128 // reference. |
122 void ReleaseBlobConsolidation(const std::string& uuid); | 129 void ReleaseBlobConsolidation(const std::string& uuid); |
123 | 130 |
124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; | 131 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
125 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; | 132 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; |
126 | 133 |
127 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | 134 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
128 }; | 135 }; |
129 | 136 |
130 } // namespace content | 137 } // namespace content |
131 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 138 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
OLD | NEW |