[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / common / indexed_db / indexed_db_dispatcher.h
blob07f086562c75e6512e109113cc4eb0a558afaace
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
8 #include <map>
9 #include <vector>
11 #include "base/id_map.h"
12 #include "base/nullable_string16.h"
13 #include "content/common/content_export.h"
14 #include "ipc/ipc_sync_message_filter.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebExceptionCode.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCallbacks.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCursor.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbacks.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCallbacks.h"
23 #include "webkit/glue/worker_task_runner.h"
25 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params;
26 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params;
27 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params;
29 namespace WebKit {
30 class WebFrame;
31 class WebIDBKeyRange;
34 namespace content {
35 class IndexedDBKey;
36 class IndexedDBKeyPath;
37 class IndexedDBKeyRange;
38 class RendererWebIDBCursorImpl;
39 class RendererWebIDBDatabaseImpl;
40 class SerializedScriptValue;
42 CONTENT_EXPORT extern const size_t kMaxIDBValueSizeInBytes;
44 // Handle the indexed db related communication for this context thread - the
45 // main thread and each worker thread have their own copies.
46 class CONTENT_EXPORT IndexedDBDispatcher
47 : public webkit_glue::WorkerTaskRunner::Observer {
48 public:
49 // Constructor made public to allow RenderThreadImpl to own a copy without
50 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate
51 // two copies of RenderThreadImpl on the same thread. Everyone else probably
52 // wants to use ThreadSpecificInstance().
53 IndexedDBDispatcher();
54 virtual ~IndexedDBDispatcher();
55 static IndexedDBDispatcher* ThreadSpecificInstance();
57 // webkit_glue::WorkerTaskRunner::Observer implementation.
58 virtual void OnWorkerRunLoopStopped() OVERRIDE;
60 void OnMessageReceived(const IPC::Message& msg);
61 static bool Send(IPC::Message* msg);
63 void RequestIDBFactoryGetDatabaseNames(
64 WebKit::WebIDBCallbacks* callbacks,
65 const string16& origin,
66 WebKit::WebFrame* web_frame);
68 void RequestIDBFactoryOpen(
69 const string16& name,
70 int64 version,
71 WebKit::WebIDBCallbacks* callbacks,
72 WebKit::WebIDBDatabaseCallbacks* database_callbacks,
73 const string16& origin,
74 WebKit::WebFrame* web_frame);
76 void RequestIDBFactoryOpen(
77 const string16& name,
78 int64 version,
79 int64 transaction_id,
80 WebKit::WebIDBCallbacks* callbacks,
81 WebKit::WebIDBDatabaseCallbacks* database_callbacks,
82 const string16& origin,
83 WebKit::WebFrame* web_frame);
85 void RequestIDBFactoryDeleteDatabase(
86 const string16& name,
87 WebKit::WebIDBCallbacks* callbacks,
88 const string16& origin,
89 WebKit::WebFrame* web_frame);
91 void RequestIDBCursorAdvance(
92 unsigned long count,
93 WebKit::WebIDBCallbacks* callbacks_ptr,
94 int32 ipc_cursor_id,
95 WebKit::WebExceptionCode* ec);
97 void RequestIDBCursorContinue(
98 const IndexedDBKey& key,
99 WebKit::WebIDBCallbacks* callbacks_ptr,
100 int32 ipc_cursor_id,
101 WebKit::WebExceptionCode* ec);
103 void RequestIDBCursorPrefetch(
104 int n,
105 WebKit::WebIDBCallbacks* callbacks_ptr,
106 int32 ipc_cursor_id,
107 WebKit::WebExceptionCode* ec);
109 void RequestIDBCursorPrefetchReset(int used_prefetches, int unused_prefetches,
110 int32 ipc_cursor_id);
112 void RequestIDBCursorDelete(
113 WebKit::WebIDBCallbacks* callbacks_ptr,
114 int32 ipc_cursor_id,
115 WebKit::WebExceptionCode* ec);
117 void RequestIDBDatabaseClose(
118 int32 ipc_database_id);
120 void RequestIDBIndexOpenObjectCursor(
121 const WebKit::WebIDBKeyRange& idb_key_range,
122 unsigned short direction,
123 WebKit::WebIDBCallbacks* callbacks,
124 int32 ipc_index_id,
125 const WebKit::WebIDBTransaction& transaction,
126 WebKit::WebExceptionCode* ec);
128 void RequestIDBIndexOpenKeyCursor(
129 const WebKit::WebIDBKeyRange& idb_key_range,
130 unsigned short direction,
131 WebKit::WebIDBCallbacks* callbacks,
132 int32 ipc_index_id,
133 const WebKit::WebIDBTransaction& transaction,
134 WebKit::WebExceptionCode* ec);
136 void RequestIDBIndexCount(
137 const WebKit::WebIDBKeyRange& idb_key_range,
138 WebKit::WebIDBCallbacks* callbacks,
139 int32 ipc_index_id,
140 const WebKit::WebIDBTransaction& transaction,
141 WebKit::WebExceptionCode* ec);
143 void RequestIDBIndexGetObject(
144 const IndexedDBKeyRange& key_range,
145 WebKit::WebIDBCallbacks* callbacks,
146 int32 ipc_index_id,
147 const WebKit::WebIDBTransaction& transaction,
148 WebKit::WebExceptionCode* ec);
150 void RequestIDBIndexGetKey(
151 const IndexedDBKeyRange& key_range,
152 WebKit::WebIDBCallbacks* callbacks,
153 int32 ipc_index_id,
154 const WebKit::WebIDBTransaction& transaction,
155 WebKit::WebExceptionCode* ec);
157 void RequestIDBObjectStoreGet(
158 const IndexedDBKeyRange& key_range,
159 WebKit::WebIDBCallbacks* callbacks,
160 int32 ipc_object_store_id,
161 const WebKit::WebIDBTransaction& transaction,
162 WebKit::WebExceptionCode* ec);
164 void RequestIDBObjectStorePut(
165 const SerializedScriptValue& value,
166 const IndexedDBKey& key,
167 WebKit::WebIDBObjectStore::PutMode putMode,
168 WebKit::WebIDBCallbacks* callbacks,
169 int32 ipc_object_store_id,
170 const WebKit::WebIDBTransaction& transaction,
171 const WebKit::WebVector<long long>& indexIds,
172 const WebKit::WebVector<WebKit::WebVector<
173 WebKit::WebIDBKey> >& indexKeys);
175 void RequestIDBObjectStoreDelete(
176 const IndexedDBKeyRange& key_range,
177 WebKit::WebIDBCallbacks* callbacks,
178 int32 ipc_object_store_id,
179 const WebKit::WebIDBTransaction& transaction,
180 WebKit::WebExceptionCode* ec);
182 void RequestIDBObjectStoreClear(
183 WebKit::WebIDBCallbacks* callbacks,
184 int32 ipc_object_store_id,
185 const WebKit::WebIDBTransaction& transaction,
186 WebKit::WebExceptionCode* ec);
188 void RequestIDBObjectStoreOpenCursor(
189 const WebKit::WebIDBKeyRange& idb_key_range,
190 WebKit::WebIDBCursor::Direction direction,
191 WebKit::WebIDBCallbacks* callbacks,
192 int32 ipc_object_store_id,
193 WebKit::WebIDBTransaction::TaskType task_type,
194 const WebKit::WebIDBTransaction& transaction,
195 WebKit::WebExceptionCode* ec);
197 void RequestIDBObjectStoreCount(
198 const WebKit::WebIDBKeyRange& idb_key_range,
199 WebKit::WebIDBCallbacks* callbacks,
200 int32 ipc_object_store_id,
201 const WebKit::WebIDBTransaction& transaction,
202 WebKit::WebExceptionCode* ec);
204 void RegisterWebIDBTransactionCallbacks(
205 WebKit::WebIDBTransactionCallbacks* callbacks,
206 int32 id);
208 void CursorDestroyed(int32 ipc_cursor_id);
209 void DatabaseDestroyed(int32 ipc_database_id);
211 static int32 TransactionId(const WebKit::WebIDBTransaction& transaction);
213 private:
214 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest);
216 // IDBCallback message handlers.
217 void OnSuccessIDBDatabase(int32 ipc_thread_id,
218 int32 ipc_response_id,
219 int32 ipc_object_id);
220 void OnSuccessIndexedDBKey(int32 ipc_thread_id,
221 int32 ipc_response_id,
222 const IndexedDBKey& key);
223 void OnSuccessOpenCursor(
224 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p);
225 void OnSuccessCursorContinue(
226 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p);
227 void OnSuccessCursorPrefetch(
228 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p);
229 void OnSuccessStringList(int32 ipc_thread_id,
230 int32 ipc_response_id,
231 const std::vector<string16>& value);
232 void OnSuccessSerializedScriptValue(
233 int32 ipc_thread_id,
234 int32 ipc_response_id,
235 const SerializedScriptValue& value);
236 void OnSuccessSerializedScriptValueWithKey(
237 int32 ipc_thread_id,
238 int32 ipc_response_id,
239 const SerializedScriptValue& value,
240 const IndexedDBKey& primary_key,
241 const IndexedDBKeyPath& key_path);
242 void OnSuccessInteger(
243 int32 ipc_thread_id,
244 int32 ipc_response_id,
245 int64 value);
246 void OnSuccessUndefined(
247 int32 ipc_thread_id,
248 int32 ipc_response_id);
249 void OnError(int32 ipc_thread_id,
250 int32 ipc_response_id,
251 int code,
252 const string16& message);
253 void OnBlocked(int32 ipc_thread_id, int32 ipc_response_id);
254 void OnIntBlocked(int32 ipc_thread_id, int32 ipc_response_id,
255 int64 existing_version);
256 void OnUpgradeNeeded(int32 ipc_thread_id,
257 int32 ipc_response_id,
258 int32 ipc_transaction_id,
259 int32 ipc_database_id,
260 int64 old_version);
261 void OnAbort(int32 ipc_thread_id,
262 int32 ipc_transaction_id,
263 int code,
264 const string16& message);
265 void OnComplete(int32 ipc_thread_id, int32 ipc_transaction_id);
266 void OnForcedClose(int32 ipc_thread_id, int32 ipc_database_id);
267 void OnVersionChange(int32 ipc_thread_id,
268 int32 ipc_database_id,
269 const string16& newVersion);
270 void OnIntVersionChange(int32 ipc_thread_id,
271 int32 ipc_database_id,
272 int64 old_version,
273 int64 new_version);
275 // Reset cursor prefetch caches for all cursors except exception_cursor_id.
276 void ResetCursorPrefetchCaches(int32 ipc_exception_cursor_id = -1);
278 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
279 // destroyed and used on the same thread it was created on.
280 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_;
281 IDMap<WebKit::WebIDBTransactionCallbacks, IDMapOwnPointer>
282 pending_transaction_callbacks_;
283 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer>
284 pending_database_callbacks_;
286 // Map from cursor id to RendererWebIDBCursorImpl.
287 std::map<int32, RendererWebIDBCursorImpl*> cursors_;
289 std::map<int32, RendererWebIDBDatabaseImpl*> databases_;
291 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
294 } // namespace content
296 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_DISPATCHER_H_