Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: content/browser/blob_storage/blob_dispatcher_host.h

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: Comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
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 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
89 DeferenceBlobOnDifferentHost);
90
91 typedef std::map<std::string, int> BlobReferenceMap;
92
93 void OnRegisterBlobUUID(const std::string& uuid,
94 const std::string& content_type,
95 const std::string& content_disposition,
96 const std::set<std::string>& referenced_blob_uuids);
97 void OnStartBuildingBlob(
98 const std::string& uuid,
99 const std::vector<storage::DataElement>& descriptions);
100 void OnMemoryItemResponse(
101 const std::string& uuid,
102 const std::vector<storage::BlobItemBytesResponse>& response);
103 void OnCancelBuildingBlob(const std::string& uuid,
104 const storage::IPCBlobCreationCancelCode code);
105
106 void OnIncrementBlobRefCount(const std::string& uuid);
107 void OnDecrementBlobRefCount(const std::string& uuid);
108 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid);
109 void OnRevokePublicBlobURL(const GURL& public_url);
110
111 storage::BlobStorageContext* context();
112
113 void SendMemoryRequest(
114 const std::string& uuid,
115 scoped_ptr<std::vector<storage::BlobItemBytesRequest>> requests,
116 scoped_ptr<std::vector<base::SharedMemoryHandle>> memory_handles,
117 scoped_ptr<std::vector<base::File>> files);
118
119 // Send the appropriate IPC response to the renderer for the given result.
120 void SendIPCResponse(const std::string& uuid,
121 storage::BlobTransportResult result);
122
123 bool IsInUseInHost(const std::string& uuid);
124 bool IsUrlRegisteredInHost(const GURL& blob_url);
125
126 // Unregisters all blobs and urls that were registered in this host.
127 void ClearHostFromBlobStorageContext();
128
129 // Collection of blob ids and a count of how many usages
130 // of that id are attributable to this consumer.
131 BlobReferenceMap blobs_inuse_map_;
132
133 // The set of public blob urls coined by this consumer.
134 std::set<GURL> public_blob_urls_;
135
136 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
137 storage::BlobAsyncBuilderHost async_builder_;
138
139 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost);
140 };
141 } // namespace content
142 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698