| 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/common/blob.mojom.h" |
| 19 #include "content/public/browser/browser_associated_interface.h" |
| 18 #include "content/public/browser/browser_message_filter.h" | 20 #include "content/public/browser/browser_message_filter.h" |
| 21 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
| 19 #include "storage/browser/blob/blob_async_builder_host.h" | 22 #include "storage/browser/blob/blob_async_builder_host.h" |
| 20 #include "storage/browser/blob/blob_transport_result.h" | 23 #include "storage/browser/blob/blob_transport_result.h" |
| 21 #include "storage/common/blob_storage/blob_storage_constants.h" | 24 #include "storage/common/blob_storage/blob_storage_constants.h" |
| 22 | 25 |
| 23 class GURL; | 26 class GURL; |
| 24 | 27 |
| 25 namespace IPC { | 28 namespace IPC { |
| 26 class Sender; | 29 class Sender; |
| 27 } | 30 } |
| 28 | 31 |
| 29 namespace storage { | 32 namespace storage { |
| 30 class DataElement; | 33 class DataElement; |
| 31 class BlobDataBuilder; | 34 class BlobDataBuilder; |
| 32 struct BlobItemBytesRequest; | 35 struct BlobItemBytesRequest; |
| 33 struct BlobItemBytesResponse; | 36 struct BlobItemBytesResponse; |
| 34 class BlobStorageContext; | 37 class BlobStorageContext; |
| 35 class FileSystemContext; | 38 class FileSystemContext; |
| 36 } | 39 } |
| 37 | 40 |
| 38 namespace content { | 41 namespace content { |
| 39 class ChromeBlobStorageContext; | 42 class ChromeBlobStorageContext; |
| 40 | 43 |
| 41 // This class's responsibility is to listen for and dispatch blob storage | 44 // This class's responsibility is to listen for and dispatch blob storage |
| 42 // messages and handle logistics of blob storage for a single child process. | 45 // messages and handle logistics of blob storage for a single child process. |
| 43 // When the child process terminates all blob references attributable to | 46 // When the child process terminates all blob references attributable to |
| 44 // that process go away upon destruction of the instance. | 47 // that process go away upon destruction of the instance. |
| 45 // This lives in the browser process, is single threaded (IO thread), and there | 48 // This lives in the browser process, is single threaded (IO thread), and there |
| 46 // is one per child process. | 49 // is one per child process. |
| 47 class CONTENT_EXPORT BlobDispatcherHost : public BrowserMessageFilter { | 50 class CONTENT_EXPORT BlobDispatcherHost |
| 51 : public BrowserMessageFilter, |
| 52 public BrowserAssociatedInterface<mojom::BlobFactory>, |
| 53 public mojom::BlobFactory, |
| 54 public mojom::Blob { |
| 48 public: | 55 public: |
| 49 BlobDispatcherHost( | 56 BlobDispatcherHost( |
| 50 int process_id, | 57 int process_id, |
| 51 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, | 58 scoped_refptr<ChromeBlobStorageContext> blob_storage_context, |
| 52 scoped_refptr<storage::FileSystemContext> file_system_context); | 59 scoped_refptr<storage::FileSystemContext> file_system_context); |
| 53 | 60 |
| 54 // BrowserMessageFilter implementation. | 61 // BrowserMessageFilter implementation. |
| 55 void OnChannelClosing() override; | 62 void OnChannelClosing() override; |
| 56 bool OnMessageReceived(const IPC::Message& message) override; | 63 bool OnMessageReceived(const IPC::Message& message) override; |
| 57 | 64 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 100 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 94 DeferenceBlobOnDifferentHost); | 101 DeferenceBlobOnDifferentHost); |
| 95 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); | 102 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BuildingReferenceChain); |
| 96 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 103 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 97 BuildingReferenceChainWithCancel); | 104 BuildingReferenceChainWithCancel); |
| 98 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, | 105 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 99 BuildingReferenceChainWithSourceDeath); | 106 BuildingReferenceChainWithSourceDeath); |
| 100 | 107 |
| 101 typedef std::map<std::string, int> BlobReferenceMap; | 108 typedef std::map<std::string, int> BlobReferenceMap; |
| 102 | 109 |
| 103 void OnRegisterBlobUUID(const std::string& uuid, | 110 // mojom::BlobFactory: |
| 104 const std::string& content_type, | 111 void BuildBlob(const std::string& uuid, |
| 105 const std::string& content_disposition, | 112 const std::string& content_type, |
| 106 const std::set<std::string>& referenced_blob_uuids); | 113 const std::string& content_disposition, |
| 107 void OnStartBuildingBlob( | 114 const std::vector<std::string>& referenced_blob_uuids, |
| 108 const std::string& uuid, | 115 const std::vector<storage::DataElement>& item_descriptions, |
| 109 const std::vector<storage::DataElement>& descriptions); | 116 const BuildBlobCallback& callback); |
| 117 |
| 110 void OnMemoryItemResponse( | 118 void OnMemoryItemResponse( |
| 111 const std::string& uuid, | 119 const std::string& uuid, |
| 112 const std::vector<storage::BlobItemBytesResponse>& response); | 120 const std::vector<storage::BlobItemBytesResponse>& response); |
| 113 void OnCancelBuildingBlob(const std::string& uuid, | |
| 114 const storage::IPCBlobCreationCancelCode code); | |
| 115 | 121 |
| 116 void OnIncrementBlobRefCount(const std::string& uuid); | 122 void OnIncrementBlobRefCount(const std::string& uuid); |
| 117 void OnDecrementBlobRefCount(const std::string& uuid); | 123 void OnDecrementBlobRefCount(const std::string& uuid); |
| 118 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); | 124 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); |
| 119 void OnRevokePublicBlobURL(const GURL& public_url); | 125 void OnRevokePublicBlobURL(const GURL& public_url); |
| 120 | 126 |
| 121 storage::BlobStorageContext* context(); | 127 storage::BlobStorageContext* context(); |
| 122 | 128 |
| 123 void SendMemoryRequest( | 129 void SendMemoryRequest( |
| 124 const std::string& uuid, | 130 const std::string& uuid, |
| 125 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, | 131 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, |
| 126 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, | 132 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, |
| 127 std::unique_ptr<std::vector<base::File>> files); | 133 std::unique_ptr<std::vector<base::File>> files); |
| 128 | 134 |
| 129 // Send the appropriate IPC response to the renderer for the given result. | 135 // Send the appropriate IPC response to the renderer for the given result. |
| 130 void SendIPCResponse(const std::string& uuid, | 136 void SendIPCResponse(const BuildBlobCallback& callback, |
| 131 storage::BlobTransportResult result); | 137 storage::BlobTransportResult result); |
| 132 | 138 |
| 133 bool IsInUseInHost(const std::string& uuid); | 139 bool IsInUseInHost(const std::string& uuid); |
| 134 bool IsUrlRegisteredInHost(const GURL& blob_url); | 140 bool IsUrlRegisteredInHost(const GURL& blob_url); |
| 135 | 141 |
| 136 // Unregisters all blobs and urls that were registered in this host. | 142 // Unregisters all blobs and urls that were registered in this host. |
| 137 void ClearHostFromBlobStorageContext(); | 143 void ClearHostFromBlobStorageContext(); |
| 138 | 144 |
| 139 const int process_id_; | 145 const int process_id_; |
| 140 scoped_refptr<storage::FileSystemContext> file_system_context_; | 146 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 141 | 147 |
| 142 // Collection of blob ids and a count of how many usages | 148 // Collection of blob ids and a count of how many usages |
| 143 // of that id are attributable to this consumer. | 149 // of that id are attributable to this consumer. |
| 144 BlobReferenceMap blobs_inuse_map_; | 150 BlobReferenceMap blobs_inuse_map_; |
| 145 | 151 |
| 146 // The set of public blob urls coined by this consumer. | 152 // The set of public blob urls coined by this consumer. |
| 147 std::set<GURL> public_blob_urls_; | 153 std::set<GURL> public_blob_urls_; |
| 148 | 154 |
| 149 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 155 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 150 storage::BlobAsyncBuilderHost async_builder_; | 156 storage::BlobAsyncBuilderHost async_builder_; |
| 151 | 157 |
| 158 mojo::AssociatedBindingSet<mojom::Blob> blob_bindings_; |
| 159 |
| 152 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); | 160 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); |
| 153 }; | 161 }; |
| 162 |
| 154 } // namespace content | 163 } // namespace content |
| 164 |
| 155 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ | 165 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
| OLD | NEW |