| 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 <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/shared_memory_handle.h" | 18 #include "base/memory/shared_memory_handle.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "ipc/ipc_platform_file.h" | 20 #include "ipc/ipc_platform_file.h" |
| 21 #include "storage/common/blob_storage/blob_storage_constants.h" | 21 #include "storage/common/blob_storage/blob_storage_constants.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 template <typename T> | 24 template <typename T> |
| 25 struct DefaultLazyInstanceTraits; | 25 struct DefaultLazyInstanceTraits; |
| 26 class SingleThreadTaskRunner; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace storage { | 29 namespace storage { |
| 29 class DataElement; | 30 class DataElement; |
| 30 struct BlobItemBytesRequest; | 31 struct BlobItemBytesRequest; |
| 31 struct BlobItemBytesResponse; | 32 struct BlobItemBytesResponse; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace IPC { | 35 namespace IPC { |
| 35 class Sender; | 36 class Sender; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 // * include shortcut data in the descriptions, | 49 // * include shortcut data in the descriptions, |
| 49 // * generate responses to blob memory requests, and | 50 // * generate responses to blob memory requests, and |
| 50 // * send IPC responses. | 51 // * send IPC responses. |
| 51 // Must be used on the IO thread. | 52 // Must be used on the IO thread. |
| 52 class CONTENT_EXPORT BlobTransportController { | 53 class CONTENT_EXPORT BlobTransportController { |
| 53 public: | 54 public: |
| 54 static BlobTransportController* GetInstance(); | 55 static BlobTransportController* GetInstance(); |
| 55 | 56 |
| 56 // This kicks off a blob transfer to the browser thread, which involves | 57 // This kicks off a blob transfer to the browser thread, which involves |
| 57 // sending an IPC message and storing the blob consolidation object. | 58 // sending an IPC message and storing the blob consolidation object. |
| 58 void InitiateBlobTransfer(const std::string& uuid, | 59 // If we have no pending blobs, we also call ChildProcess::AddRefProcess to |
| 59 const std::string& type, | 60 // keep our process around while we transfer. This will be decremented when |
| 60 scoped_ptr<BlobConsolidation> consolidation, | 61 // we finish our last pending transfer (when our map is empty). |
| 61 IPC::Sender* sender); | 62 void InitiateBlobTransfer( |
| 63 const std::string& uuid, |
| 64 scoped_ptr<BlobConsolidation> consolidation, |
| 65 IPC::Sender* sender, |
| 66 scoped_refptr<base::SingleThreadTaskRunner> main_runner); |
| 62 | 67 |
| 63 // This responds to the request using the sender. | 68 // This responds to the request using the sender. |
| 64 void OnMemoryRequest( | 69 void OnMemoryRequest( |
| 65 const std::string& uuid, | 70 const std::string& uuid, |
| 66 const std::vector<storage::BlobItemBytesRequest>& requests, | 71 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 67 std::vector<base::SharedMemoryHandle>* memory_handles, | 72 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 68 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 73 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 69 IPC::Sender* sender); | 74 IPC::Sender* sender); |
| 70 | 75 |
| 71 void OnCancel(const std::string& uuid, | 76 void OnCancel(const std::string& uuid, |
| 72 storage::IPCBlobCreationCancelCode code); | 77 storage::IPCBlobCreationCancelCode code); |
| 73 | 78 |
| 74 void OnDone(const std::string& uuid); | 79 void OnDone(const std::string& uuid); |
| 75 | 80 |
| 76 // Clears all internal state for testing and such. | |
| 77 void Clear(); | |
| 78 | 81 |
| 79 bool IsTransporting(const std::string& uuid) { | 82 bool IsTransporting(const std::string& uuid) { |
| 80 return blob_storage_.find(uuid) != blob_storage_.end(); | 83 return blob_storage_.find(uuid) != blob_storage_.end(); |
| 81 } | 84 } |
| 82 | 85 |
| 83 ~BlobTransportController(); | 86 ~BlobTransportController(); |
| 84 | 87 |
| 85 private: | 88 private: |
| 89 friend class BlobTransportControllerTest; |
| 86 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | 90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
| 87 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | 91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
| 88 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | 92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
| 89 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | 93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
| 90 | 94 |
| 95 // Clears all internal state. If our map wasn't previously empty, then we call |
| 96 // ChildProcess::ReleaseProcess to release our previous reference. |
| 97 void ClearForTesting(); |
| 98 |
| 91 enum class ResponsesStatus { | 99 enum class ResponsesStatus { |
| 92 BLOB_NOT_FOUND, | 100 BLOB_NOT_FOUND, |
| 93 SHARED_MEMORY_MAP_FAILED, | 101 SHARED_MEMORY_MAP_FAILED, |
| 94 SUCCESS | 102 SUCCESS |
| 95 }; | 103 }; |
| 96 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | 104 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
| 97 | 105 |
| 98 BlobTransportController(); | 106 BlobTransportController(); |
| 99 | 107 |
| 100 // Sends the IPC to cancel the blob transfer, and releases the blob from | |
| 101 // internal storage. | |
| 102 void CancelBlobTransfer(const std::string& uuid, | |
| 103 storage::IPCBlobCreationCancelCode code, | |
| 104 IPC::Sender* sender); | |
| 105 | |
| 106 void GetDescriptions(BlobConsolidation* consolidation, | 108 void GetDescriptions(BlobConsolidation* consolidation, |
| 107 size_t max_data_population, | 109 size_t max_data_population, |
| 108 std::vector<storage::DataElement>* out); | 110 std::vector<storage::DataElement>* out); |
| 109 | 111 |
| 110 ResponsesStatus GetResponses( | 112 ResponsesStatus GetResponses( |
| 111 const std::string& uuid, | 113 const std::string& uuid, |
| 112 const std::vector<storage::BlobItemBytesRequest>& requests, | 114 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 113 std::vector<base::SharedMemoryHandle>* memory_handles, | 115 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 114 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 116 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 115 std::vector<storage::BlobItemBytesResponse>* output); | 117 std::vector<storage::BlobItemBytesResponse>* output); |
| 116 | 118 |
| 119 // Deletes the consolidation, and if we removed the last consolidation from |
| 120 // our map, we call ChildProcess::ReleaseProcess to release our previous |
| 121 // reference. |
| 117 void ReleaseBlobConsolidation(const std::string& uuid); | 122 void ReleaseBlobConsolidation(const std::string& uuid); |
| 118 | 123 |
| 124 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| 119 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; | 125 std::map<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; |
| 120 | 126 |
| 121 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | 127 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 } // namespace content | 130 } // namespace content |
| 125 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | 131 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| OLD | NEW |