OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| 6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/containers/scoped_ptr_map.h" |
| 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/shared_memory_handle.h" |
| 17 #include "content/common/content_export.h" |
| 18 #include "ipc/ipc_platform_file.h" |
| 19 #include "storage/common/blob_storage/blob_storage_constants.h" |
| 20 |
| 21 namespace base { |
| 22 template <typename T> |
| 23 struct DefaultLazyInstanceTraits; |
| 24 } |
| 25 |
| 26 namespace storage { |
| 27 class DataElement; |
| 28 struct BlobItemBytesRequest; |
| 29 struct BlobItemBytesResponse; |
| 30 } |
| 31 |
| 32 namespace IPC { |
| 33 class Sender; |
| 34 } |
| 35 |
| 36 namespace content { |
| 37 |
| 38 class BlobConsolidation; |
| 39 |
| 40 // This class is used to manage all the asynchronous transporation of blobs from |
| 41 // the Renderer to the Browser process, where it's handling the Renderer side. |
| 42 // The function of this class is to: |
| 43 // * Be a lazy singleton, |
| 44 // * hold all of the blob data that is being transported to the Browser process, |
| 45 // * create the blob item 'descriptions' for the browser, |
| 46 // * include shortcut data in the descriptions, |
| 47 // * generate responses to blob memory requests, and |
| 48 // * send IPC responses. |
| 49 // Must be used on the IO thread. |
| 50 class CONTENT_EXPORT BlobTransportController { |
| 51 public: |
| 52 static BlobTransportController* GetInstance(); |
| 53 |
| 54 // This kicks off a blob transfer to the browser thread, which involves |
| 55 // sending an IPC message and storing the blob consolidation object. |
| 56 void InitiateBlobTransfer(const std::string& uuid, |
| 57 const std::string& type, |
| 58 scoped_ptr<BlobConsolidation> consolidation, |
| 59 IPC::Sender* sender); |
| 60 |
| 61 // This responds to the request using the sender. |
| 62 void OnMemoryRequest( |
| 63 const std::string& uuid, |
| 64 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 65 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 66 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 67 IPC::Sender* sender); |
| 68 |
| 69 void OnCancel(const std::string& uuid, |
| 70 storage::IPCBlobCreationCancelCode code); |
| 71 |
| 72 void OnDone(const std::string& uuid); |
| 73 |
| 74 // Clears all internal state for testing and such. |
| 75 void Clear(); |
| 76 |
| 77 bool IsTransporting(const std::string& uuid) { |
| 78 return blob_storage_.find(uuid) != blob_storage_.end(); |
| 79 } |
| 80 |
| 81 ~BlobTransportController(); |
| 82 |
| 83 private: |
| 84 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
| 85 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
| 86 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
| 87 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
| 88 |
| 89 enum class ResponsesStatus { |
| 90 BLOB_NOT_FOUND, |
| 91 SHARED_MEMORY_MAP_FAILED, |
| 92 SUCCESS |
| 93 }; |
| 94 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
| 95 |
| 96 BlobTransportController(); |
| 97 |
| 98 // Sends the IPC to cancel the blob transfer, and releases the blob from |
| 99 // internal storage. |
| 100 void CancelBlobTransfer(const std::string& uuid, |
| 101 storage::IPCBlobCreationCancelCode code, |
| 102 IPC::Sender* sender); |
| 103 |
| 104 void GetDescriptions(BlobConsolidation* consolidation, |
| 105 size_t max_data_population, |
| 106 std::vector<storage::DataElement>* out); |
| 107 |
| 108 ResponsesStatus GetResponses( |
| 109 const std::string& uuid, |
| 110 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 111 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 112 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 113 std::vector<storage::BlobItemBytesResponse>* output); |
| 114 |
| 115 void ReleaseBlobConsolidation(const std::string& uuid); |
| 116 |
| 117 base::ScopedPtrMap<std::string, scoped_ptr<BlobConsolidation>> blob_storage_; |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
| 120 }; |
| 121 |
| 122 } // namespace content |
| 123 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
OLD | NEW |