| 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 |
| 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" |
| 28 #include "third_party/WebKit/public/platform/modules/indexeddb/indexed_db.mojom.
h" |
| 29 #include "url/origin.h" | 29 #include "url/origin.h" |
| 30 | 30 |
| 31 struct IndexedDBDatabaseMetadata; | 31 struct IndexedDBDatabaseMetadata; |
| 32 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | 32 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; |
| 33 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | 33 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; |
| 34 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | 34 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; |
| 35 struct IndexedDBMsg_CallbacksSuccessArray_Params; | 35 struct IndexedDBMsg_CallbacksSuccessArray_Params; |
| 36 struct IndexedDBMsg_CallbacksSuccessValue_Params; | 36 struct IndexedDBMsg_CallbacksSuccessValue_Params; |
| 37 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; | 37 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; |
| 38 struct IndexedDBMsg_Observation; | 38 struct IndexedDBMsg_Observation; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void RemoveIDBObserversFromDatabase( | 91 void RemoveIDBObserversFromDatabase( |
| 92 int32_t ipc_database_id, | 92 int32_t ipc_database_id, |
| 93 const std::vector<int32_t>& observer_ids_to_remove); | 93 const std::vector<int32_t>& observer_ids_to_remove); |
| 94 | 94 |
| 95 // Removes observers from our local map observers_ . No IPC message generated. | 95 // Removes observers from our local map observers_ . No IPC message generated. |
| 96 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove); | 96 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove); |
| 97 | 97 |
| 98 void RequestIDBFactoryGetDatabaseNames(blink::WebIDBCallbacks* callbacks, | 98 void RequestIDBFactoryGetDatabaseNames(blink::WebIDBCallbacks* callbacks, |
| 99 const url::Origin& origin); | 99 const url::Origin& origin); |
| 100 | 100 |
| 101 void RequestIDBFactoryOpen(const base::string16& name, | 101 void RequestIDBFactoryOpen( |
| 102 int64_t version, | 102 const std::string& name, |
| 103 int64_t transaction_id, | 103 int64_t version, |
| 104 blink::WebIDBCallbacks* callbacks, | 104 int64_t transaction_id, |
| 105 blink::WebIDBDatabaseCallbacks* database_callbacks, | 105 blink::WebIDBCallbacks* callbacks, |
| 106 const url::Origin& origin); | 106 mojo::ScopedInterfaceEndpointHandle* client_interface_endpoint, |
| 107 const url::Origin& origin); |
| 107 | 108 |
| 108 void RequestIDBFactoryDeleteDatabase(const base::string16& name, | 109 void RequestIDBFactoryDeleteDatabase(const base::string16& name, |
| 109 blink::WebIDBCallbacks* callbacks, | 110 blink::WebIDBCallbacks* callbacks, |
| 110 const url::Origin& origin); | 111 const url::Origin& origin); |
| 111 | 112 |
| 112 // 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. |
| 113 virtual void RequestIDBCursorAdvance(unsigned long count, | 114 virtual void RequestIDBCursorAdvance(unsigned long count, |
| 114 blink::WebIDBCallbacks* callbacks_ptr, | 115 blink::WebIDBCallbacks* callbacks_ptr, |
| 115 int32_t ipc_cursor_id, | 116 int32_t ipc_cursor_id, |
| 116 int64_t transaction_id); | 117 int64_t transaction_id); |
| 117 | 118 |
| 118 // This method is virtual so it can be overridden in unit tests. | 119 // This method is virtual so it can be overridden in unit tests. |
| 119 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, | 120 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, |
| 120 const IndexedDBKey& primary_key, | 121 const IndexedDBKey& primary_key, |
| 121 blink::WebIDBCallbacks* callbacks_ptr, | 122 blink::WebIDBCallbacks* callbacks_ptr, |
| 122 int32_t ipc_cursor_id, | 123 int32_t ipc_cursor_id, |
| 123 int64_t transaction_id); | 124 int64_t transaction_id); |
| 124 | 125 |
| 125 // This method is virtual so it can be overridden in unit tests. | 126 // This method is virtual so it can be overridden in unit tests. |
| 126 virtual void RequestIDBCursorPrefetch(int n, | 127 virtual void RequestIDBCursorPrefetch(int n, |
| 127 blink::WebIDBCallbacks* callbacks_ptr, | 128 blink::WebIDBCallbacks* callbacks_ptr, |
| 128 int32_t ipc_cursor_id); | 129 int32_t ipc_cursor_id); |
| 129 | 130 |
| 130 // This method is virtual so it can be overridden in unit tests. | 131 // This method is virtual so it can be overridden in unit tests. |
| 131 virtual void RequestIDBCursorPrefetchReset(int used_prefetches, | 132 virtual void RequestIDBCursorPrefetchReset(int used_prefetches, |
| 132 int unused_prefetches, | 133 int unused_prefetches, |
| 133 int32_t ipc_cursor_id); | 134 int32_t ipc_cursor_id); |
| 134 | 135 |
| 135 void RequestIDBDatabaseClose(int32_t ipc_database_id, | 136 void RequestIDBDatabaseClose(int32_t ipc_database_id); |
| 136 int32_t ipc_database_callbacks_id); | |
| 137 | 137 |
| 138 void NotifyIDBDatabaseVersionChangeIgnored(int32_t ipc_database_id); | 138 void NotifyIDBDatabaseVersionChangeIgnored(int32_t ipc_database_id); |
| 139 | 139 |
| 140 void RequestIDBDatabaseCreateTransaction( | 140 void RequestIDBDatabaseCreateTransaction( |
| 141 int32_t ipc_database_id, | 141 int32_t ipc_database_id, |
| 142 int64_t transaction_id, | 142 int64_t transaction_id, |
| 143 blink::WebIDBDatabaseCallbacks* database_callbacks_ptr, | |
| 144 blink::WebVector<long long> object_store_ids, | 143 blink::WebVector<long long> object_store_ids, |
| 145 blink::WebIDBTransactionMode mode); | 144 blink::WebIDBTransactionMode mode); |
| 146 | 145 |
| 147 void RequestIDBDatabaseGet(int32_t ipc_database_id, | 146 void RequestIDBDatabaseGet(int32_t ipc_database_id, |
| 148 int64_t transaction_id, | 147 int64_t transaction_id, |
| 149 int64_t object_store_id, | 148 int64_t object_store_id, |
| 150 int64_t index_id, | 149 int64_t index_id, |
| 151 const IndexedDBKeyRange& key_range, | 150 const IndexedDBKeyRange& key_range, |
| 152 bool key_only, | 151 bool key_only, |
| 153 blink::WebIDBCallbacks* callbacks); | 152 blink::WebIDBCallbacks* callbacks); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 template <typename T> | 216 template <typename T> |
| 218 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { | 217 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { |
| 219 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); | 218 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); |
| 220 params->ipc_thread_id = CurrentWorkerId(); | 219 params->ipc_thread_id = CurrentWorkerId(); |
| 221 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 220 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
| 222 } | 221 } |
| 223 | 222 |
| 224 // IDBCallback message handlers. | 223 // IDBCallback message handlers. |
| 225 void OnSuccessIDBDatabase(int32_t ipc_thread_id, | 224 void OnSuccessIDBDatabase(int32_t ipc_thread_id, |
| 226 int32_t ipc_callbacks_id, | 225 int32_t ipc_callbacks_id, |
| 227 int32_t ipc_database_callbacks_id, | |
| 228 int32_t ipc_object_id, | 226 int32_t ipc_object_id, |
| 229 const IndexedDBDatabaseMetadata& idb_metadata); | 227 const IndexedDBDatabaseMetadata& idb_metadata); |
| 230 void OnSuccessIndexedDBKey(int32_t ipc_thread_id, | 228 void OnSuccessIndexedDBKey(int32_t ipc_thread_id, |
| 231 int32_t ipc_callbacks_id, | 229 int32_t ipc_callbacks_id, |
| 232 const IndexedDBKey& key); | 230 const IndexedDBKey& key); |
| 233 | 231 |
| 234 void OnSuccessOpenCursor( | 232 void OnSuccessOpenCursor( |
| 235 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); | 233 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); |
| 236 void OnSuccessCursorContinue( | 234 void OnSuccessCursorContinue( |
| 237 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); | 235 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); |
| 238 void OnSuccessCursorPrefetch( | 236 void OnSuccessCursorPrefetch( |
| 239 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); | 237 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); |
| 240 void OnSuccessStringList(int32_t ipc_thread_id, | 238 void OnSuccessStringList(int32_t ipc_thread_id, |
| 241 int32_t ipc_callbacks_id, | 239 int32_t ipc_callbacks_id, |
| 242 const std::vector<base::string16>& value); | 240 const std::vector<base::string16>& value); |
| 243 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p); | 241 void OnSuccessValue(const IndexedDBMsg_CallbacksSuccessValue_Params& p); |
| 244 void OnSuccessArray(const IndexedDBMsg_CallbacksSuccessArray_Params& p); | 242 void OnSuccessArray(const IndexedDBMsg_CallbacksSuccessArray_Params& p); |
| 245 void OnSuccessInteger(int32_t ipc_thread_id, | 243 void OnSuccessInteger(int32_t ipc_thread_id, |
| 246 int32_t ipc_callbacks_id, | 244 int32_t ipc_callbacks_id, |
| 247 int64_t value); | 245 int64_t value); |
| 248 void OnSuccessUndefined(int32_t ipc_thread_id, int32_t ipc_callbacks_id); | 246 void OnSuccessUndefined(int32_t ipc_thread_id, int32_t ipc_callbacks_id); |
| 249 void OnError(int32_t ipc_thread_id, | 247 void OnError(int32_t ipc_thread_id, |
| 250 int32_t ipc_callbacks_id, | 248 int32_t ipc_callbacks_id, |
| 251 int code, | 249 int code, |
| 252 const base::string16& message); | 250 const base::string16& message); |
| 253 void OnIntBlocked(int32_t ipc_thread_id, | 251 void OnIntBlocked(int32_t ipc_thread_id, |
| 254 int32_t ipc_callbacks_id, | 252 int32_t ipc_callbacks_id, |
| 255 int64_t existing_version); | 253 int64_t existing_version); |
| 256 void OnUpgradeNeeded(const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p); | 254 void OnUpgradeNeeded(const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p); |
| 257 void OnAbort(int32_t ipc_thread_id, | |
| 258 int32_t ipc_database_id, | |
| 259 int64_t transaction_id, | |
| 260 int code, | |
| 261 const base::string16& message); | |
| 262 void OnComplete(int32_t ipc_thread_id, | |
| 263 int32_t ipc_database_id, | |
| 264 int64_t transaction_id); | |
| 265 void OnDatabaseChanges(int32_t ipc_thread_id, | 255 void OnDatabaseChanges(int32_t ipc_thread_id, |
| 266 int32_t ipc_database_id, | 256 int32_t ipc_database_id, |
| 267 const IndexedDBMsg_ObserverChanges&); | 257 const IndexedDBMsg_ObserverChanges&); |
| 268 | 258 |
| 269 void OnForcedClose(int32_t ipc_thread_id, int32_t ipc_database_id); | |
| 270 void OnVersionChange(int32_t ipc_thread_id, | |
| 271 int32_t ipc_database_id, | |
| 272 int64_t old_version, | |
| 273 int64_t new_version); | |
| 274 | |
| 275 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | 259 // Reset cursor prefetch caches for all cursors except exception_cursor_id. |
| 276 void ResetCursorPrefetchCaches(int64_t transaction_id, | 260 void ResetCursorPrefetchCaches(int64_t transaction_id, |
| 277 int32_t ipc_exception_cursor_id); | 261 int32_t ipc_exception_cursor_id); |
| 278 | 262 |
| 263 indexed_db::mojom::DatabaseFactoryAssociatedPtr database_factory_; |
| 279 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 264 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 280 | 265 |
| 281 // Maximum size (in bytes) of value/key pair allowed for put requests. Any | 266 // Maximum size (in bytes) of value/key pair allowed for put requests. Any |
| 282 // requests larger than this size will be rejected. | 267 // requests larger than this size will be rejected. |
| 283 // Used by unit tests to exercise behavior without allocating huge chunks | 268 // Used by unit tests to exercise behavior without allocating huge chunks |
| 284 // of memory. | 269 // of memory. |
| 285 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; | 270 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; |
| 286 | 271 |
| 287 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 272 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be |
| 288 // destroyed and used on the same thread it was created on. | 273 // destroyed and used on the same thread it was created on. |
| 289 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 274 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; |
| 290 IDMap<blink::WebIDBDatabaseCallbacks, IDMapOwnPointer> | |
| 291 pending_database_callbacks_; | |
| 292 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; | 275 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; |
| 293 | 276 |
| 294 // Maps the ipc_callback_id from an open cursor request to the request's | 277 // Maps the ipc_callback_id from an open cursor request to the request's |
| 295 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl | 278 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl |
| 296 // when it is created. | 279 // when it is created. |
| 297 std::map<int32_t, int64_t> cursor_transaction_ids_; | 280 std::map<int32_t, int64_t> cursor_transaction_ids_; |
| 298 | 281 |
| 299 // Map from cursor id to WebIDBCursorImpl. | 282 // Map from cursor id to WebIDBCursorImpl. |
| 300 std::map<int32_t, WebIDBCursorImpl*> cursors_; | 283 std::map<int32_t, WebIDBCursorImpl*> cursors_; |
| 301 | 284 |
| 302 std::map<int32_t, WebIDBDatabaseImpl*> databases_; | 285 std::map<int32_t, WebIDBDatabaseImpl*> databases_; |
| 303 | 286 |
| 304 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 287 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
| 305 }; | 288 }; |
| 306 | 289 |
| 307 } // namespace content | 290 } // namespace content |
| 308 | 291 |
| 309 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 292 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
| OLD | NEW |