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