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_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/files/file.h" |
| 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/shared_memory_handle.h" |
| 17 #include "content/common/content_export.h" |
| 18 #include "content/public/browser/browser_message_filter.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" |
| 22 |
| 23 class GURL; |
| 24 |
| 25 namespace IPC { |
| 26 class Sender; |
| 27 } |
| 28 |
| 29 namespace storage { |
| 30 class DataElement; |
| 31 class BlobDataBuilder; |
| 32 struct BlobItemBytesRequest; |
| 33 struct BlobItemBytesResponse; |
| 34 class BlobStorageContext; |
| 35 } |
| 36 |
| 37 namespace content { |
| 38 class ChromeBlobStorageContext; |
| 39 |
| 40 // This class's responsibility is to listen for and dispatch blob storage |
| 41 // messages and handle logistics of blob storage for a single child process. |
| 42 // When the child process terminates all blob references attributable to |
| 43 // that process go away upon destruction of the instance. |
| 44 // This lives in the browser process, is single threaded (IO thread), and there |
| 45 // is one per child process. |
| 46 class CONTENT_EXPORT BlobDispatcherHost : public BrowserMessageFilter { |
| 47 public: |
| 48 explicit BlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context); |
| 49 |
| 50 // BrowserMessageFilter implementation. |
| 51 void OnChannelClosing() override; |
| 52 bool OnMessageReceived(const IPC::Message& message) override; |
| 53 |
| 54 protected: |
| 55 ~BlobDispatcherHost() override; |
| 56 |
| 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: |
| 66 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; |
| 67 friend class BlobDispatcherHostTest; |
| 68 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); |
| 69 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); |
| 70 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); |
| 71 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 72 BlobReferenceWhileConstructing); |
| 73 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 74 BlobReferenceWhileShortcutConstructing); |
| 75 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 76 BlobReferenceWhileConstructingCancelled); |
| 77 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterRegister); |
| 78 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterOnStart); |
| 79 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 80 DecrementRefAfterOnStartWithHandle); |
| 81 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 82 HostDisconnectAfterRegisterWithHandle); |
| 83 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, HostDisconnectAfterOnStart); |
| 84 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 85 HostDisconnectAfterOnMemoryResponse); |
| 86 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, |
| 87 CreateBlobWithBrokenReference); |
| 88 |
| 89 typedef std::map<std::string, int> BlobReferenceMap; |
| 90 |
| 91 void OnRegisterBlobUUID(const std::string& uuid, |
| 92 const std::string& content_type, |
| 93 const std::string& content_disposition, |
| 94 const std::set<std::string>& referenced_blob_uuids); |
| 95 void OnStartBuildingBlob( |
| 96 const std::string& uuid, |
| 97 const std::vector<storage::DataElement>& descriptions); |
| 98 void OnMemoryItemResponse( |
| 99 const std::string& uuid, |
| 100 const std::vector<storage::BlobItemBytesResponse>& response); |
| 101 void OnCancelBuildingBlob(const std::string& uuid, |
| 102 const storage::IPCBlobCreationCancelCode code); |
| 103 |
| 104 void OnIncrementBlobRefCount(const std::string& uuid); |
| 105 void OnDecrementBlobRefCount(const std::string& uuid); |
| 106 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); |
| 107 void OnRevokePublicBlobURL(const GURL& public_url); |
| 108 |
| 109 storage::BlobStorageContext* context(); |
| 110 |
| 111 void SendMemoryRequest( |
| 112 const std::string& uuid, |
| 113 scoped_ptr<std::vector<storage::BlobItemBytesRequest>> requests, |
| 114 scoped_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, |
| 115 scoped_ptr<std::vector<base::File>> files); |
| 116 |
| 117 // Send the appropriate IPC response to the renderer for the given result. |
| 118 void SendIPCResponse(const std::string& uuid, |
| 119 storage::BlobTransportResult result); |
| 120 |
| 121 bool IsInUseInHost(const std::string& uuid); |
| 122 bool IsBeingBuiltInHost(const std::string& uuid); |
| 123 bool IsUrlRegisteredInHost(const GURL& blob_url); |
| 124 |
| 125 // Unregisters all blobs and urls that were registered in this host. |
| 126 void ClearHostFromBlobStorageContext(); |
| 127 |
| 128 // Collection of blob ids and a count of how many usages |
| 129 // of that id are attributable to this consumer. |
| 130 BlobReferenceMap blobs_inuse_map_; |
| 131 |
| 132 // The set of public blob urls coined by this consumer. |
| 133 std::set<GURL> public_blob_urls_; |
| 134 |
| 135 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 136 storage::BlobAsyncBuilderHost async_builder_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); |
| 139 }; |
| 140 } // namespace content |
| 141 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ |
OLD | NEW |