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 <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
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 // This function of this class is to: | |
michaeln
2015/10/22 21:12:42
This s/b The
dmurph
2015/10/22 23:43:04
Done.
| |
43 // * Be a lazy singleton, | |
44 // * delegate calls to the BlobTransportTemporaryHolder, and | |
michaeln
2015/10/22 21:12:42
comment is stale
dmurph
2015/10/22 23:43:04
Fixed.
| |
45 // * send IPC responses. | |
46 // Must be used on the IO thread. | |
47 class CONTENT_EXPORT BlobTransportController { | |
michaeln
2015/10/22 21:10:22
thnx for smushing the classes together!
| |
48 public: | |
49 static BlobTransportController* GetInstance(); | |
50 | |
51 // This kicks off a blob transfer to the browser thread, which involves | |
52 // sending an IPC message and storing the blob consolidation object. | |
53 void InitiateBlobTransfer(const std::string& uuid, | |
54 const std::string& type, | |
55 scoped_ptr<BlobConsolidation> consolidation, | |
56 IPC::Sender* sender); | |
57 | |
58 // This responds to the request using the sender. | |
59 void OnMemoryRequest( | |
60 const std::string& uuid, | |
61 const std::vector<storage::BlobItemBytesRequest>& requests, | |
62 std::vector<base::SharedMemoryHandle>* memory_handles, | |
63 const std::vector<IPC::PlatformFileForTransit>& file_handles, | |
64 IPC::Sender* sender); | |
65 | |
66 void OnCancel(const std::string& uuid, | |
67 storage::IPCBlobCreationCancelCode code); | |
68 | |
69 void OnDone(const std::string& uuid); | |
70 | |
71 // Clears all internal state for testing and such. | |
72 void Clear(); | |
73 | |
74 ~BlobTransportController(); | |
75 | |
76 private: | |
77 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); | |
78 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); | |
79 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); | |
80 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); | |
81 | |
82 enum class ResponsesStatus { | |
83 BLOB_NOT_FOUND, | |
84 INVALID_ITEM_INDEX, | |
85 INVALID_DATA_RANGE, | |
86 INVALID_ITEM, | |
87 INVALID_HANDLE_INDEX, | |
88 SHARED_MEMORY_MAP_FAILED, | |
89 SUCCESS | |
90 }; | |
91 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; | |
92 | |
93 BlobTransportController(); | |
94 | |
95 // Sends the IPC to cancel the blob transfer, and releases the blob from | |
96 // internal storage. | |
97 void CancelBlobTransfer(const std::string& uuid, | |
98 storage::IPCBlobCreationCancelCode code, | |
99 IPC::Sender* sender); | |
100 | |
101 // Gives the blob data to this class to hold. | |
102 // Returns false if there already exists a blob with that uuid. If that is | |
103 // the case, then the consolidation is destroyed. | |
104 bool HoldBlobConsolidation(const std::string& uuid, | |
105 scoped_ptr<BlobConsolidation> consolidation); | |
106 | |
107 void GetDescriptions(const std::string& uuid, | |
108 size_t max_data_population, | |
109 std::vector<storage::DataElement>* out); | |
110 | |
111 ResponsesStatus GetResponses( | |
112 const std::string& uuid, | |
113 const std::vector<storage::BlobItemBytesRequest>& requests, | |
114 std::vector<base::SharedMemoryHandle>* memory_handles, | |
115 const std::vector<IPC::PlatformFileForTransit>& file_handles, | |
116 std::vector<storage::BlobItemBytesResponse>* output); | |
117 | |
118 void ReleaseBlob(const std::string& uuid); | |
michaeln
2015/10/22 21:10:22
naming nit: Releaseonsolidation to harmonize with
dmurph
2015/10/22 23:43:04
Done.
| |
119 | |
120 BlobConsolidation* GetConsolidation(const std::string& uuid); | |
121 | |
122 std::map<std::string, BlobConsolidation*> blob_storage_; | |
123 | |
124 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); | |
125 }; | |
126 | |
127 } // namespace content | |
128 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ | |
OLD | NEW |