OLD | NEW |
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 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void WillStopCurrentWorkerThread() override; | 69 void WillStopCurrentWorkerThread() override; |
70 | 70 |
71 static std::vector<blink::WebIDBObservation> ConvertObservations( | 71 static std::vector<blink::WebIDBObservation> ConvertObservations( |
72 const std::vector<IndexedDBMsg_Observation>& idb_observation); | 72 const std::vector<IndexedDBMsg_Observation>& idb_observation); |
73 | 73 |
74 void OnMessageReceived(const IPC::Message& msg); | 74 void OnMessageReceived(const IPC::Message& msg); |
75 | 75 |
76 // This method is virtual so it can be overridden in unit tests. | 76 // This method is virtual so it can be overridden in unit tests. |
77 virtual bool Send(IPC::Message* msg); | 77 virtual bool Send(IPC::Message* msg); |
78 | 78 |
79 int32_t AddIDBObserver(int32_t ipc_database_id, | 79 int32_t RegisterObserver(std::unique_ptr<blink::WebIDBObserver> observer); |
80 int64_t transaction_id, | |
81 std::unique_ptr<blink::WebIDBObserver> observer); | |
82 | 80 |
83 // The observer with ID's in |observer_ids_to_remove| observe the | 81 // Removes observers from our local map observers_. |
84 // |ipc_database_id|. | 82 void RemoveObservers(const std::vector<int32_t>& observer_ids_to_remove); |
85 // We remove our local references to these observer objects, and send an IPC | |
86 // to clean up the observers from the backend. | |
87 void RemoveIDBObserversFromDatabase( | |
88 int32_t ipc_database_id, | |
89 const std::vector<int32_t>& observer_ids_to_remove); | |
90 | |
91 // Removes observers from our local map observers_ . No IPC message generated. | |
92 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove); | |
93 | 83 |
94 // This method is virtual so it can be overridden in unit tests. | 84 // This method is virtual so it can be overridden in unit tests. |
95 virtual void RequestIDBCursorAdvance(unsigned long count, | 85 virtual void RequestIDBCursorAdvance(unsigned long count, |
96 blink::WebIDBCallbacks* callbacks_ptr, | 86 blink::WebIDBCallbacks* callbacks_ptr, |
97 int32_t ipc_cursor_id, | 87 int32_t ipc_cursor_id, |
98 int64_t transaction_id); | 88 int64_t transaction_id); |
99 | 89 |
100 // This method is virtual so it can be overridden in unit tests. | 90 // This method is virtual so it can be overridden in unit tests. |
101 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, | 91 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, |
102 const IndexedDBKey& primary_key, | 92 const IndexedDBKey& primary_key, |
103 blink::WebIDBCallbacks* callbacks_ptr, | 93 blink::WebIDBCallbacks* callbacks_ptr, |
104 int32_t ipc_cursor_id, | 94 int32_t ipc_cursor_id, |
105 int64_t transaction_id); | 95 int64_t transaction_id); |
106 | 96 |
107 // This method is virtual so it can be overridden in unit tests. | 97 // This method is virtual so it can be overridden in unit tests. |
108 virtual void RequestIDBCursorPrefetch(int n, | 98 virtual void RequestIDBCursorPrefetch(int n, |
109 blink::WebIDBCallbacks* callbacks_ptr, | 99 blink::WebIDBCallbacks* callbacks_ptr, |
110 int32_t ipc_cursor_id); | 100 int32_t ipc_cursor_id); |
111 | 101 |
112 // This method is virtual so it can be overridden in unit tests. | 102 // This method is virtual so it can be overridden in unit tests. |
113 virtual void RequestIDBCursorPrefetchReset(int used_prefetches, | 103 virtual void RequestIDBCursorPrefetchReset(int used_prefetches, |
114 int unused_prefetches, | 104 int unused_prefetches, |
115 int32_t ipc_cursor_id); | 105 int32_t ipc_cursor_id); |
116 | 106 |
117 void RequestIDBDatabaseClose(int32_t ipc_database_id); | 107 void RegisterCursor(int32_t ipc_cursor_id, WebIDBCursorImpl* cursor); |
118 | |
119 void NotifyIDBDatabaseVersionChangeIgnored(int32_t ipc_database_id); | |
120 | |
121 void RequestIDBDatabaseCreateTransaction( | |
122 int32_t ipc_database_id, | |
123 int64_t transaction_id, | |
124 blink::WebVector<long long> object_store_ids, | |
125 blink::WebIDBTransactionMode mode); | |
126 | |
127 void RequestIDBDatabaseGet(int32_t ipc_database_id, | |
128 int64_t transaction_id, | |
129 int64_t object_store_id, | |
130 int64_t index_id, | |
131 const IndexedDBKeyRange& key_range, | |
132 bool key_only, | |
133 blink::WebIDBCallbacks* callbacks); | |
134 | |
135 void RequestIDBDatabaseGetAll(int32_t ipc_database_id, | |
136 int64_t transaction_id, | |
137 int64_t object_store_id, | |
138 int64_t index_id, | |
139 const IndexedDBKeyRange& key_range, | |
140 bool key_only, | |
141 int64_t max_count, | |
142 blink::WebIDBCallbacks* callbacks); | |
143 | |
144 void RequestIDBDatabasePut( | |
145 int32_t ipc_database_id, | |
146 int64_t transaction_id, | |
147 int64_t object_store_id, | |
148 const blink::WebData& value, | |
149 const blink::WebVector<blink::WebBlobInfo>& web_blob_info, | |
150 const IndexedDBKey& key, | |
151 blink::WebIDBPutMode put_mode, | |
152 blink::WebIDBCallbacks* callbacks, | |
153 const blink::WebVector<long long>& index_ids, | |
154 const blink::WebVector<blink::WebVector<blink::WebIDBKey>>& index_keys); | |
155 | |
156 void RequestIDBDatabaseOpenCursor(int32_t ipc_database_id, | |
157 int64_t transaction_id, | |
158 int64_t object_store_id, | |
159 int64_t index_id, | |
160 const IndexedDBKeyRange& key_range, | |
161 blink::WebIDBCursorDirection direction, | |
162 bool key_only, | |
163 blink::WebIDBTaskType task_type, | |
164 blink::WebIDBCallbacks* callbacks); | |
165 | |
166 void RequestIDBDatabaseCount(int32_t ipc_database_id, | |
167 int64_t transaction_id, | |
168 int64_t object_store_id, | |
169 int64_t index_id, | |
170 const IndexedDBKeyRange& key_range, | |
171 blink::WebIDBCallbacks* callbacks); | |
172 | |
173 void RequestIDBDatabaseDeleteRange(int32_t ipc_database_id, | |
174 int64_t transaction_id, | |
175 int64_t object_store_id, | |
176 const IndexedDBKeyRange& key_range, | |
177 blink::WebIDBCallbacks* callbacks); | |
178 | |
179 void RequestIDBDatabaseClear(int32_t ipc_database_id, | |
180 int64_t transaction_id, | |
181 int64_t object_store_id, | |
182 blink::WebIDBCallbacks* callbacks); | |
183 | 108 |
184 virtual void CursorDestroyed(int32_t ipc_cursor_id); | 109 virtual void CursorDestroyed(int32_t ipc_cursor_id); |
185 void DatabaseDestroyed(int32_t ipc_database_id); | 110 |
186 blink::WebIDBDatabase* RegisterDatabase(int32_t ipc_database_id); | 111 enum { kAllCursors = -1 }; |
| 112 |
| 113 // Reset cursor prefetch caches for all cursors except exception_cursor_id. |
| 114 void ResetCursorPrefetchCaches(int64_t transaction_id, |
| 115 int32_t ipc_exception_cursor_id); |
187 | 116 |
188 void RegisterMojoOwnedCallbacks( | 117 void RegisterMojoOwnedCallbacks( |
189 IndexedDBCallbacksImpl::InternalState* callback_state); | 118 IndexedDBCallbacksImpl::InternalState* callback_state); |
190 void UnregisterMojoOwnedCallbacks( | 119 void UnregisterMojoOwnedCallbacks( |
191 IndexedDBCallbacksImpl::InternalState* callback_state); | 120 IndexedDBCallbacksImpl::InternalState* callback_state); |
192 void RegisterMojoOwnedDatabaseCallbacks( | 121 void RegisterMojoOwnedDatabaseCallbacks( |
193 blink::WebIDBDatabaseCallbacks* callback_state); | 122 blink::WebIDBDatabaseCallbacks* callback_state); |
194 void UnregisterMojoOwnedDatabaseCallbacks( | 123 void UnregisterMojoOwnedDatabaseCallbacks( |
195 blink::WebIDBDatabaseCallbacks* callback_state); | 124 blink::WebIDBDatabaseCallbacks* callback_state); |
196 | 125 |
197 private: | 126 private: |
198 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); | 127 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); |
199 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); | 128 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); |
200 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); | |
201 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, KeyAndValueSizeTest); | |
202 | |
203 enum { kAllCursors = -1 }; | |
204 | 129 |
205 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } | 130 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } |
206 | 131 |
207 template <typename T> | 132 template <typename T> |
208 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { | 133 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { |
209 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); | 134 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); |
210 params->ipc_thread_id = CurrentWorkerId(); | 135 params->ipc_thread_id = CurrentWorkerId(); |
211 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 136 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
212 } | 137 } |
213 | 138 |
214 // IDBCallback message handlers. | 139 // IDBCallback message handlers. |
215 void OnSuccessIndexedDBKey(int32_t ipc_thread_id, | |
216 int32_t ipc_callbacks_id, | |
217 const IndexedDBKey& key); | |
218 | |
219 void OnSuccessOpenCursor( | |
220 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); | |
221 void OnSuccessCursorContinue( | 140 void OnSuccessCursorContinue( |
222 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); | 141 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); |
223 void OnSuccessCursorPrefetch( | 142 void OnSuccessCursorPrefetch( |
224 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); | 143 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); |
225 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p); | 144 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p); |
226 void OnSuccessArray(const IndexedDBMsg_CallbacksSuccessArray_Params& p); | |
227 void OnSuccessInteger(int32_t ipc_thread_id, | 145 void OnSuccessInteger(int32_t ipc_thread_id, |
228 int32_t ipc_callbacks_id, | 146 int32_t ipc_callbacks_id, |
229 int64_t value); | 147 int64_t value); |
230 void OnSuccessUndefined(int32_t ipc_thread_id, int32_t ipc_callbacks_id); | |
231 void OnError(int32_t ipc_thread_id, | 148 void OnError(int32_t ipc_thread_id, |
232 int32_t ipc_callbacks_id, | 149 int32_t ipc_callbacks_id, |
233 int code, | 150 int code, |
234 const base::string16& message); | 151 const base::string16& message); |
235 void OnDatabaseChanges(int32_t ipc_thread_id, | 152 void OnDatabaseChanges(int32_t ipc_thread_id, |
236 const IndexedDBMsg_ObserverChanges&); | 153 const IndexedDBMsg_ObserverChanges&); |
237 | 154 |
238 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | |
239 void ResetCursorPrefetchCaches(int64_t transaction_id, | |
240 int32_t ipc_exception_cursor_id); | |
241 | |
242 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 155 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
243 | 156 |
244 // Maximum size (in bytes) of value/key pair allowed for put requests. Any | |
245 // requests larger than this size will be rejected. | |
246 // Used by unit tests to exercise behavior without allocating huge chunks | |
247 // of memory. | |
248 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; | |
249 | |
250 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 157 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be |
251 // destroyed and used on the same thread it was created on. | 158 // destroyed and used on the same thread it was created on. |
252 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 159 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; |
253 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; | 160 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; |
254 | 161 |
255 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl | 162 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl |
256 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is | 163 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is |
257 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the | 164 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the |
258 // object will leak because the thread's task runner is no longer executing | 165 // object will leak because the thread's task runner is no longer executing |
259 // tasks. | 166 // tasks. |
260 std::unordered_set<IndexedDBCallbacksImpl::InternalState*> | 167 std::unordered_set<IndexedDBCallbacksImpl::InternalState*> |
261 mojo_owned_callback_state_; | 168 mojo_owned_callback_state_; |
262 std::unordered_set<blink::WebIDBDatabaseCallbacks*> | 169 std::unordered_set<blink::WebIDBDatabaseCallbacks*> |
263 mojo_owned_database_callback_state_; | 170 mojo_owned_database_callback_state_; |
264 | 171 |
265 // Maps the ipc_callback_id from an open cursor request to the request's | 172 // Maps the ipc_callback_id from an open cursor request to the request's |
266 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl | 173 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl |
267 // when it is created. | 174 // when it is created. |
268 std::map<int32_t, int64_t> cursor_transaction_ids_; | 175 std::map<int32_t, int64_t> cursor_transaction_ids_; |
269 | 176 |
270 // Map from cursor id to WebIDBCursorImpl. | 177 // Map from cursor id to WebIDBCursorImpl. |
271 std::map<int32_t, WebIDBCursorImpl*> cursors_; | 178 std::map<int32_t, WebIDBCursorImpl*> cursors_; |
272 | 179 |
273 std::map<int32_t, WebIDBDatabaseImpl*> databases_; | |
274 | |
275 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 180 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
276 }; | 181 }; |
277 | 182 |
278 } // namespace content | 183 } // namespace content |
279 | 184 |
280 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 185 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
OLD | NEW |