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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.h

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Created 4 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/id_map.h" 16 #include "base/id_map.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h"
20 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 19 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
21 #include "content/common/indexed_db/indexed_db.mojom.h" 20 #include "content/common/indexed_db/indexed_db.mojom.h"
22 #include "content/public/browser/browser_associated_interface.h" 21 #include "content/public/browser/browser_associated_interface.h"
23 #include "content/public/browser/browser_message_filter.h" 22 #include "content/public/browser/browser_message_filter.h"
24 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
25 #include "storage/browser/blob/blob_data_handle.h" 24 #include "storage/browser/blob/blob_data_handle.h"
26 #include "storage/browser/quota/quota_manager.h"
27 #include "storage/common/quota/quota_status_code.h"
28 #include "url/gurl.h" 25 #include "url/gurl.h"
29 26
30 struct IndexedDBDatabaseMetadata;
31 struct IndexedDBHostMsg_DatabaseCount_Params;
32 struct IndexedDBHostMsg_DatabaseCreateIndex_Params;
33 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params;
34 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params;
35 struct IndexedDBHostMsg_DatabaseDeleteRange_Params;
36 struct IndexedDBHostMsg_DatabaseGet_Params;
37 struct IndexedDBHostMsg_DatabaseGetAll_Params;
38 struct IndexedDBHostMsg_DatabaseObserve_Params; 27 struct IndexedDBHostMsg_DatabaseObserve_Params;
39 struct IndexedDBHostMsg_DatabaseOpenCursor_Params;
40 struct IndexedDBHostMsg_DatabasePut_Params;
41 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params;
42 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params;
43 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params;
44 struct IndexedDBHostMsg_FactoryOpen_Params;
45 struct IndexedDBMsg_Observation; 28 struct IndexedDBMsg_Observation;
46 struct IndexedDBMsg_ObserverChanges; 29 struct IndexedDBMsg_ObserverChanges;
47 30
48 namespace url { 31 namespace url {
49 class Origin; 32 class Origin;
50 } 33 }
51 34
52 namespace content { 35 namespace content {
53 class IndexedDBBlobInfo; 36 class IndexedDBBlobInfo;
54 class IndexedDBCallbacks; 37 class IndexedDBCallbacks;
55 class IndexedDBConnection; 38 class IndexedDBConnection;
56 class IndexedDBContextImpl; 39 class IndexedDBContextImpl;
57 class IndexedDBCursor; 40 class IndexedDBCursor;
58 class IndexedDBDatabaseCallbacks; 41 class IndexedDBDatabaseCallbacks;
59 class IndexedDBKey; 42 class IndexedDBKey;
60 class IndexedDBKeyPath;
61 class IndexedDBKeyRange;
62 class IndexedDBObservation; 43 class IndexedDBObservation;
63 class IndexedDBObserverChanges; 44 class IndexedDBObserverChanges;
64 struct IndexedDBDatabaseMetadata;
65 45
66 // Handles all IndexedDB related messages from a particular renderer process. 46 // Handles all IndexedDB related messages from a particular renderer process.
67 class IndexedDBDispatcherHost 47 class IndexedDBDispatcherHost
68 : public BrowserMessageFilter, 48 : public BrowserMessageFilter,
69 public BrowserAssociatedInterface<::indexed_db::mojom::Factory>, 49 public BrowserAssociatedInterface<::indexed_db::mojom::Factory>,
70 public ::indexed_db::mojom::Factory { 50 public ::indexed_db::mojom::Factory {
71 public: 51 public:
72 // Only call the constructor from the UI thread. 52 // Only call the constructor from the UI thread.
73 IndexedDBDispatcherHost(int ipc_process_id, 53 IndexedDBDispatcherHost(int ipc_process_id,
74 net::URLRequestContextGetter* request_context_getter, 54 net::URLRequestContextGetter* request_context_getter,
(...skipping 12 matching lines...) Expand all
87 const IPC::Message& message) override; 67 const IPC::Message& message) override;
88 bool OnMessageReceived(const IPC::Message& message) override; 68 bool OnMessageReceived(const IPC::Message& message) override;
89 69
90 void FinishTransaction(int64_t host_transaction_id, bool committed); 70 void FinishTransaction(int64_t host_transaction_id, bool committed);
91 71
92 // A shortcut for accessing our context. 72 // A shortcut for accessing our context.
93 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } 73 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); }
94 storage::BlobStorageContext* blob_storage_context() const { 74 storage::BlobStorageContext* blob_storage_context() const {
95 return blob_storage_context_->context(); 75 return blob_storage_context_->context();
96 } 76 }
77 int ipc_process_id() { return ipc_process_id_; }
cmumford 2016/10/28 18:40:53 const
Reilly Grant (use Gerrit) 2016/11/03 21:32:21 Done.
97 78
98 // IndexedDBCallbacks call these methods to add the results into the 79 // IndexedDBCallbacks call these methods to add the results into the
99 // applicable map. See below for more details. 80 // applicable map. See below for more details.
100 int32_t Add(IndexedDBCursor* cursor); 81 int32_t Add(IndexedDBCursor* cursor);
101 int32_t Add(IndexedDBConnection* connection,
102 const url::Origin& origin);
103 82
104 void RegisterTransactionId(int64_t host_transaction_id, 83 bool RegisterTransactionId(int64_t host_transaction_id,
105 const url::Origin& origin); 84 const url::Origin& origin);
85 bool GetTransactionSize(int64_t host_transaction_id,
86 int64_t* transaction_size);
87 void AddToTransaction(int64_t host_transaction_id, int64_t value_length);
106 88
107 IndexedDBCursor* GetCursorFromId(int32_t ipc_cursor_id); 89 IndexedDBCursor* GetCursorFromId(int32_t ipc_cursor_id);
108 90
109 // These are called to map a 32-bit front-end (renderer-specific) transaction 91 // These are called to map a 32-bit front-end (renderer-specific) transaction
110 // id to and from a back-end ("host") transaction id that encodes the process 92 // id to and from a back-end ("host") transaction id that encodes the process
111 // id in the high 32 bits. The mapping is host-specific and ids are validated. 93 // id in the high 32 bits. The mapping is host-specific and ids are validated.
112 int64_t HostTransactionId(int64_t transaction_id); 94 int64_t HostTransactionId(int64_t transaction_id);
113 int64_t RendererTransactionId(int64_t host_transaction_id); 95 int64_t RendererTransactionId(int64_t host_transaction_id);
114 96
115 // These are called to decode a host transaction ID, for diagnostic purposes. 97 // These are called to decode a host transaction ID, for diagnostic purposes.
116 static uint32_t TransactionIdToRendererTransactionId( 98 static uint32_t TransactionIdToRendererTransactionId(
117 int64_t host_transaction_id); 99 int64_t host_transaction_id);
118 static uint32_t TransactionIdToProcessId(int64_t host_transaction_id); 100 static uint32_t TransactionIdToProcessId(int64_t host_transaction_id);
119 101
120 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); 102 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info);
103 void DropBlobData(const std::string& uuid);
121 104
122 // True if the channel is closing/closed and outstanding requests 105 // True if the channel is closing/closed and outstanding requests
123 // can be abandoned. Only access on IndexedDB thread. 106 // can be abandoned. Only access on IndexedDB thread.
124 bool IsOpen() const; 107 bool IsOpen() const;
125 108
126 private: 109 private:
127 // Friends to enable OnDestruct() delegation. 110 // Friends to enable OnDestruct() delegation.
128 friend class BrowserThread; 111 friend class BrowserThread;
129 friend class base::DeleteHelper<IndexedDBDispatcherHost>; 112 friend class base::DeleteHelper<IndexedDBDispatcherHost>;
130 113
131 // Used in nested classes. 114 // Used in nested classes.
132 typedef std::map<int64_t, int64_t> TransactionIDToDatabaseIDMap; 115 typedef std::map<int64_t, int64_t> TransactionIDToDatabaseIDMap;
133 typedef std::map<int64_t, uint64_t> TransactionIDToSizeMap; 116 typedef std::map<int64_t, uint64_t> TransactionIDToSizeMap;
134 typedef std::map<int64_t, url::Origin> TransactionIDToOriginMap; 117 typedef std::map<int64_t, url::Origin> TransactionIDToOriginMap;
135 typedef std::map<int32_t, url::Origin> WebIDBObjectIDToOriginMap;
136 118
137 // IDMap for RefCounted types 119 // IDMap for RefCounted types
138 template <typename RefCountedType> 120 template <typename RefCountedType>
139 class RefIDMap { 121 class RefIDMap {
140 public: 122 public:
141 typedef int32_t KeyType; 123 typedef int32_t KeyType;
142 124
143 RefIDMap() {} 125 RefIDMap() {}
144 ~RefIDMap() {} 126 ~RefIDMap() {}
145 127
(...skipping 13 matching lines...) Expand all
159 void set_check_on_null_data(bool value) { 141 void set_check_on_null_data(bool value) {
160 map_.set_check_on_null_data(value); 142 map_.set_check_on_null_data(value);
161 } 143 }
162 144
163 private: 145 private:
164 IDMap<scoped_refptr<RefCountedType>, IDMapOwnPointer> map_; 146 IDMap<scoped_refptr<RefCountedType>, IDMapOwnPointer> map_;
165 147
166 DISALLOW_COPY_AND_ASSIGN(RefIDMap); 148 DISALLOW_COPY_AND_ASSIGN(RefIDMap);
167 }; 149 };
168 150
169 class DatabaseDispatcherHost {
170 public:
171 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent);
172 ~DatabaseDispatcherHost();
173
174 void CloseAll();
175 bool OnMessageReceived(const IPC::Message& message);
176
177 void OnCreateObjectStore(
178 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params);
179 void OnDeleteObjectStore(int32_t ipc_database_id,
180 int64_t transaction_id,
181 int64_t object_store_id);
182 void OnRenameObjectStore(int32_t ipc_database_id,
183 int64_t transaction_id,
184 int64_t object_store_id,
185 const base::string16& new_name);
186 void OnCreateTransaction(
187 const IndexedDBHostMsg_DatabaseCreateTransaction_Params&);
188 void OnClose(int32_t ipc_database_id);
189 void OnVersionChangeIgnored(int32_t ipc_database_id);
190 void OnDestroyed(int32_t ipc_database_id);
191
192 void OnObserve(const IndexedDBHostMsg_DatabaseObserve_Params&);
193 void OnUnobserve(int32_t ipc_database_id,
194 const std::vector<int32_t>& observer_ids_to_remove);
195
196 void OnGet(const IndexedDBHostMsg_DatabaseGet_Params& params);
197 void OnGetAll(const IndexedDBHostMsg_DatabaseGetAll_Params& params);
198 // OnPutWrapper starts on the IO thread so that it can grab BlobDataHandles
199 // before posting to the IDB TaskRunner for the rest of the job.
200 void OnPutWrapper(const IndexedDBHostMsg_DatabasePut_Params& params);
201 void OnPut(const IndexedDBHostMsg_DatabasePut_Params& params,
202 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles);
203 void OnSetIndexKeys(
204 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params);
205 void OnSetIndexesReady(int32_t ipc_database_id,
206 int64_t transaction_id,
207 int64_t object_store_id,
208 const std::vector<int64_t>& ids);
209 void OnOpenCursor(const IndexedDBHostMsg_DatabaseOpenCursor_Params& params);
210 void OnCount(const IndexedDBHostMsg_DatabaseCount_Params& params);
211 void OnDeleteRange(
212 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params);
213 void OnClear(int32_t ipc_thread_id,
214 int32_t ipc_callbacks_id,
215 int32_t ipc_database_id,
216 int64_t transaction_id,
217 int64_t object_store_id);
218 void OnCreateIndex(
219 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params);
220 void OnDeleteIndex(int32_t ipc_database_id,
221 int64_t transaction_id,
222 int64_t object_store_id,
223 int64_t index_id);
224 void OnRenameIndex(int32_t ipc_database_id,
225 int64_t transaction_id,
226 int64_t object_store_id,
227 int64_t index_id,
228 const base::string16& new_name);
229
230 void OnAbort(int32_t ipc_database_id, int64_t transaction_id);
231 void OnCommit(int32_t ipc_database_id, int64_t transaction_id);
232 void OnGotUsageAndQuotaForCommit(int32_t ipc_database_id,
233 int64_t transaction_id,
234 storage::QuotaStatusCode status,
235 int64_t usage,
236 int64_t quota);
237
238 IndexedDBDispatcherHost* parent_;
239 IDMap<IndexedDBConnection, IDMapOwnPointer> map_;
240 WebIDBObjectIDToOriginMap database_origin_map_;
241 TransactionIDToSizeMap transaction_size_map_;
242 TransactionIDToOriginMap transaction_origin_map_;
243 TransactionIDToDatabaseIDMap transaction_database_map_;
244
245 // Weak pointers are used when an asynchronous quota request is made, in
246 // case the dispatcher is torn down before the response returns.
247 base::WeakPtrFactory<DatabaseDispatcherHost> weak_factory_;
248
249 private:
250 DISALLOW_COPY_AND_ASSIGN(DatabaseDispatcherHost);
251 };
252
253 class CursorDispatcherHost { 151 class CursorDispatcherHost {
254 public: 152 public:
255 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent); 153 explicit CursorDispatcherHost(IndexedDBDispatcherHost* parent);
256 ~CursorDispatcherHost(); 154 ~CursorDispatcherHost();
257 155
258 bool OnMessageReceived(const IPC::Message& message); 156 bool OnMessageReceived(const IPC::Message& message);
259 157
260 void OnAdvance(int32_t ipc_object_store_id, 158 void OnAdvance(int32_t ipc_object_store_id,
261 int32_t ipc_thread_id, 159 int32_t ipc_thread_id,
262 int32_t ipc_callbacks_id, 160 int32_t ipc_callbacks_id,
(...skipping 16 matching lines...) Expand all
279 RefIDMap<IndexedDBCursor> map_; 177 RefIDMap<IndexedDBCursor> map_;
280 178
281 private: 179 private:
282 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost); 180 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost);
283 }; 181 };
284 182
285 ~IndexedDBDispatcherHost() override; 183 ~IndexedDBDispatcherHost() override;
286 184
287 // Helper templates. 185 // Helper templates.
288 template <class ReturnType> 186 template <class ReturnType>
289 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map,
290 int32_t ipc_return_object_id);
291 template <class ReturnType>
292 ReturnType* GetOrTerminateProcess(RefIDMap<ReturnType>* map, 187 ReturnType* GetOrTerminateProcess(RefIDMap<ReturnType>* map,
293 int32_t ipc_return_object_id); 188 int32_t ipc_return_object_id);
294 189
295 template <typename MapType> 190 template <typename MapType>
296 void DestroyObject(MapType* map, int32_t ipc_object_id); 191 void DestroyObject(MapType* map, int32_t ipc_object_id);
297 192
298 // indexed_db::mojom::Factory implementation: 193 // indexed_db::mojom::Factory implementation:
299 void GetDatabaseNames( 194 void GetDatabaseNames(
300 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 195 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
301 const url::Origin& origin) override; 196 const url::Origin& origin) override;
(...skipping 19 matching lines...) Expand all
321 const base::string16& name, 216 const base::string16& name,
322 int64_t version, 217 int64_t version,
323 int64_t transaction_id); 218 int64_t transaction_id);
324 void DeleteDatabaseOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, 219 void DeleteDatabaseOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks,
325 const url::Origin& origin, 220 const url::Origin& origin,
326 const base::string16& name); 221 const base::string16& name);
327 222
328 // Message processing. Most of the work is delegated to the dispatcher hosts 223 // Message processing. Most of the work is delegated to the dispatcher hosts
329 // below. 224 // below.
330 void OnAckReceivedBlobs(const std::vector<std::string>& uuids); 225 void OnAckReceivedBlobs(const std::vector<std::string>& uuids);
331 void OnPutHelper(
332 const IndexedDBHostMsg_DatabasePut_Params& params,
333 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles);
334 226
335 void ResetDispatcherHosts(); 227 void ResetDispatcherHosts();
336 void DropBlobData(const std::string& uuid);
337 228
338 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 229 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
339 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; 230 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
340 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; 231 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
341 232
342 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count 233 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count
343 // is incremented in HoldBlobData(), and count is decremented and/or entry 234 // is incremented in HoldBlobData(), and count is decremented and/or entry
344 // removed in DropBlobData(). 235 // removed in DropBlobData().
345 std::map<std::string, 236 std::map<std::string,
346 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> 237 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>>
347 blob_data_handle_map_; 238 blob_data_handle_map_;
348 239
349 // Only access on IndexedDB thread. 240 // Only access on IndexedDB thread.
350 bool is_open_ = true; 241 bool is_open_ = true;
351 std::unique_ptr<DatabaseDispatcherHost> database_dispatcher_host_; 242 TransactionIDToSizeMap transaction_size_map_;
243 TransactionIDToOriginMap transaction_origin_map_;
352 std::unique_ptr<CursorDispatcherHost> cursor_dispatcher_host_; 244 std::unique_ptr<CursorDispatcherHost> cursor_dispatcher_host_;
353 245
354 // Used to set file permissions for blob storage. 246 // Used to set file permissions for blob storage.
355 int ipc_process_id_; 247 int ipc_process_id_;
356 248
357 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); 249 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost);
358 }; 250 };
359 251
360 } // namespace content 252 } // namespace content
361 253
362 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ 254 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698