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

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.h

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Allow cpp_only to be set by the invoker. Created 4 years, 2 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
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/strings/nullable_string16.h" 19 #include "base/strings/nullable_string16.h"
20 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
21 #include "content/common/indexed_db/indexed_db_constants.h" 21 #include "content/common/indexed_db/indexed_db_constants.h"
22 #include "content/public/child/worker_thread.h" 22 #include "content/public/child/worker_thread.h"
23 #include "ipc/ipc_sync_message_filter.h" 23 #include "ipc/ipc_sync_message_filter.h"
24 #include "third_party/WebKit/public/platform/WebBlobInfo.h" 24 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h " 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h "
26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h"
27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObserver.h" 26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObserver.h"
28 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
29 #include "url/origin.h" 28 #include "url/origin.h"
30 29
31 struct IndexedDBDatabaseMetadata; 30 struct IndexedDBDatabaseMetadata;
32 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; 31 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params;
33 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; 32 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params;
34 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; 33 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params;
35 struct IndexedDBMsg_CallbacksSuccessArray_Params; 34 struct IndexedDBMsg_CallbacksSuccessArray_Params;
36 struct IndexedDBMsg_CallbacksSuccessValue_Params; 35 struct IndexedDBMsg_CallbacksSuccessValue_Params;
(...skipping 26 matching lines...) Expand all
63 ~IndexedDBDispatcher() override; 62 ~IndexedDBDispatcher() override;
64 63
65 // |thread_safe_sender| needs to be passed in because if the call leads to 64 // |thread_safe_sender| needs to be passed in because if the call leads to
66 // construction it will be needed. 65 // construction it will be needed.
67 static IndexedDBDispatcher* ThreadSpecificInstance( 66 static IndexedDBDispatcher* ThreadSpecificInstance(
68 ThreadSafeSender* thread_safe_sender); 67 ThreadSafeSender* thread_safe_sender);
69 68
70 // WorkerThread::Observer implementation. 69 // WorkerThread::Observer implementation.
71 void WillStopCurrentWorkerThread() override; 70 void WillStopCurrentWorkerThread() override;
72 71
73 static blink::WebIDBMetadata ConvertMetadata(
74 const IndexedDBDatabaseMetadata& idb_metadata);
75 static std::vector<blink::WebIDBObservation> ConvertObservations( 72 static std::vector<blink::WebIDBObservation> ConvertObservations(
76 const std::vector<IndexedDBMsg_Observation>& idb_observation); 73 const std::vector<IndexedDBMsg_Observation>& idb_observation);
77 74
78 void OnMessageReceived(const IPC::Message& msg); 75 void OnMessageReceived(const IPC::Message& msg);
79 76
80 // This method is virtual so it can be overridden in unit tests. 77 // This method is virtual so it can be overridden in unit tests.
81 virtual bool Send(IPC::Message* msg); 78 virtual bool Send(IPC::Message* msg);
82 79
83 int32_t AddIDBObserver(int32_t ipc_database_id, 80 int32_t AddIDBObserver(int32_t ipc_database_id,
84 int64_t transaction_id, 81 int64_t transaction_id,
85 std::unique_ptr<blink::WebIDBObserver> observer); 82 std::unique_ptr<blink::WebIDBObserver> observer);
86 83
87 // The observer with ID's in |observer_ids_to_remove| observe the 84 // The observer with ID's in |observer_ids_to_remove| observe the
88 // |ipc_database_id|. 85 // |ipc_database_id|.
89 // We remove our local references to these observer objects, and send an IPC 86 // We remove our local references to these observer objects, and send an IPC
90 // to clean up the observers from the backend. 87 // to clean up the observers from the backend.
91 void RemoveIDBObserversFromDatabase( 88 void RemoveIDBObserversFromDatabase(
92 int32_t ipc_database_id, 89 int32_t ipc_database_id,
93 const std::vector<int32_t>& observer_ids_to_remove); 90 const std::vector<int32_t>& observer_ids_to_remove);
94 91
95 // Removes observers from our local map observers_ . No IPC message generated. 92 // Removes observers from our local map observers_ . No IPC message generated.
96 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove); 93 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove);
97 94
98 void RequestIDBFactoryGetDatabaseNames(blink::WebIDBCallbacks* callbacks,
99 const url::Origin& origin);
100
101 void RequestIDBFactoryOpen(const base::string16& name,
102 int64_t version,
103 int64_t transaction_id,
104 blink::WebIDBCallbacks* callbacks,
105 blink::WebIDBDatabaseCallbacks* database_callbacks,
106 const url::Origin& origin);
107
108 void RequestIDBFactoryDeleteDatabase(const base::string16& name,
109 blink::WebIDBCallbacks* callbacks,
110 const url::Origin& origin);
111
112 // This method is virtual so it can be overridden in unit tests. 95 // This method is virtual so it can be overridden in unit tests.
113 virtual void RequestIDBCursorAdvance(unsigned long count, 96 virtual void RequestIDBCursorAdvance(unsigned long count,
114 blink::WebIDBCallbacks* callbacks_ptr, 97 blink::WebIDBCallbacks* callbacks_ptr,
115 int32_t ipc_cursor_id, 98 int32_t ipc_cursor_id,
116 int64_t transaction_id); 99 int64_t transaction_id);
117 100
118 // This method is virtual so it can be overridden in unit tests. 101 // This method is virtual so it can be overridden in unit tests.
119 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, 102 virtual void RequestIDBCursorContinue(const IndexedDBKey& key,
120 const IndexedDBKey& primary_key, 103 const IndexedDBKey& primary_key,
121 blink::WebIDBCallbacks* callbacks_ptr, 104 blink::WebIDBCallbacks* callbacks_ptr,
122 int32_t ipc_cursor_id, 105 int32_t ipc_cursor_id,
123 int64_t transaction_id); 106 int64_t transaction_id);
124 107
125 // This method is virtual so it can be overridden in unit tests. 108 // This method is virtual so it can be overridden in unit tests.
126 virtual void RequestIDBCursorPrefetch(int n, 109 virtual void RequestIDBCursorPrefetch(int n,
127 blink::WebIDBCallbacks* callbacks_ptr, 110 blink::WebIDBCallbacks* callbacks_ptr,
128 int32_t ipc_cursor_id); 111 int32_t ipc_cursor_id);
129 112
130 // This method is virtual so it can be overridden in unit tests. 113 // This method is virtual so it can be overridden in unit tests.
131 virtual void RequestIDBCursorPrefetchReset(int used_prefetches, 114 virtual void RequestIDBCursorPrefetchReset(int used_prefetches,
132 int unused_prefetches, 115 int unused_prefetches,
133 int32_t ipc_cursor_id); 116 int32_t ipc_cursor_id);
134 117
135 void RequestIDBDatabaseClose(int32_t ipc_database_id, 118 void RequestIDBDatabaseClose(int32_t ipc_database_id);
136 int32_t ipc_database_callbacks_id);
137 119
138 void NotifyIDBDatabaseVersionChangeIgnored(int32_t ipc_database_id); 120 void NotifyIDBDatabaseVersionChangeIgnored(int32_t ipc_database_id);
139 121
140 void RequestIDBDatabaseCreateTransaction( 122 void RequestIDBDatabaseCreateTransaction(
141 int32_t ipc_database_id, 123 int32_t ipc_database_id,
142 int64_t transaction_id, 124 int64_t transaction_id,
143 blink::WebVector<long long> object_store_ids, 125 blink::WebVector<long long> object_store_ids,
144 blink::WebIDBTransactionMode mode); 126 blink::WebIDBTransactionMode mode);
145 127
146 void RequestIDBDatabaseGet(int32_t ipc_database_id, 128 void RequestIDBDatabaseGet(int32_t ipc_database_id,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 const IndexedDBKeyRange& key_range, 177 const IndexedDBKeyRange& key_range,
196 blink::WebIDBCallbacks* callbacks); 178 blink::WebIDBCallbacks* callbacks);
197 179
198 void RequestIDBDatabaseClear(int32_t ipc_database_id, 180 void RequestIDBDatabaseClear(int32_t ipc_database_id,
199 int64_t transaction_id, 181 int64_t transaction_id,
200 int64_t object_store_id, 182 int64_t object_store_id,
201 blink::WebIDBCallbacks* callbacks); 183 blink::WebIDBCallbacks* callbacks);
202 184
203 virtual void CursorDestroyed(int32_t ipc_cursor_id); 185 virtual void CursorDestroyed(int32_t ipc_cursor_id);
204 void DatabaseDestroyed(int32_t ipc_database_id); 186 void DatabaseDestroyed(int32_t ipc_database_id);
187 blink::WebIDBDatabase* RegisterDatabase(int32_t ipc_database_id);
205 188
206 private: 189 private:
207 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); 190 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset);
208 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); 191 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId);
209 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); 192 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest);
210 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, KeyAndValueSizeTest); 193 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, KeyAndValueSizeTest);
211 194
212 enum { kAllCursors = -1 }; 195 enum { kAllCursors = -1 };
213 196
214 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } 197 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); }
215 198
216 template <typename T> 199 template <typename T>
217 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { 200 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) {
218 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); 201 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr);
219 params->ipc_thread_id = CurrentWorkerId(); 202 params->ipc_thread_id = CurrentWorkerId();
220 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); 203 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
221 } 204 }
222 205
223 // IDBCallback message handlers. 206 // IDBCallback message handlers.
224 void OnSuccessIDBDatabase(int32_t ipc_thread_id,
225 int32_t ipc_callbacks_id,
226 int32_t ipc_database_callbacks_id,
227 int32_t ipc_object_id,
228 const IndexedDBDatabaseMetadata& idb_metadata);
229 void OnSuccessIndexedDBKey(int32_t ipc_thread_id, 207 void OnSuccessIndexedDBKey(int32_t ipc_thread_id,
230 int32_t ipc_callbacks_id, 208 int32_t ipc_callbacks_id,
231 const IndexedDBKey& key); 209 const IndexedDBKey& key);
232 210
233 void OnSuccessOpenCursor( 211 void OnSuccessOpenCursor(
234 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); 212 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p);
235 void OnSuccessCursorContinue( 213 void OnSuccessCursorContinue(
236 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); 214 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p);
237 void OnSuccessCursorPrefetch( 215 void OnSuccessCursorPrefetch(
238 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); 216 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p);
239 void OnSuccessStringList(int32_t ipc_thread_id,
240 int32_t ipc_callbacks_id,
241 const std::vector<base::string16>& value);
242 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p); 217 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p);
243 void OnSuccessArray(const IndexedDBMsg_CallbacksSuccessArray_Params& p); 218 void OnSuccessArray(const IndexedDBMsg_CallbacksSuccessArray_Params& p);
244 void OnSuccessInteger(int32_t ipc_thread_id, 219 void OnSuccessInteger(int32_t ipc_thread_id,
245 int32_t ipc_callbacks_id, 220 int32_t ipc_callbacks_id,
246 int64_t value); 221 int64_t value);
247 void OnSuccessUndefined(int32_t ipc_thread_id, int32_t ipc_callbacks_id); 222 void OnSuccessUndefined(int32_t ipc_thread_id, int32_t ipc_callbacks_id);
248 void OnError(int32_t ipc_thread_id, 223 void OnError(int32_t ipc_thread_id,
249 int32_t ipc_callbacks_id, 224 int32_t ipc_callbacks_id,
250 int code, 225 int code,
251 const base::string16& message); 226 const base::string16& message);
252 void OnIntBlocked(int32_t ipc_thread_id,
253 int32_t ipc_callbacks_id,
254 int64_t existing_version);
255 void OnUpgradeNeeded(const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p);
256 void OnAbort(int32_t ipc_thread_id,
257 int32_t ipc_database_id,
258 int64_t transaction_id,
259 int code,
260 const base::string16& message);
261 void OnComplete(int32_t ipc_thread_id,
262 int32_t ipc_database_id,
263 int64_t transaction_id);
264 void OnDatabaseChanges(int32_t ipc_thread_id, 227 void OnDatabaseChanges(int32_t ipc_thread_id,
265 int32_t ipc_database_id, 228 int32_t ipc_database_id,
266 const IndexedDBMsg_ObserverChanges&); 229 const IndexedDBMsg_ObserverChanges&);
267 230
268 void OnForcedClose(int32_t ipc_thread_id, int32_t ipc_database_id);
269 void OnVersionChange(int32_t ipc_thread_id,
270 int32_t ipc_database_id,
271 int64_t old_version,
272 int64_t new_version);
273
274 // Reset cursor prefetch caches for all cursors except exception_cursor_id. 231 // Reset cursor prefetch caches for all cursors except exception_cursor_id.
275 void ResetCursorPrefetchCaches(int64_t transaction_id, 232 void ResetCursorPrefetchCaches(int64_t transaction_id,
276 int32_t ipc_exception_cursor_id); 233 int32_t ipc_exception_cursor_id);
277 234
278 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 235 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
279 236
280 // Maximum size (in bytes) of value/key pair allowed for put requests. Any 237 // Maximum size (in bytes) of value/key pair allowed for put requests. Any
281 // requests larger than this size will be rejected. 238 // requests larger than this size will be rejected.
282 // Used by unit tests to exercise behavior without allocating huge chunks 239 // Used by unit tests to exercise behavior without allocating huge chunks
283 // of memory. 240 // of memory.
284 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; 241 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes;
285 242
286 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be 243 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
287 // destroyed and used on the same thread it was created on. 244 // destroyed and used on the same thread it was created on.
288 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; 245 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_;
289 IDMap<blink::WebIDBDatabaseCallbacks, IDMapOwnPointer>
290 pending_database_callbacks_;
291 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; 246 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_;
292 247
293 // Maps the ipc_callback_id from an open cursor request to the request's 248 // Maps the ipc_callback_id from an open cursor request to the request's
294 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl 249 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl
295 // when it is created. 250 // when it is created.
296 std::map<int32_t, int64_t> cursor_transaction_ids_; 251 std::map<int32_t, int64_t> cursor_transaction_ids_;
297 252
298 // Map from cursor id to WebIDBCursorImpl. 253 // Map from cursor id to WebIDBCursorImpl.
299 std::map<int32_t, WebIDBCursorImpl*> cursors_; 254 std::map<int32_t, WebIDBCursorImpl*> cursors_;
300 255
301 std::map<int32_t, WebIDBDatabaseImpl*> databases_; 256 std::map<int32_t, WebIDBDatabaseImpl*> databases_;
302 257
303 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 258 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
304 }; 259 };
305 260
306 } // namespace content 261 } // namespace content
307 262
308 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 263 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698