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