OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_COMMON_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
6 #define CONTENT_COMMON_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/id_map.h" | |
13 #include "base/nullable_string16.h" | |
14 #include "content/common/content_export.h" | |
15 #include "ipc/ipc_sync_message_filter.h" | |
16 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" | |
17 #include "third_party/WebKit/public/platform/WebIDBCursor.h" | |
18 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | |
19 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" | |
20 #include "webkit/glue/worker_task_runner.h" | |
21 | |
22 struct IndexedDBDatabaseMetadata; | |
23 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; | |
24 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; | |
25 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; | |
26 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; | |
27 | |
28 namespace WebKit { | |
29 class WebData; | |
30 } | |
31 | |
32 namespace content { | |
33 class IndexedDBKey; | |
34 class IndexedDBKeyPath; | |
35 class IndexedDBKeyRange; | |
36 class RendererWebIDBCursorImpl; | |
37 class RendererWebIDBDatabaseImpl; | |
38 | |
39 CONTENT_EXPORT extern const size_t kMaxIDBValueSizeInBytes; | |
40 | |
41 // Handle the indexed db related communication for this context thread - the | |
42 // main thread and each worker thread have their own copies. | |
43 class CONTENT_EXPORT IndexedDBDispatcher | |
44 : public webkit_glue::WorkerTaskRunner::Observer { | |
45 public: | |
46 // Constructor made public to allow RenderThreadImpl to own a copy without | |
47 // failing a NOTREACHED in ThreadSpecificInstance in tests that instantiate | |
48 // two copies of RenderThreadImpl on the same thread. Everyone else probably | |
49 // wants to use ThreadSpecificInstance(). | |
50 IndexedDBDispatcher(); | |
51 virtual ~IndexedDBDispatcher(); | |
52 static IndexedDBDispatcher* ThreadSpecificInstance(); | |
53 | |
54 // webkit_glue::WorkerTaskRunner::Observer implementation. | |
55 virtual void OnWorkerRunLoopStopped() OVERRIDE; | |
56 | |
57 static WebKit::WebIDBMetadata ConvertMetadata( | |
58 const IndexedDBDatabaseMetadata& idb_metadata); | |
59 | |
60 void OnMessageReceived(const IPC::Message& msg); | |
61 static bool Send(IPC::Message* msg); | |
62 | |
63 void RequestIDBFactoryGetDatabaseNames(WebKit::WebIDBCallbacks* callbacks, | |
64 const string16& database_identifier); | |
65 | |
66 void RequestIDBFactoryOpen( | |
67 const string16& name, | |
68 int64 version, | |
69 int64 transaction_id, | |
70 WebKit::WebIDBCallbacks* callbacks, | |
71 WebKit::WebIDBDatabaseCallbacks* database_callbacks, | |
72 const string16& database_identifier); | |
73 | |
74 void RequestIDBFactoryDeleteDatabase(const string16& name, | |
75 WebKit::WebIDBCallbacks* callbacks, | |
76 const string16& database_identifier); | |
77 | |
78 void RequestIDBCursorAdvance(unsigned long count, | |
79 WebKit::WebIDBCallbacks* callbacks_ptr, | |
80 int32 ipc_cursor_id); | |
81 | |
82 virtual void RequestIDBCursorContinue(const IndexedDBKey& key, | |
83 WebKit::WebIDBCallbacks* callbacks_ptr, | |
84 int32 ipc_cursor_id); | |
85 | |
86 virtual void RequestIDBCursorPrefetch(int n, | |
87 WebKit::WebIDBCallbacks* callbacks_ptr, | |
88 int32 ipc_cursor_id); | |
89 | |
90 void RequestIDBCursorPrefetchReset(int used_prefetches, | |
91 int unused_prefetches, | |
92 int32 ipc_cursor_id); | |
93 | |
94 void RequestIDBDatabaseClose(int32 ipc_database_id, | |
95 int32 ipc_database_callbacks_id); | |
96 | |
97 void RequestIDBDatabaseCreateTransaction( | |
98 int32 ipc_database_id, | |
99 int64 transaction_id, | |
100 WebKit::WebIDBDatabaseCallbacks* database_callbacks_ptr, | |
101 WebKit::WebVector<long long> object_store_ids, | |
102 unsigned short mode); | |
103 | |
104 void RequestIDBDatabaseGet(int32 ipc_database_id, | |
105 int64 transaction_id, | |
106 int64 object_store_id, | |
107 int64 index_id, | |
108 const IndexedDBKeyRange& key_range, | |
109 bool key_only, | |
110 WebKit::WebIDBCallbacks* callbacks); | |
111 | |
112 void RequestIDBDatabasePut( | |
113 int32 ipc_database_id, | |
114 int64 transaction_id, | |
115 int64 object_store_id, | |
116 const WebKit::WebData& value, | |
117 const IndexedDBKey& key, | |
118 WebKit::WebIDBDatabase::PutMode put_mode, | |
119 WebKit::WebIDBCallbacks* callbacks, | |
120 const WebKit::WebVector<long long>& index_ids, | |
121 const WebKit::WebVector<WebKit::WebVector<WebKit::WebIDBKey> >& | |
122 index_keys); | |
123 | |
124 void RequestIDBDatabaseOpenCursor(int32 ipc_database_id, | |
125 int64 transaction_id, | |
126 int64 object_store_id, | |
127 int64 index_id, | |
128 const IndexedDBKeyRange& key_range, | |
129 unsigned short direction, | |
130 bool key_only, | |
131 WebKit::WebIDBDatabase::TaskType task_type, | |
132 WebKit::WebIDBCallbacks* callbacks); | |
133 | |
134 void RequestIDBDatabaseCount(int32 ipc_database_id, | |
135 int64 transaction_id, | |
136 int64 object_store_id, | |
137 int64 index_id, | |
138 const IndexedDBKeyRange& key_range, | |
139 WebKit::WebIDBCallbacks* callbacks); | |
140 | |
141 void RequestIDBDatabaseDeleteRange(int32 ipc_database_id, | |
142 int64 transaction_id, | |
143 int64 object_store_id, | |
144 const IndexedDBKeyRange& key_range, | |
145 WebKit::WebIDBCallbacks* callbacks); | |
146 | |
147 void RequestIDBDatabaseClear(int32 ipc_database_id, | |
148 int64 transaction_id, | |
149 int64 object_store_id, | |
150 WebKit::WebIDBCallbacks* callbacks); | |
151 | |
152 virtual void CursorDestroyed(int32 ipc_cursor_id); | |
153 void DatabaseDestroyed(int32 ipc_database_id); | |
154 | |
155 private: | |
156 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, ValueSizeTest); | |
157 | |
158 static int32 CurrentWorkerId() { | |
159 return webkit_glue::WorkerTaskRunner::Instance()->CurrentWorkerId(); | |
160 } | |
161 | |
162 template <typename T> | |
163 void init_params(T& params, WebKit::WebIDBCallbacks* callbacks_ptr) { | |
164 scoped_ptr<WebKit::WebIDBCallbacks> callbacks(callbacks_ptr); | |
165 params.ipc_thread_id = CurrentWorkerId(); | |
166 params.ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
167 } | |
168 | |
169 // IDBCallback message handlers. | |
170 void OnSuccessIDBDatabase(int32 ipc_thread_id, | |
171 int32 ipc_callbacks_id, | |
172 int32 ipc_database_callbacks_id, | |
173 int32 ipc_object_id, | |
174 const IndexedDBDatabaseMetadata& idb_metadata); | |
175 void OnSuccessIndexedDBKey(int32 ipc_thread_id, | |
176 int32 ipc_callbacks_id, | |
177 const IndexedDBKey& key); | |
178 | |
179 void OnSuccessOpenCursor( | |
180 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p); | |
181 void OnSuccessCursorContinue( | |
182 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p); | |
183 void OnSuccessCursorPrefetch( | |
184 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p); | |
185 void OnSuccessStringList(int32 ipc_thread_id, | |
186 int32 ipc_callbacks_id, | |
187 const std::vector<string16>& value); | |
188 void OnSuccessValue(int32 ipc_thread_id, | |
189 int32 ipc_callbacks_id, | |
190 const std::vector<char>& value); | |
191 void OnSuccessValueWithKey(int32 ipc_thread_id, | |
192 int32 ipc_callbacks_id, | |
193 const std::vector<char>& value, | |
194 const IndexedDBKey& primary_key, | |
195 const IndexedDBKeyPath& key_path); | |
196 void OnSuccessInteger(int32 ipc_thread_id, | |
197 int32 ipc_callbacks_id, | |
198 int64 value); | |
199 void OnSuccessUndefined(int32 ipc_thread_id, int32 ipc_callbacks_id); | |
200 void OnError(int32 ipc_thread_id, | |
201 int32 ipc_callbacks_id, | |
202 int code, | |
203 const string16& message); | |
204 void OnIntBlocked(int32 ipc_thread_id, | |
205 int32 ipc_callbacks_id, | |
206 int64 existing_version); | |
207 void OnUpgradeNeeded(const IndexedDBMsg_CallbacksUpgradeNeeded_Params& p); | |
208 void OnAbort(int32 ipc_thread_id, | |
209 int32 ipc_database_id, | |
210 int64 transaction_id, | |
211 int code, | |
212 const string16& message); | |
213 void OnComplete(int32 ipc_thread_id, | |
214 int32 ipc_database_id, | |
215 int64 transaction_id); | |
216 void OnForcedClose(int32 ipc_thread_id, int32 ipc_database_id); | |
217 void OnIntVersionChange(int32 ipc_thread_id, | |
218 int32 ipc_database_id, | |
219 int64 old_version, | |
220 int64 new_version); | |
221 | |
222 // Reset cursor prefetch caches for all cursors except exception_cursor_id. | |
223 void ResetCursorPrefetchCaches(int32 ipc_exception_cursor_id = -1); | |
224 | |
225 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be | |
226 // destroyed and used on the same thread it was created on. | |
227 IDMap<WebKit::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; | |
228 IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> | |
229 pending_database_callbacks_; | |
230 | |
231 // Map from cursor id to RendererWebIDBCursorImpl. | |
232 std::map<int32, RendererWebIDBCursorImpl*> cursors_; | |
233 | |
234 std::map<int32, RendererWebIDBDatabaseImpl*> databases_; | |
235 | |
236 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); | |
237 }; | |
238 | |
239 } // namespace content | |
240 | |
241 #endif // CONTENT_COMMON_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ | |
OLD | NEW |