| 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 <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/strings/nullable_string16.h" | 14 #include "base/strings/nullable_string16.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "ipc/ipc_sync_message_filter.h" | 16 #include "ipc/ipc_sync_message_filter.h" |
| 17 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | 17 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" |
| 18 #include "third_party/WebKit/public/platform/WebIDBCursor.h" | 18 #include "third_party/WebKit/public/platform/WebIDBCursor.h" |
| 19 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 19 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
| 20 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" | 20 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" |
| 21 #include "webkit/child/worker_task_runner.h" | 21 #include "webkit/child/worker_task_runner.h" |
| 22 | 22 |
| 23 struct IndexedDBDatabaseMetadata; | 23 struct IndexedDBDatabaseMetadata; |
| 24 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | 24 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; |
| 25 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | 25 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; |
| 26 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | 26 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; |
| 27 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; | 27 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; |
| 28 | 28 |
| 29 namespace WebKit { | 29 namespace blink { |
| 30 class WebData; | 30 class WebData; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 class IndexedDBKey; | 34 class IndexedDBKey; |
| 35 class IndexedDBKeyPath; | 35 class IndexedDBKeyPath; |
| 36 class IndexedDBKeyRange; | 36 class IndexedDBKeyRange; |
| 37 class RendererWebIDBCursorImpl; | 37 class RendererWebIDBCursorImpl; |
| 38 class RendererWebIDBDatabaseImpl; | 38 class RendererWebIDBDatabaseImpl; |
| 39 class ThreadSafeSender; | 39 class ThreadSafeSender; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 virtual ~IndexedDBDispatcher(); | 53 virtual ~IndexedDBDispatcher(); |
| 54 | 54 |
| 55 // |thread_safe_sender| needs to be passed in because if the call leads to | 55 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 56 // construction it will be needed. | 56 // construction it will be needed. |
| 57 static IndexedDBDispatcher* ThreadSpecificInstance( | 57 static IndexedDBDispatcher* ThreadSpecificInstance( |
| 58 ThreadSafeSender* thread_safe_sender); | 58 ThreadSafeSender* thread_safe_sender); |
| 59 | 59 |
| 60 // webkit_glue::WorkerTaskRunner::Observer implementation. | 60 // webkit_glue::WorkerTaskRunner::Observer implementation. |
| 61 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 61 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
| 62 | 62 |
| 63 static WebKit::WebIDBMetadata ConvertMetadata( | 63 static blink::WebIDBMetadata ConvertMetadata( |
| 64 const IndexedDBDatabaseMetadata& idb_metadata); | 64 const IndexedDBDatabaseMetadata& idb_metadata); |
| 65 | 65 |
| 66 void OnMessageReceived(const IPC::Message& msg); | 66 void OnMessageReceived(const IPC::Message& msg); |
| 67 bool Send(IPC::Message* msg); | 67 bool Send(IPC::Message* msg); |
| 68 | 68 |
| 69 void RequestIDBFactoryGetDatabaseNames( | 69 void RequestIDBFactoryGetDatabaseNames( |
| 70 WebKit::WebIDBCallbacks* callbacks, | 70 blink::WebIDBCallbacks* callbacks, |
| 71 const std::string& database_identifier); | 71 const std::string& database_identifier); |
| 72 | 72 |
| 73 void RequestIDBFactoryOpen( | 73 void RequestIDBFactoryOpen( |
| 74 const string16& name, | 74 const string16& name, |
| 75 int64 version, | 75 int64 version, |
| 76 int64 transaction_id, | 76 int64 transaction_id, |
| 77 WebKit::WebIDBCallbacks* callbacks, | 77 blink::WebIDBCallbacks* callbacks, |
| 78 WebKit::WebIDBDatabaseCallbacks* database_callbacks, | 78 blink::WebIDBDatabaseCallbacks* database_callbacks, |
| 79 const std::string& database_identifier); | 79 const std::string& database_identifier); |
| 80 | 80 |
| 81 void RequestIDBFactoryDeleteDatabase(const string16& name, | 81 void RequestIDBFactoryDeleteDatabase(const string16& name, |
| 82 WebKit::WebIDBCallbacks* callbacks, | 82 blink::WebIDBCallbacks* callbacks, |
| 83 const std::string& database_identifier); | 83 const std::string& database_identifier); |
| 84 | 84 |
| 85 void RequestIDBCursorAdvance(unsigned long count, | 85 void RequestIDBCursorAdvance(unsigned long count, |
| 86 WebKit::WebIDBCallbacks* callbacks_ptr, | 86 blink::WebIDBCallbacks* callbacks_ptr, |
| 87 int32 ipc_cursor_id); | 87 int32 ipc_cursor_id); |
| 88 | 88 |
| 89 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, | 89 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, |
| 90 WebKit::WebIDBCallbacks* callbacks_ptr, | 90 blink::WebIDBCallbacks* callbacks_ptr, |
| 91 int32 ipc_cursor_id); | 91 int32 ipc_cursor_id); |
| 92 | 92 |
| 93 virtual void RequestIDBCursorPrefetch(int n, | 93 virtual void RequestIDBCursorPrefetch(int n, |
| 94 WebKit::WebIDBCallbacks* callbacks_ptr, | 94 blink::WebIDBCallbacks* callbacks_ptr, |
| 95 int32 ipc_cursor_id); | 95 int32 ipc_cursor_id); |
| 96 | 96 |
| 97 void RequestIDBCursorPrefetchReset(int used_prefetches, | 97 void RequestIDBCursorPrefetchReset(int used_prefetches, |
| 98 int unused_prefetches, | 98 int unused_prefetches, |
| 99 int32 ipc_cursor_id); | 99 int32 ipc_cursor_id); |
| 100 | 100 |
| 101 void RequestIDBDatabaseClose(int32 ipc_database_id, | 101 void RequestIDBDatabaseClose(int32 ipc_database_id, |
| 102 int32 ipc_database_callbacks_id); | 102 int32 ipc_database_callbacks_id); |
| 103 | 103 |
| 104 void RequestIDBDatabaseCreateTransaction( | 104 void RequestIDBDatabaseCreateTransaction( |
| 105 int32 ipc_database_id, | 105 int32 ipc_database_id, |
| 106 int64 transaction_id, | 106 int64 transaction_id, |
| 107 WebKit::WebIDBDatabaseCallbacks* database_callbacks_ptr, | 107 blink::WebIDBDatabaseCallbacks* database_callbacks_ptr, |
| 108 WebKit::WebVector<long long> object_store_ids, | 108 blink::WebVector<long long> object_store_ids, |
| 109 unsigned short mode); | 109 unsigned short mode); |
| 110 | 110 |
| 111 void RequestIDBDatabaseGet(int32 ipc_database_id, | 111 void RequestIDBDatabaseGet(int32 ipc_database_id, |
| 112 int64 transaction_id, | 112 int64 transaction_id, |
| 113 int64 object_store_id, | 113 int64 object_store_id, |
| 114 int64 index_id, | 114 int64 index_id, |
| 115 const IndexedDBKeyRange& key_range, | 115 const IndexedDBKeyRange& key_range, |
| 116 bool key_only, | 116 bool key_only, |
| 117 WebKit::WebIDBCallbacks* callbacks); | 117 blink::WebIDBCallbacks* callbacks); |
| 118 | 118 |
| 119 void RequestIDBDatabasePut( | 119 void RequestIDBDatabasePut( |
| 120 int32 ipc_database_id, | 120 int32 ipc_database_id, |
| 121 int64 transaction_id, | 121 int64 transaction_id, |
| 122 int64 object_store_id, | 122 int64 object_store_id, |
| 123 const WebKit::WebData& value, | 123 const blink::WebData& value, |
| 124 const IndexedDBKey& key, | 124 const IndexedDBKey& key, |
| 125 WebKit::WebIDBDatabase::PutMode put_mode, | 125 blink::WebIDBDatabase::PutMode put_mode, |
| 126 WebKit::WebIDBCallbacks* callbacks, | 126 blink::WebIDBCallbacks* callbacks, |
| 127 const WebKit::WebVector<long long>& index_ids, | 127 const blink::WebVector<long long>& index_ids, |
| 128 const WebKit::WebVector<WebKit::WebVector<WebKit::WebIDBKey> >& | 128 const blink::WebVector<blink::WebVector<blink::WebIDBKey> >& |
| 129 index_keys); | 129 index_keys); |
| 130 | 130 |
| 131 void RequestIDBDatabaseOpenCursor(int32 ipc_database_id, | 131 void RequestIDBDatabaseOpenCursor(int32 ipc_database_id, |
| 132 int64 transaction_id, | 132 int64 transaction_id, |
| 133 int64 object_store_id, | 133 int64 object_store_id, |
| 134 int64 index_id, | 134 int64 index_id, |
| 135 const IndexedDBKeyRange& key_range, | 135 const IndexedDBKeyRange& key_range, |
| 136 unsigned short direction, | 136 unsigned short direction, |
| 137 bool key_only, | 137 bool key_only, |
| 138 WebKit::WebIDBDatabase::TaskType task_type, | 138 blink::WebIDBDatabase::TaskType task_type, |
| 139 WebKit::WebIDBCallbacks* callbacks); | 139 blink::WebIDBCallbacks* callbacks); |
| 140 | 140 |
| 141 void RequestIDBDatabaseCount(int32 ipc_database_id, | 141 void RequestIDBDatabaseCount(int32 ipc_database_id, |
| 142 int64 transaction_id, | 142 int64 transaction_id, |
| 143 int64 object_store_id, | 143 int64 object_store_id, |
| 144 int64 index_id, | 144 int64 index_id, |
| 145 const IndexedDBKeyRange& key_range, | 145 const IndexedDBKeyRange& key_range, |
| 146 WebKit::WebIDBCallbacks* callbacks); | 146 blink::WebIDBCallbacks* callbacks); |
| 147 | 147 |
| 148 void RequestIDBDatabaseDeleteRange(int32 ipc_database_id, | 148 void RequestIDBDatabaseDeleteRange(int32 ipc_database_id, |
| 149 int64 transaction_id, | 149 int64 transaction_id, |
| 150 int64 object_store_id, | 150 int64 object_store_id, |
| 151 const IndexedDBKeyRange& key_range, | 151 const IndexedDBKeyRange& key_range, |
| 152 WebKit::WebIDBCallbacks* callbacks); | 152 blink::WebIDBCallbacks* callbacks); |
| 153 | 153 |
| 154 void RequestIDBDatabaseClear(int32 ipc_database_id, | 154 void RequestIDBDatabaseClear(int32 ipc_database_id, |
| 155 int64 transaction_id, | 155 int64 transaction_id, |
| 156 int64 object_store_id, | 156 int64 object_store_id, |
| 157 WebKit::WebIDBCallbacks* callbacks); | 157 blink::WebIDBCallbacks* callbacks); |
| 158 | 158 |
| 159 virtual void CursorDestroyed(int32 ipc_cursor_id); | 159 virtual void CursorDestroyed(int32 ipc_cursor_id); |
| 160 void DatabaseDestroyed(int32 ipc_database_id); | 160 void DatabaseDestroyed(int32 ipc_database_id); |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); | 163 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); |
| 164 | 164 |
| 165 static int32 CurrentWorkerId() { | 165 static int32 CurrentWorkerId() { |
| 166 return webkit_glue::WorkerTaskRunner::Instance()->CurrentWorkerId(); | 166 return webkit_glue::WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 template <typename T> | 169 template <typename T> |
| 170 void init_params(T& params, WebKit::WebIDBCallbacks* callbacks_ptr) { | 170 void init_params(T& params, blink::WebIDBCallbacks* callbacks_ptr) { |
| 171 scoped_ptr<WebKit::WebIDBCallbacks> callbacks(callbacks_ptr); | 171 scoped_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); |
| 172 params.ipc_thread_id = CurrentWorkerId(); | 172 params.ipc_thread_id = CurrentWorkerId(); |
| 173 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | 173 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // IDBCallback message handlers. | 176 // IDBCallback message handlers. |
| 177 void OnSuccessIDBDatabase(int32 ipc_thread_id, | 177 void OnSuccessIDBDatabase(int32 ipc_thread_id, |
| 178 int32 ipc_callbacks_id, | 178 int32 ipc_callbacks_id, |
| 179 int32 ipc_database_callbacks_id, | 179 int32 ipc_database_callbacks_id, |
| 180 int32 ipc_object_id, | 180 int32 ipc_object_id, |
| 181 const IndexedDBDatabaseMetadata& idb_metadata); | 181 const IndexedDBDatabaseMetadata& idb_metadata); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 int64 old_version, | 226 int64 old_version, |
| 227 int64 new_version); | 227 int64 new_version); |
| 228 | 228 |
| 229 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | 229 // Reset cursor prefetch caches for all cursors except exception_cursor_id. |
| 230 void ResetCursorPrefetchCaches(int32 ipc_exception_cursor_id = -1); | 230 void ResetCursorPrefetchCaches(int32 ipc_exception_cursor_id = -1); |
| 231 | 231 |
| 232 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 232 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 233 | 233 |
| 234 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | 234 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be |
| 235 // destroyed and used on the same thread it was created on. | 235 // destroyed and used on the same thread it was created on. |
| 236 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | 236 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; |
| 237 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | 237 IDMap<blink::WebIDBDatabaseCallbacks, IDMapOwnPointer> |
| 238 pending_database_callbacks_; | 238 pending_database_callbacks_; |
| 239 | 239 |
| 240 // Map from cursor id to RendererWebIDBCursorImpl. | 240 // Map from cursor id to RendererWebIDBCursorImpl. |
| 241 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | 241 std::map<int32, RendererWebIDBCursorImpl*> cursors_; |
| 242 | 242 |
| 243 std::map<int32, RendererWebIDBDatabaseImpl*> databases_; | 243 std::map<int32, RendererWebIDBDatabaseImpl*> databases_; |
| 244 | 244 |
| 245 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | 245 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 } // namespace content | 248 } // namespace content |
| 249 | 249 |
| 250 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | 250 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ |
| OLD | NEW |