| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
| 6 #define CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/id_map.h" | |
| 13 #include "base/nullable_string16.h" | |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h" | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac
ks.h" | |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h" | |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCall
backs.h" | |
| 20 #include "webkit/glue/worker_task_runner.h" | |
| 21 | |
| 22 class IndexedDBKey; | |
| 23 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | |
| 24 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | |
| 25 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | |
| 26 class RendererWebIDBCursorImpl; | |
| 27 | |
| 28 namespace IPC { | |
| 29 class Message; | |
| 30 } | |
| 31 | |
| 32 namespace WebKit { | |
| 33 class WebFrame; | |
| 34 class WebIDBKeyRange; | |
| 35 class WebIDBTransaction; | |
| 36 } | |
| 37 | |
| 38 namespace content { | |
| 39 class SerializedScriptValue; | |
| 40 } | |
| 41 | |
| 42 // Handle the indexed db related communication for this context thread - the | |
| 43 // main thread and each worker thread have their own copies. | |
| 44 class IndexedDBDispatcher : public webkit_glue::WorkerTaskRunner::Observer { | |
| 45 public: | |
| 46 virtual ~IndexedDBDispatcher(); | |
| 47 static IndexedDBDispatcher* ThreadSpecificInstance(); | |
| 48 | |
| 49 // webkit_glue::WorkerTaskRunner::Observer implementation. | |
| 50 virtual void OnWorkerRunLoopStopped() OVERRIDE; | |
| 51 | |
| 52 void OnMessageReceived(const IPC::Message& msg); | |
| 53 void Send(IPC::Message* msg); | |
| 54 | |
| 55 void RequestIDBFactoryGetDatabaseNames( | |
| 56 WebKit::WebIDBCallbacks* callbacks, | |
| 57 const string16& origin, | |
| 58 WebKit::WebFrame* web_frame); | |
| 59 | |
| 60 void RequestIDBFactoryOpen( | |
| 61 const string16& name, | |
| 62 WebKit::WebIDBCallbacks* callbacks, | |
| 63 const string16& origin, | |
| 64 WebKit::WebFrame* web_frame); | |
| 65 | |
| 66 void RequestIDBFactoryDeleteDatabase( | |
| 67 const string16& name, | |
| 68 WebKit::WebIDBCallbacks* callbacks, | |
| 69 const string16& origin, | |
| 70 WebKit::WebFrame* web_frame); | |
| 71 | |
| 72 void RequestIDBCursorUpdate( | |
| 73 const content::SerializedScriptValue& value, | |
| 74 WebKit::WebIDBCallbacks* callbacks_ptr, | |
| 75 int32 idb_cursor_id, | |
| 76 WebKit::WebExceptionCode* ec); | |
| 77 | |
| 78 void RequestIDBCursorContinue( | |
| 79 const IndexedDBKey& key, | |
| 80 WebKit::WebIDBCallbacks* callbacks_ptr, | |
| 81 int32 idb_cursor_id, | |
| 82 WebKit::WebExceptionCode* ec); | |
| 83 | |
| 84 void RequestIDBCursorPrefetch( | |
| 85 int n, | |
| 86 WebKit::WebIDBCallbacks* callbacks_ptr, | |
| 87 int32 idb_cursor_id, | |
| 88 WebKit::WebExceptionCode* ec); | |
| 89 | |
| 90 void RequestIDBCursorPrefetchReset(int used_prefetches, int unused_prefetches, | |
| 91 int32 idb_cursor_id); | |
| 92 | |
| 93 void RequestIDBCursorDelete( | |
| 94 WebKit::WebIDBCallbacks* callbacks_ptr, | |
| 95 int32 idb_cursor_id, | |
| 96 WebKit::WebExceptionCode* ec); | |
| 97 | |
| 98 void RequestIDBDatabaseClose( | |
| 99 int32 idb_database_id); | |
| 100 | |
| 101 void RequestIDBDatabaseOpen( | |
| 102 WebKit::WebIDBDatabaseCallbacks* callbacks_ptr, | |
| 103 int32 idb_database_id); | |
| 104 | |
| 105 void RequestIDBDatabaseSetVersion( | |
| 106 const string16& version, | |
| 107 WebKit::WebIDBCallbacks* callbacks, | |
| 108 int32 idb_database_id, | |
| 109 WebKit::WebExceptionCode* ec); | |
| 110 | |
| 111 void RequestIDBIndexOpenObjectCursor( | |
| 112 const WebKit::WebIDBKeyRange& idb_key_range, | |
| 113 unsigned short direction, | |
| 114 WebKit::WebIDBCallbacks* callbacks, | |
| 115 int32 idb_index_id, | |
| 116 const WebKit::WebIDBTransaction& transaction, | |
| 117 WebKit::WebExceptionCode* ec); | |
| 118 | |
| 119 void RequestIDBIndexOpenKeyCursor( | |
| 120 const WebKit::WebIDBKeyRange& idb_key_range, | |
| 121 unsigned short direction, | |
| 122 WebKit::WebIDBCallbacks* callbacks, | |
| 123 int32 idb_index_id, | |
| 124 const WebKit::WebIDBTransaction& transaction, | |
| 125 WebKit::WebExceptionCode* ec); | |
| 126 | |
| 127 void RequestIDBIndexCount( | |
| 128 const WebKit::WebIDBKeyRange& idb_key_range, | |
| 129 WebKit::WebIDBCallbacks* callbacks, | |
| 130 int32 idb_index_id, | |
| 131 const WebKit::WebIDBTransaction& transaction, | |
| 132 WebKit::WebExceptionCode* ec); | |
| 133 | |
| 134 void RequestIDBIndexGetObject(const IndexedDBKey& key, | |
| 135 WebKit::WebIDBCallbacks* callbacks, | |
| 136 int32 idb_index_id, | |
| 137 const WebKit::WebIDBTransaction& transaction, | |
| 138 WebKit::WebExceptionCode* ec); | |
| 139 | |
| 140 void RequestIDBIndexGetKey(const IndexedDBKey& key, | |
| 141 WebKit::WebIDBCallbacks* callbacks, | |
| 142 int32 idb_index_id, | |
| 143 const WebKit::WebIDBTransaction& transaction, | |
| 144 WebKit::WebExceptionCode* ec); | |
| 145 | |
| 146 void RequestIDBObjectStoreGet(const IndexedDBKey& key, | |
| 147 WebKit::WebIDBCallbacks* callbacks, | |
| 148 int32 idb_object_store_id, | |
| 149 const WebKit::WebIDBTransaction& transaction, | |
| 150 WebKit::WebExceptionCode* ec); | |
| 151 | |
| 152 void RequestIDBObjectStorePut(const content::SerializedScriptValue& value, | |
| 153 const IndexedDBKey& key, | |
| 154 WebKit::WebIDBObjectStore::PutMode putMode, | |
| 155 WebKit::WebIDBCallbacks* callbacks, | |
| 156 int32 idb_object_store_id, | |
| 157 const WebKit::WebIDBTransaction& transaction, | |
| 158 WebKit::WebExceptionCode* ec); | |
| 159 | |
| 160 void RequestIDBObjectStoreDelete( | |
| 161 const IndexedDBKey& key, | |
| 162 WebKit::WebIDBCallbacks* callbacks, | |
| 163 int32 idb_object_store_id, | |
| 164 const WebKit::WebIDBTransaction& transaction, | |
| 165 WebKit::WebExceptionCode* ec); | |
| 166 | |
| 167 void RequestIDBObjectStoreClear( | |
| 168 WebKit::WebIDBCallbacks* callbacks, | |
| 169 int32 idb_object_store_id, | |
| 170 const WebKit::WebIDBTransaction& transaction, | |
| 171 WebKit::WebExceptionCode* ec); | |
| 172 | |
| 173 void RequestIDBObjectStoreOpenCursor( | |
| 174 const WebKit::WebIDBKeyRange& idb_key_range, | |
| 175 unsigned short direction, | |
| 176 WebKit::WebIDBCallbacks* callbacks, | |
| 177 int32 idb_object_store_id, | |
| 178 const WebKit::WebIDBTransaction& transaction, | |
| 179 WebKit::WebExceptionCode* ec); | |
| 180 | |
| 181 void RequestIDBObjectStoreCount( | |
| 182 const WebKit::WebIDBKeyRange& idb_key_range, | |
| 183 WebKit::WebIDBCallbacks* callbacks, | |
| 184 int32 idb_object_store_id, | |
| 185 const WebKit::WebIDBTransaction& transaction, | |
| 186 WebKit::WebExceptionCode* ec); | |
| 187 | |
| 188 void RegisterWebIDBTransactionCallbacks( | |
| 189 WebKit::WebIDBTransactionCallbacks* callbacks, | |
| 190 int32 id); | |
| 191 | |
| 192 void CursorDestroyed(int32 cursor_id); | |
| 193 | |
| 194 static int32 TransactionId(const WebKit::WebIDBTransaction& transaction); | |
| 195 | |
| 196 private: | |
| 197 IndexedDBDispatcher(); | |
| 198 // IDBCallback message handlers. | |
| 199 void OnSuccessNull(int32 response_id); | |
| 200 void OnSuccessIDBDatabase(int32 thread_id, | |
| 201 int32 response_id, | |
| 202 int32 object_id); | |
| 203 void OnSuccessIndexedDBKey(int32 thread_id, | |
| 204 int32 response_id, | |
| 205 const IndexedDBKey& key); | |
| 206 void OnSuccessIDBTransaction(int32 thread_id, | |
| 207 int32 response_id, | |
| 208 int32 object_id); | |
| 209 void OnSuccessOpenCursor( | |
| 210 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); | |
| 211 void OnSuccessCursorContinue( | |
| 212 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); | |
| 213 void OnSuccessCursorPrefetch( | |
| 214 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); | |
| 215 void OnSuccessStringList(int32 thread_id, | |
| 216 int32 response_id, | |
| 217 const std::vector<string16>& value); | |
| 218 void OnSuccessSerializedScriptValue( | |
| 219 int32 thread_id, | |
| 220 int32 response_id, | |
| 221 const content::SerializedScriptValue& value); | |
| 222 void OnError(int32 thread_id, | |
| 223 int32 response_id, | |
| 224 int code, | |
| 225 const string16& message); | |
| 226 void OnBlocked(int32 thread_id, int32 response_id); | |
| 227 void OnAbort(int32 thread_id, int32 transaction_id); | |
| 228 void OnComplete(int32 thread_id, int32 transaction_id); | |
| 229 void OnVersionChange(int32 thread_id, | |
| 230 int32 database_id, | |
| 231 const string16& newVersion); | |
| 232 | |
| 233 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | |
| 234 void ResetCursorPrefetchCaches(int32 exception_cursor_id = -1); | |
| 235 | |
| 236 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | |
| 237 // destroyed and used on the same thread it was created on. | |
| 238 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | |
| 239 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer> | |
| 240 pending_transaction_callbacks_; | |
| 241 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | |
| 242 pending_database_callbacks_; | |
| 243 | |
| 244 // Map from cursor id to RendererWebIDBCursorImpl. | |
| 245 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | |
| 246 | |
| 247 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | |
| 248 }; | |
| 249 | |
| 250 #endif // CONTENT_RENDERER_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
| OLD | NEW |