| 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 the main thread or a worker 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, |
| 65 const std::string& content_type, |
| 64 scoped_ptr<BlobConsolidation> consolidation, | 66 scoped_ptr<BlobConsolidation> consolidation, |
| 65 IPC::Sender* sender, | 67 scoped_refptr<ThreadSafeSender> sender, |
| 68 base::SingleThreadTaskRunner* io_runner, |
| 66 scoped_refptr<base::SingleThreadTaskRunner> main_runner); | 69 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| 67 | 70 |
| 68 // This responds to the request using the sender. | 71 // This responds to the request using the sender. |
| 69 void OnMemoryRequest( | 72 void OnMemoryRequest( |
| 70 const std::string& uuid, | 73 const std::string& uuid, |
| 71 const std::vector<storage::BlobItemBytesRequest>& requests, | 74 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 72 std::vector<base::SharedMemoryHandle>* memory_handles, | 75 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 73 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 76 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 74 IPC::Sender* sender); | 77 IPC::Sender* sender); |
| 75 | 78 |
| 76 void OnCancel(const std::string& uuid, | 79 void OnCancel(const std::string& uuid, |
| 77 storage::IPCBlobCreationCancelCode code); | 80 storage::IPCBlobCreationCancelCode code); |
| 78 | 81 |
| 79 void OnDone(const std::string& uuid); | 82 void OnDone(const std::string& uuid); |
| 80 | 83 |
| 81 | |
| 82 bool IsTransporting(const std::string& uuid) { | 84 bool IsTransporting(const std::string& uuid) { |
| 83 return blob_storage_.find(uuid) != blob_storage_.end(); | 85 return blob_storage_.find(uuid) != blob_storage_.end(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 ~BlobTransportController(); | |
| 87 | |
| 88 private: | 88 private: |
| 89 friend class BlobTransportControllerTest; | 89 friend class BlobTransportControllerTest; |
| 90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | 90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
| 91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | 91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
| 92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | 92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
| 93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | 93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
| 94 | 94 |
| 95 static void GetDescriptions(BlobConsolidation* consolidation, |
| 96 size_t max_data_population, |
| 97 std::vector<storage::DataElement>* out); |
| 98 |
| 99 BlobTransportController(); |
| 100 ~BlobTransportController(); |
| 101 |
| 95 // Clears all internal state. If our map wasn't previously empty, then we call | 102 // Clears all internal state. If our map wasn't previously empty, then we call |
| 96 // ChildProcess::ReleaseProcess to release our previous reference. | 103 // ChildProcess::ReleaseProcess to release our previous reference. |
| 97 void ClearForTesting(); | 104 void ClearForTesting(); |
| 98 | 105 |
| 99 enum class ResponsesStatus { | 106 enum class ResponsesStatus { |
| 100 BLOB_NOT_FOUND, | 107 BLOB_NOT_FOUND, |
| 101 SHARED_MEMORY_MAP_FAILED, | 108 SHARED_MEMORY_MAP_FAILED, |
| 102 SUCCESS | 109 SUCCESS |
| 103 }; | 110 }; |
| 104 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | 111 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
| 105 | 112 |
| 106 BlobTransportController(); | 113 void StoreBlobDataForRequests( |
| 107 | 114 const std::string& uuid, |
| 108 void GetDescriptions(BlobConsolidation* consolidation, | 115 scoped_ptr<BlobConsolidation> consolidation, |
| 109 size_t max_data_population, | 116 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| 110 std::vector<storage::DataElement>* out); | |
| 111 | 117 |
| 112 ResponsesStatus GetResponses( | 118 ResponsesStatus GetResponses( |
| 113 const std::string& uuid, | 119 const std::string& uuid, |
| 114 const std::vector<storage::BlobItemBytesRequest>& requests, | 120 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 115 std::vector<base::SharedMemoryHandle>* memory_handles, | 121 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 116 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 122 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 117 std::vector<storage::BlobItemBytesResponse>* output); | 123 std::vector<storage::BlobItemBytesResponse>* output); |
| 118 | 124 |
| 119 // Deletes the consolidation, and if we removed the last consolidation from | 125 // Deletes the consolidation, and if we removed the last consolidation from |
| 120 // our map, we call ChildProcess::ReleaseProcess to release our previous | 126 // our map, we call ChildProcess::ReleaseProcess to release our previous |
| 121 // reference. | 127 // reference. |
| 122 void ReleaseBlobConsolidation(const std::string& uuid); | 128 void ReleaseBlobConsolidation(const std::string& uuid); |
| 123 | 129 |
| 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; | 130 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| 125 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; | 131 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; |
| 126 | 132 |
| 127 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | 133 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| 128 }; | 134 }; |
| 129 | 135 |
| 130 } // namespace content | 136 } // namespace content |
| 131 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 137 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| OLD | NEW |