| 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_async_builder_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 IPC { | 24 namespace IPC { |
| 26 class Sender; | 25 class Sender; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace storage { | 28 namespace storage { |
| 30 class DataElement; | 29 class DataElement; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, | 50 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, |
| 52 scoped_refptr<storage::FileSystemContext> file_system_context); | 51 scoped_refptr<storage::FileSystemContext> file_system_context); |
| 53 | 52 |
| 54 // BrowserMessageFilter implementation. | 53 // BrowserMessageFilter implementation. |
| 55 void OnChannelClosing() override; | 54 void OnChannelClosing() override; |
| 56 bool OnMessageReceived(const IPC::Message& message) override; | 55 bool OnMessageReceived(const IPC::Message& message) override; |
| 57 | 56 |
| 58 protected: | 57 protected: |
| 59 ~BlobDispatcherHost() override; | 58 ~BlobDispatcherHost() override; |
| 60 | 59 |
| 61 // For testing use only. | |
| 62 void SetMemoryConstantsForTesting(size_t max_ipc_memory_size, | |
| 63 size_t max_shared_memory_size, | |
| 64 uint64_t max_file_size) { | |
| 65 async_builder_.SetMemoryConstantsForTesting( | |
| 66 max_ipc_memory_size, max_shared_memory_size, max_file_size); | |
| 67 } | |
| 68 | |
| 69 private: | 60 private: |
| 70 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; | 61 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; |
| 71 friend class BlobDispatcherHostTest; | 62 friend class BlobDispatcherHostTest; |
| 72 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); | 63 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); |
| 73 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, MultipleTransfers); | 64 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, MultipleTransfers); |
| 74 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); | 65 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); |
| 75 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); | 66 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); |
| 76 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 67 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 77 BlobReferenceWhileConstructing); | 68 BlobReferenceWhileConstructing); |
| 78 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 69 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 93 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 84 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 94 DeferenceBlobOnDifferentHost); | 85 DeferenceBlobOnDifferentHost); |
| 95 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); | 86 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); |
| 96 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 87 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 97 BuildingReferenceChainWithCancel); | 88 BuildingReferenceChainWithCancel); |
| 98 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 89 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 99 BuildingReferenceChainWithSourceDeath); | 90 BuildingReferenceChainWithSourceDeath); |
| 100 | 91 |
| 101 typedef std::map<std::string, int> BlobReferenceMap; | 92 typedef std::map<std::string, int> BlobReferenceMap; |
| 102 | 93 |
| 103 void OnRegisterBlobUUID(const std::string& uuid, | 94 void OnRegisterBlob(const std::string& uuid, |
| 104 const std::string& content_type, | 95 const std::string& content_type, |
| 105 const std::string& content_disposition, | 96 const std::string& content_disposition, |
| 106 const std::set<std::string>& referenced_blob_uuids); | 97 const std::vector<storage::DataElement>& descriptions); |
| 107 void OnStartBuildingBlob( | |
| 108 const std::string& uuid, | |
| 109 const std::vector<storage::DataElement>& descriptions); | |
| 110 void OnMemoryItemResponse( | 98 void OnMemoryItemResponse( |
| 111 const std::string& uuid, | 99 const std::string& uuid, |
| 112 const std::vector<storage::BlobItemBytesResponse>& response); | 100 const std::vector<storage::BlobItemBytesResponse>& response); |
| 113 void OnCancelBuildingBlob(const std::string& uuid, | 101 void OnCancelBuildingBob(const std::string& uuid, |
| 114 const storage::IPCBlobCreationCancelCode code); | 102 const storage::BlobStatus code); |
| 115 | 103 |
| 116 void OnIncrementBlobRefCount(const std::string& uuid); | 104 void OnIncrementBlobRefCount(const std::string& uuid); |
| 117 void OnDecrementBlobRefCount(const std::string& uuid); | 105 void OnDecrementBlobRefCount(const std::string& uuid); |
| 118 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); | 106 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); |
| 119 void OnRevokePublicBlobURL(const GURL& public_url); | 107 void OnRevokePublicBlobURL(const GURL& public_url); |
| 120 | 108 |
| 121 storage::BlobStorageContext* context(); | 109 storage::BlobStorageContext* context(); |
| 122 | 110 |
| 123 void SendMemoryRequest( | 111 void SendMemoryRequest(const std::string& uuid, |
| 124 const std::string& uuid, | 112 std::vector<storage::BlobItemBytesRequest> requests, |
| 125 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, | 113 std::vector<base::SharedMemoryHandle> memory_handles, |
| 126 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, | 114 std::vector<base::File> files); |
| 127 std::unique_ptr<std::vector<base::File>> files); | |
| 128 | 115 |
| 129 // Send the appropriate IPC response to the renderer for the given result. | 116 // We send the status unless it's BlobStatus::PENDING. |
| 130 void SendIPCResponse(const std::string& uuid, | 117 void SendFinalBlobStatus(const std::string& uuid, storage::BlobStatus status); |
| 131 storage::BlobTransportResult result); | |
| 132 | 118 |
| 133 bool IsInUseInHost(const std::string& uuid); | 119 bool IsInUseInHost(const std::string& uuid); |
| 134 bool IsUrlRegisteredInHost(const GURL& blob_url); | 120 bool IsUrlRegisteredInHost(const GURL& blob_url); |
| 135 | 121 |
| 136 // Unregisters all blobs and urls that were registered in this host. | 122 // Unregisters all blobs and urls that were registered in this host. |
| 137 void ClearHostFromBlobStorageContext(); | 123 void ClearHostFromBlobStorageContext(); |
| 138 | 124 |
| 139 const int process_id_; | 125 const int process_id_; |
| 140 scoped_refptr<storage::FileSystemContext> file_system_context_; | 126 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 141 | 127 |
| 142 // Collection of blob ids and a count of how many usages | 128 // Collection of blob ids and a count of how many usages |
| 143 // of that id are attributable to this consumer. | 129 // of that id are attributable to this consumer. |
| 144 BlobReferenceMap blobs_inuse_map_; | 130 BlobReferenceMap blobs_inuse_map_; |
| 145 | 131 |
| 146 // The set of public blob urls coined by this consumer. | 132 // The set of public blob urls coined by this consumer. |
| 147 std::set<GURL> public_blob_urls_; | 133 std::set<GURL> public_blob_urls_; |
| 148 | 134 |
| 149 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 135 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 150 storage::BlobAsyncBuilderHost async_builder_; | 136 storage::BlobAsyncBuilderHost async_builder_; |
| 151 | 137 |
| 152 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); | 138 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); |
| 153 }; | 139 }; |
| 154 } // namespace content | 140 } // namespace content |
| 155 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ | 141 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
| OLD | NEW |