OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/shared_memory_handle.h" | 16 #include "base/memory/shared_memory_handle.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "content/public/browser/browser_message_filter.h" | 18 #include "content/public/browser/browser_message_filter.h" |
19 #include "storage/browser/blob/blob_async_builder_host.h" | 19 #include "storage/browser/blob/blob_transport_host.h" |
20 #include "storage/browser/blob/blob_transport_result.h" | |
21 #include "storage/common/blob_storage/blob_storage_constants.h" | 20 #include "storage/common/blob_storage/blob_storage_constants.h" |
22 | 21 |
23 class GURL; | 22 class GURL; |
24 | 23 |
25 namespace storage { | 24 namespace storage { |
26 class DataElement; | 25 class DataElement; |
27 struct BlobItemBytesRequest; | 26 struct BlobItemBytesRequest; |
28 struct BlobItemBytesResponse; | 27 struct BlobItemBytesResponse; |
29 class BlobStorageContext; | 28 class BlobStorageContext; |
30 class FileSystemContext; | 29 class FileSystemContext; |
(...skipping 15 matching lines...) Expand all Loading... |
46 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, | 45 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, |
47 scoped_refptr<storage::FileSystemContext> file_system_context); | 46 scoped_refptr<storage::FileSystemContext> file_system_context); |
48 | 47 |
49 // BrowserMessageFilter implementation. | 48 // BrowserMessageFilter implementation. |
50 void OnChannelClosing() override; | 49 void OnChannelClosing() override; |
51 bool OnMessageReceived(const IPC::Message& message) override; | 50 bool OnMessageReceived(const IPC::Message& message) override; |
52 | 51 |
53 protected: | 52 protected: |
54 ~BlobDispatcherHost() override; | 53 ~BlobDispatcherHost() override; |
55 | 54 |
56 // For testing use only. | |
57 void SetMemoryConstantsForTesting(size_t max_ipc_memory_size, | |
58 size_t max_shared_memory_size, | |
59 uint64_t max_file_size) { | |
60 async_builder_.SetMemoryConstantsForTesting( | |
61 max_ipc_memory_size, max_shared_memory_size, max_file_size); | |
62 } | |
63 | |
64 private: | 55 private: |
65 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; | 56 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; |
66 friend class BlobDispatcherHostTest; | 57 friend class BlobDispatcherHostTest; |
67 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); | 58 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); |
68 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, MultipleTransfers); | 59 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, MultipleTransfers); |
69 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); | 60 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); |
70 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); | 61 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); |
71 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 62 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
72 BlobReferenceWhileConstructing); | 63 BlobReferenceWhileConstructing); |
73 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 64 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
(...skipping 14 matching lines...) Expand all Loading... |
88 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 79 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
89 DeferenceBlobOnDifferentHost); | 80 DeferenceBlobOnDifferentHost); |
90 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); | 81 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); |
91 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 82 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
92 BuildingReferenceChainWithCancel); | 83 BuildingReferenceChainWithCancel); |
93 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 84 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
94 BuildingReferenceChainWithSourceDeath); | 85 BuildingReferenceChainWithSourceDeath); |
95 | 86 |
96 typedef std::map<std::string, int> BlobReferenceMap; | 87 typedef std::map<std::string, int> BlobReferenceMap; |
97 | 88 |
98 void OnRegisterBlobUUID(const std::string& uuid, | 89 void OnRegisterBlob(const std::string& uuid, |
99 const std::string& content_type, | 90 const std::string& content_type, |
100 const std::string& content_disposition, | 91 const std::string& content_disposition, |
101 const std::set<std::string>& referenced_blob_uuids); | 92 const std::vector<storage::DataElement>& descriptions); |
102 void OnStartBuildingBlob( | |
103 const std::string& uuid, | |
104 const std::vector<storage::DataElement>& descriptions); | |
105 void OnMemoryItemResponse( | 93 void OnMemoryItemResponse( |
106 const std::string& uuid, | 94 const std::string& uuid, |
107 const std::vector<storage::BlobItemBytesResponse>& response); | 95 const std::vector<storage::BlobItemBytesResponse>& response); |
108 void OnCancelBuildingBlob(const std::string& uuid, | 96 void OnCancelBuildingBlob(const std::string& uuid, |
109 const storage::IPCBlobCreationCancelCode code); | 97 const storage::BlobStatus code); |
110 | 98 |
111 void OnIncrementBlobRefCount(const std::string& uuid); | 99 void OnIncrementBlobRefCount(const std::string& uuid); |
112 void OnDecrementBlobRefCount(const std::string& uuid); | 100 void OnDecrementBlobRefCount(const std::string& uuid); |
113 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); | 101 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); |
114 void OnRevokePublicBlobURL(const GURL& public_url); | 102 void OnRevokePublicBlobURL(const GURL& public_url); |
115 | 103 |
116 storage::BlobStorageContext* context(); | 104 storage::BlobStorageContext* context(); |
117 | 105 |
118 void SendMemoryRequest( | 106 void SendMemoryRequest(const std::string& uuid, |
119 const std::string& uuid, | 107 std::vector<storage::BlobItemBytesRequest> requests, |
120 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, | 108 std::vector<base::SharedMemoryHandle> memory_handles, |
121 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, | 109 std::vector<base::File> files); |
122 std::unique_ptr<std::vector<base::File>> files); | |
123 | 110 |
124 // Send the appropriate IPC response to the renderer for the given result. | 111 // The status should never be a pending status (see BlobStatusIsPending). |
125 void SendIPCResponse(const std::string& uuid, | 112 void SendFinalBlobStatus(const std::string& uuid, storage::BlobStatus status); |
126 storage::BlobTransportResult result); | |
127 | 113 |
128 bool IsInUseInHost(const std::string& uuid); | 114 bool IsInUseInHost(const std::string& uuid); |
129 bool IsUrlRegisteredInHost(const GURL& blob_url); | 115 bool IsUrlRegisteredInHost(const GURL& blob_url); |
130 | 116 |
131 // Unregisters all blobs and urls that were registered in this host. | 117 // Unregisters all blobs and urls that were registered in this host. |
132 void ClearHostFromBlobStorageContext(); | 118 void ClearHostFromBlobStorageContext(); |
133 | 119 |
134 const int process_id_; | 120 const int process_id_; |
135 scoped_refptr<storage::FileSystemContext> file_system_context_; | 121 scoped_refptr<storage::FileSystemContext> file_system_context_; |
136 | 122 |
137 // Collection of blob ids and a count of how many usages | 123 // Collection of blob ids and a count of how many usages |
138 // of that id are attributable to this consumer. | 124 // of that id are attributable to this consumer. |
139 BlobReferenceMap blobs_inuse_map_; | 125 BlobReferenceMap blobs_inuse_map_; |
140 | 126 |
141 // The set of public blob urls coined by this consumer. | 127 // The set of public blob urls coined by this consumer. |
142 std::set<GURL> public_blob_urls_; | 128 std::set<GURL> public_blob_urls_; |
143 | 129 |
144 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 130 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
145 storage::BlobAsyncBuilderHost async_builder_; | 131 storage::BlobTransportHost transport_host_; |
146 | 132 |
147 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); | 133 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); |
148 }; | 134 }; |
149 } // namespace content | 135 } // namespace content |
150 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ | 136 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
OLD | NEW |