Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: content/renderer/indexed_db_dispatcher.cc

Issue 8747002: Dispatch IndexedDB IPC messages to worker threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make RenderThreadImpl own mainthread's idb dispatcher Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "content/renderer/indexed_db_dispatcher.h" 5 #include "content/renderer/indexed_db_dispatcher.h"
6 6
7 #include "base/lazy_instance.h"
7 #include "content/common/indexed_db_messages.h" 8 #include "content/common/indexed_db_messages.h"
8 #include "content/renderer/render_thread_impl.h" 9 #include "content/renderer/render_thread_impl.h"
9 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
10 #include "content/renderer/renderer_webidbcursor_impl.h" 11 #include "content/renderer/renderer_webidbcursor_impl.h"
11 #include "content/renderer/renderer_webidbdatabase_impl.h" 12 #include "content/renderer/renderer_webidbdatabase_impl.h"
12 #include "content/renderer/renderer_webidbindex_impl.h" 13 #include "content/renderer/renderer_webidbindex_impl.h"
13 #include "content/renderer/renderer_webidbobjectstore_impl.h" 14 #include "content/renderer/renderer_webidbobjectstore_impl.h"
14 #include "content/renderer/renderer_webidbtransaction_impl.h" 15 #include "content/renderer/renderer_webidbtransaction_impl.h"
16 #include "ipc/ipc_channel.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac ks.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac ks.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h " 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h "
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
22 21
22 using base::ThreadLocalPointer;
23 using WebKit::WebDOMStringList; 23 using WebKit::WebDOMStringList;
24 using WebKit::WebExceptionCode; 24 using WebKit::WebExceptionCode;
25 using WebKit::WebFrame; 25 using WebKit::WebFrame;
26 using WebKit::WebIDBCallbacks; 26 using WebKit::WebIDBCallbacks;
27 using WebKit::WebIDBKeyRange; 27 using WebKit::WebIDBKeyRange;
28 using WebKit::WebIDBDatabase; 28 using WebKit::WebIDBDatabase;
29 using WebKit::WebIDBDatabaseCallbacks; 29 using WebKit::WebIDBDatabaseCallbacks;
30 using WebKit::WebIDBDatabaseError; 30 using WebKit::WebIDBDatabaseError;
31 using WebKit::WebIDBTransaction; 31 using WebKit::WebIDBTransaction;
32 using WebKit::WebIDBTransactionCallbacks; 32 using WebKit::WebIDBTransactionCallbacks;
33 using webkit_glue::WorkerTaskRunner;
34
35 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher>,
36 base::LeakyLazyInstanceTraits<ThreadLocalPointer<IndexedDBDispatcher> > >
37 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
38
39 namespace {
40
41 int32 CurrentWorkerId() {
42 return WorkerTaskRunner::Instance()->CurrentWorkerId();
43 }
44
45 } // unnamed namespace
33 46
34 IndexedDBDispatcher::IndexedDBDispatcher() { 47 IndexedDBDispatcher::IndexedDBDispatcher() {
35 } 48 }
36 49
37 IndexedDBDispatcher::~IndexedDBDispatcher() { 50 IndexedDBDispatcher::~IndexedDBDispatcher() {
38 } 51 }
39 52
40 bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { 53 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() {
54 if (g_idb_dispatcher_tls.Pointer()->Get())
55 return g_idb_dispatcher_tls.Pointer()->Get();
56
57 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher;
58 g_idb_dispatcher_tls.Pointer()->Set(dispatcher);
59 if (WorkerTaskRunner::Instance()->CurrentWorkerId())
60 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher);
61 return dispatcher;
62 }
63
64 void IndexedDBDispatcher::OnWorkerRunLoopStopped() {
65 g_idb_dispatcher_tls.Pointer()->Set(NULL);
michaeln 2011/12/15 02:20:48 consider putting this line in the dtor so when the
66 delete this;
67 }
68
69 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
41 bool handled = true; 70 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) 71 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
43 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, 72 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor,
44 OnSuccessOpenCursor) 73 OnSuccessOpenCursor)
45 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, 74 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue,
46 OnSuccessCursorContinue) 75 OnSuccessCursorContinue)
47 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch, 76 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch,
48 OnSuccessCursorPrefetch) 77 OnSuccessCursorPrefetch)
49 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, 78 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase,
50 OnSuccessIDBDatabase) 79 OnSuccessIDBDatabase)
51 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, 80 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey,
52 OnSuccessIndexedDBKey) 81 OnSuccessIndexedDBKey)
53 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, 82 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction,
54 OnSuccessIDBTransaction) 83 OnSuccessIDBTransaction)
55 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, 84 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList,
56 OnSuccessStringList) 85 OnSuccessStringList)
57 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, 86 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue,
58 OnSuccessSerializedScriptValue) 87 OnSuccessSerializedScriptValue)
59 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) 88 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError)
60 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked) 89 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked)
61 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) 90 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort)
62 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) 91 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete)
63 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, 92 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange,
64 OnVersionChange) 93 OnVersionChange)
65 IPC_MESSAGE_UNHANDLED(handled = false) 94 IPC_MESSAGE_UNHANDLED(handled = false)
66 IPC_END_MESSAGE_MAP() 95 IPC_END_MESSAGE_MAP()
67 return handled; 96 // If a message gets here, IndexedDBMessageFilter already determined that it
97 // is an IndexedDB message.
98 DCHECK(handled);
68 } 99 }
69 100
70 void IndexedDBDispatcher::Send(IPC::Message* msg) { 101 void IndexedDBDispatcher::Send(IPC::Message* msg) {
71 ChildThread::current()->Send(msg); 102 ChildThread::current()->Send(msg);
72 } 103 }
73 104
74 void IndexedDBDispatcher::RequestIDBCursorUpdate( 105 void IndexedDBDispatcher::RequestIDBCursorUpdate(
75 const content::SerializedScriptValue& value, 106 const content::SerializedScriptValue& value,
76 WebIDBCallbacks* callbacks_ptr, 107 WebIDBCallbacks* callbacks_ptr,
77 int32 idb_cursor_id, 108 int32 idb_cursor_id,
78 WebExceptionCode* ec) { 109 WebExceptionCode* ec) {
79 ResetCursorPrefetchCaches(); 110 ResetCursorPrefetchCaches();
80 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 111 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
81 112
82 int32 response_id = pending_callbacks_.Add(callbacks.release()); 113 int32 response_id = pending_callbacks_.Add(callbacks.release());
83 Send( 114 Send(
84 new IndexedDBHostMsg_CursorUpdate(idb_cursor_id, response_id, value, ec)); 115 new IndexedDBHostMsg_CursorUpdate(idb_cursor_id, CurrentWorkerId(),
116 response_id, value, ec));
85 if (*ec) 117 if (*ec)
86 pending_callbacks_.Remove(response_id); 118 pending_callbacks_.Remove(response_id);
87 } 119 }
88 120
89 void IndexedDBDispatcher::RequestIDBCursorContinue( 121 void IndexedDBDispatcher::RequestIDBCursorContinue(
90 const IndexedDBKey& key, 122 const IndexedDBKey& key,
91 WebIDBCallbacks* callbacks_ptr, 123 WebIDBCallbacks* callbacks_ptr,
92 int32 idb_cursor_id, 124 int32 idb_cursor_id,
93 WebExceptionCode* ec) { 125 WebExceptionCode* ec) {
94 // Reset all cursor prefetch caches except for this cursor. 126 // Reset all cursor prefetch caches except for this cursor.
95 ResetCursorPrefetchCaches(idb_cursor_id); 127 ResetCursorPrefetchCaches(idb_cursor_id);
96 128
97 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 129 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
98 130
99 int32 response_id = pending_callbacks_.Add(callbacks.release()); 131 int32 response_id = pending_callbacks_.Add(callbacks.release());
100 Send( 132 Send(
101 new IndexedDBHostMsg_CursorContinue(idb_cursor_id, response_id, key, ec)); 133 new IndexedDBHostMsg_CursorContinue(idb_cursor_id, CurrentWorkerId(),
134 response_id, key, ec));
102 if (*ec) 135 if (*ec)
103 pending_callbacks_.Remove(response_id); 136 pending_callbacks_.Remove(response_id);
104 } 137 }
105 138
106 void IndexedDBDispatcher::RequestIDBCursorPrefetch( 139 void IndexedDBDispatcher::RequestIDBCursorPrefetch(
107 int n, 140 int n,
108 WebIDBCallbacks* callbacks_ptr, 141 WebIDBCallbacks* callbacks_ptr,
109 int32 idb_cursor_id, 142 int32 idb_cursor_id,
110 WebExceptionCode* ec) { 143 WebExceptionCode* ec) {
111 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 144 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
112 145
113 int32 response_id = pending_callbacks_.Add(callbacks.release()); 146 int32 response_id = pending_callbacks_.Add(callbacks.release());
114 RenderThreadImpl::current()->Send( 147 Send(new IndexedDBHostMsg_CursorPrefetch(idb_cursor_id, CurrentWorkerId(),
115 new IndexedDBHostMsg_CursorPrefetch(idb_cursor_id, response_id, n, ec)); 148 response_id, n, ec));
116 if (*ec) 149 if (*ec)
117 pending_callbacks_.Remove(response_id); 150 pending_callbacks_.Remove(response_id);
118 } 151 }
119 152
120 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset( 153 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(
121 int used_prefetches, int unused_prefetches, int32 idb_cursor_id) { 154 int used_prefetches, int unused_prefetches, int32 idb_cursor_id) {
122 RenderThreadImpl::current()->Send( 155 Send(new IndexedDBHostMsg_CursorPrefetchReset(idb_cursor_id,
123 new IndexedDBHostMsg_CursorPrefetchReset(idb_cursor_id, used_prefetches, 156 used_prefetches,
124 unused_prefetches)); 157 unused_prefetches));
125 } 158 }
126 159
127 void IndexedDBDispatcher::RequestIDBCursorDelete( 160 void IndexedDBDispatcher::RequestIDBCursorDelete(
128 WebIDBCallbacks* callbacks_ptr, 161 WebIDBCallbacks* callbacks_ptr,
129 int32 idb_cursor_id, 162 int32 idb_cursor_id,
130 WebExceptionCode* ec) { 163 WebExceptionCode* ec) {
131 ResetCursorPrefetchCaches(); 164 ResetCursorPrefetchCaches();
132 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 165 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
133 166
134 int32 response_id = pending_callbacks_.Add(callbacks.release()); 167 int32 response_id = pending_callbacks_.Add(callbacks.release());
135 Send(new IndexedDBHostMsg_CursorDelete(idb_cursor_id, response_id, ec)); 168 Send(new IndexedDBHostMsg_CursorDelete(idb_cursor_id, CurrentWorkerId(),
169 response_id, ec));
136 if (*ec) 170 if (*ec)
137 pending_callbacks_.Remove(response_id); 171 pending_callbacks_.Remove(response_id);
138 } 172 }
139 173
140 void IndexedDBDispatcher::RequestIDBFactoryOpen( 174 void IndexedDBDispatcher::RequestIDBFactoryOpen(
141 const string16& name, 175 const string16& name,
142 WebIDBCallbacks* callbacks_ptr, 176 WebIDBCallbacks* callbacks_ptr,
143 const string16& origin, 177 const string16& origin,
144 WebFrame* web_frame) { 178 WebFrame* web_frame) {
145 ResetCursorPrefetchCaches(); 179 ResetCursorPrefetchCaches();
146 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 180 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
147 181
148 if (!web_frame) 182 if (!web_frame)
149 return; // We must be shutting down. 183 return; // We must be shutting down.
150 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view()); 184 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
151 if (!render_view) 185 if (!render_view)
152 return; // We must be shutting down. 186 return; // We must be shutting down.
153 187
154 IndexedDBHostMsg_FactoryOpen_Params params; 188 IndexedDBHostMsg_FactoryOpen_Params params;
189 params.thread_id = CurrentWorkerId();
155 params.response_id = pending_callbacks_.Add(callbacks.release()); 190 params.response_id = pending_callbacks_.Add(callbacks.release());
156 params.origin = origin; 191 params.origin = origin;
157 params.name = name; 192 params.name = name;
158 Send(new IndexedDBHostMsg_FactoryOpen(params)); 193 Send(new IndexedDBHostMsg_FactoryOpen(params));
159 } 194 }
160 195
161 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( 196 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames(
162 WebIDBCallbacks* callbacks_ptr, 197 WebIDBCallbacks* callbacks_ptr,
163 const string16& origin, 198 const string16& origin,
164 WebFrame* web_frame) { 199 WebFrame* web_frame) {
165 ResetCursorPrefetchCaches(); 200 ResetCursorPrefetchCaches();
166 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 201 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
167 202
168 if (!web_frame) 203 if (!web_frame)
169 return; // We must be shutting down. 204 return; // We must be shutting down.
170 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view()); 205 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
171 if (!render_view) 206 if (!render_view)
172 return; // We must be shutting down. 207 return; // We must be shutting down.
173 208
174 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params; 209 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params;
210 params.thread_id = CurrentWorkerId();
175 params.response_id = pending_callbacks_.Add(callbacks.release()); 211 params.response_id = pending_callbacks_.Add(callbacks.release());
176 params.origin = origin; 212 params.origin = origin;
177 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params)); 213 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params));
178 } 214 }
179 215
180 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase( 216 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase(
181 const string16& name, 217 const string16& name,
182 WebIDBCallbacks* callbacks_ptr, 218 WebIDBCallbacks* callbacks_ptr,
183 const string16& origin, 219 const string16& origin,
184 WebFrame* web_frame) { 220 WebFrame* web_frame) {
185 ResetCursorPrefetchCaches(); 221 ResetCursorPrefetchCaches();
186 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 222 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
187 223
188 if (!web_frame) 224 if (!web_frame)
189 return; // We must be shutting down. 225 return; // We must be shutting down.
190 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view()); 226 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
191 if (!render_view) 227 if (!render_view)
192 return; // We must be shutting down. 228 return; // We must be shutting down.
193 229
194 IndexedDBHostMsg_FactoryDeleteDatabase_Params params; 230 IndexedDBHostMsg_FactoryDeleteDatabase_Params params;
231 params.thread_id = CurrentWorkerId();
195 params.response_id = pending_callbacks_.Add(callbacks.release()); 232 params.response_id = pending_callbacks_.Add(callbacks.release());
196 params.origin = origin; 233 params.origin = origin;
197 params.name = name; 234 params.name = name;
198 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); 235 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params));
199 } 236 }
200 237
201 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) { 238 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) {
202 ResetCursorPrefetchCaches(); 239 ResetCursorPrefetchCaches();
203 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id)); 240 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id));
204 pending_database_callbacks_.Remove(idb_database_id); 241 pending_database_callbacks_.Remove(idb_database_id);
205 } 242 }
206 243
207 void IndexedDBDispatcher::RequestIDBDatabaseOpen( 244 void IndexedDBDispatcher::RequestIDBDatabaseOpen(
208 WebIDBDatabaseCallbacks* callbacks_ptr, 245 WebIDBDatabaseCallbacks* callbacks_ptr,
209 int32 idb_database_id) { 246 int32 idb_database_id) {
210 ResetCursorPrefetchCaches(); 247 ResetCursorPrefetchCaches();
211 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr); 248 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr);
212 249
213 int32 response_id = pending_database_callbacks_.Add(callbacks.release()); 250 DCHECK(!pending_database_callbacks_.Lookup(idb_database_id));
214 Send(new IndexedDBHostMsg_DatabaseOpen(response_id, idb_database_id)); 251 pending_database_callbacks_.AddWithID(callbacks.release(), idb_database_id);
252 Send(new IndexedDBHostMsg_DatabaseOpen(idb_database_id, CurrentWorkerId(),
253 idb_database_id));
215 } 254 }
216 255
217 void IndexedDBDispatcher::RequestIDBDatabaseSetVersion( 256 void IndexedDBDispatcher::RequestIDBDatabaseSetVersion(
218 const string16& version, 257 const string16& version,
219 WebIDBCallbacks* callbacks_ptr, 258 WebIDBCallbacks* callbacks_ptr,
220 int32 idb_database_id, 259 int32 idb_database_id,
221 WebExceptionCode* ec) { 260 WebExceptionCode* ec) {
222 ResetCursorPrefetchCaches(); 261 ResetCursorPrefetchCaches();
223 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 262 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
224 263
225 int32 response_id = pending_callbacks_.Add(callbacks.release()); 264 int32 response_id = pending_callbacks_.Add(callbacks.release());
226 Send(new IndexedDBHostMsg_DatabaseSetVersion(idb_database_id, response_id, 265 Send(new IndexedDBHostMsg_DatabaseSetVersion(idb_database_id,
227 version, ec)); 266 CurrentWorkerId(),
267 response_id, version, ec));
228 if (*ec) 268 if (*ec)
229 pending_callbacks_.Remove(response_id); 269 pending_callbacks_.Remove(response_id);
230 } 270 }
231 271
232 void IndexedDBDispatcher::RequestIDBIndexOpenObjectCursor( 272 void IndexedDBDispatcher::RequestIDBIndexOpenObjectCursor(
233 const WebIDBKeyRange& idb_key_range, 273 const WebIDBKeyRange& idb_key_range,
234 unsigned short direction, 274 unsigned short direction,
235 WebIDBCallbacks* callbacks_ptr, 275 WebIDBCallbacks* callbacks_ptr,
236 int32 idb_index_id, 276 int32 idb_index_id,
237 const WebIDBTransaction& transaction, 277 const WebIDBTransaction& transaction,
238 WebExceptionCode* ec) { 278 WebExceptionCode* ec) {
239 ResetCursorPrefetchCaches(); 279 ResetCursorPrefetchCaches();
240 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 280 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
241 IndexedDBHostMsg_IndexOpenCursor_Params params; 281 IndexedDBHostMsg_IndexOpenCursor_Params params;
282 params.thread_id = CurrentWorkerId();
242 params.response_id = pending_callbacks_.Add(callbacks.release()); 283 params.response_id = pending_callbacks_.Add(callbacks.release());
243 params.lower_key.Set(idb_key_range.lower()); 284 params.lower_key.Set(idb_key_range.lower());
244 params.upper_key.Set(idb_key_range.upper()); 285 params.upper_key.Set(idb_key_range.upper());
245 params.lower_open = idb_key_range.lowerOpen(); 286 params.lower_open = idb_key_range.lowerOpen();
246 params.upper_open = idb_key_range.upperOpen(); 287 params.upper_open = idb_key_range.upperOpen();
247 params.direction = direction; 288 params.direction = direction;
248 params.idb_index_id = idb_index_id; 289 params.idb_index_id = idb_index_id;
249 params.transaction_id = TransactionId(transaction); 290 params.transaction_id = TransactionId(transaction);
250 Send(new IndexedDBHostMsg_IndexOpenObjectCursor(params, ec)); 291 Send(new IndexedDBHostMsg_IndexOpenObjectCursor(params, ec));
251 if (*ec) 292 if (*ec)
252 pending_callbacks_.Remove(params.response_id); 293 pending_callbacks_.Remove(params.response_id);
253 } 294 }
254 295
255 void IndexedDBDispatcher::RequestIDBIndexOpenKeyCursor( 296 void IndexedDBDispatcher::RequestIDBIndexOpenKeyCursor(
256 const WebIDBKeyRange& idb_key_range, 297 const WebIDBKeyRange& idb_key_range,
257 unsigned short direction, 298 unsigned short direction,
258 WebIDBCallbacks* callbacks_ptr, 299 WebIDBCallbacks* callbacks_ptr,
259 int32 idb_index_id, 300 int32 idb_index_id,
260 const WebIDBTransaction& transaction, 301 const WebIDBTransaction& transaction,
261 WebExceptionCode* ec) { 302 WebExceptionCode* ec) {
262 ResetCursorPrefetchCaches(); 303 ResetCursorPrefetchCaches();
263 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 304 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
264 IndexedDBHostMsg_IndexOpenCursor_Params params; 305 IndexedDBHostMsg_IndexOpenCursor_Params params;
306 params.thread_id = CurrentWorkerId();
265 params.response_id = pending_callbacks_.Add(callbacks.release()); 307 params.response_id = pending_callbacks_.Add(callbacks.release());
266 // TODO(jorlow): We really should just create a Chromium abstraction for 308 // TODO(jorlow): We really should just create a Chromium abstraction for
267 // KeyRange rather than doing it ad-hoc like this. 309 // KeyRange rather than doing it ad-hoc like this.
268 params.lower_key.Set(idb_key_range.lower()); 310 params.lower_key.Set(idb_key_range.lower());
269 params.upper_key.Set(idb_key_range.upper()); 311 params.upper_key.Set(idb_key_range.upper());
270 params.lower_open = idb_key_range.lowerOpen(); 312 params.lower_open = idb_key_range.lowerOpen();
271 params.upper_open = idb_key_range.upperOpen(); 313 params.upper_open = idb_key_range.upperOpen();
272 params.direction = direction; 314 params.direction = direction;
273 params.idb_index_id = idb_index_id; 315 params.idb_index_id = idb_index_id;
274 params.transaction_id = TransactionId(transaction); 316 params.transaction_id = TransactionId(transaction);
275 Send(new IndexedDBHostMsg_IndexOpenKeyCursor(params, ec)); 317 Send(new IndexedDBHostMsg_IndexOpenKeyCursor(params, ec));
276 if (*ec) 318 if (*ec)
277 pending_callbacks_.Remove(params.response_id); 319 pending_callbacks_.Remove(params.response_id);
278 } 320 }
279 321
280 void IndexedDBDispatcher::RequestIDBIndexGetObject( 322 void IndexedDBDispatcher::RequestIDBIndexGetObject(
281 const IndexedDBKey& key, 323 const IndexedDBKey& key,
282 WebIDBCallbacks* callbacks_ptr, 324 WebIDBCallbacks* callbacks_ptr,
283 int32 idb_index_id, 325 int32 idb_index_id,
284 const WebIDBTransaction& transaction, 326 const WebIDBTransaction& transaction,
285 WebExceptionCode* ec) { 327 WebExceptionCode* ec) {
286 ResetCursorPrefetchCaches(); 328 ResetCursorPrefetchCaches();
287 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 329 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
288 int32 response_id = pending_callbacks_.Add(callbacks.release()); 330 int32 response_id = pending_callbacks_.Add(callbacks.release());
289 Send(new IndexedDBHostMsg_IndexGetObject(idb_index_id, response_id, key, 331 Send(new IndexedDBHostMsg_IndexGetObject(idb_index_id, CurrentWorkerId(),
332 response_id, key,
290 TransactionId(transaction), ec)); 333 TransactionId(transaction), ec));
291 if (*ec) 334 if (*ec)
292 pending_callbacks_.Remove(response_id); 335 pending_callbacks_.Remove(response_id);
293 } 336 }
294 337
295 void IndexedDBDispatcher::RequestIDBIndexGetKey( 338 void IndexedDBDispatcher::RequestIDBIndexGetKey(
296 const IndexedDBKey& key, 339 const IndexedDBKey& key,
297 WebIDBCallbacks* callbacks_ptr, 340 WebIDBCallbacks* callbacks_ptr,
298 int32 idb_index_id, 341 int32 idb_index_id,
299 const WebIDBTransaction& transaction, 342 const WebIDBTransaction& transaction,
300 WebExceptionCode* ec) { 343 WebExceptionCode* ec) {
301 ResetCursorPrefetchCaches(); 344 ResetCursorPrefetchCaches();
302 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 345 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
303 int32 response_id = pending_callbacks_.Add(callbacks.release()); 346 int32 response_id = pending_callbacks_.Add(callbacks.release());
304 Send(new IndexedDBHostMsg_IndexGetKey( 347 Send(new IndexedDBHostMsg_IndexGetKey(
305 idb_index_id, response_id, key, 348 idb_index_id, CurrentWorkerId(), response_id, key,
306 TransactionId(transaction), ec)); 349 TransactionId(transaction), ec));
307 if (*ec) 350 if (*ec)
308 pending_callbacks_.Remove(response_id); 351 pending_callbacks_.Remove(response_id);
309 } 352 }
310 353
311 void IndexedDBDispatcher::RequestIDBObjectStoreGet( 354 void IndexedDBDispatcher::RequestIDBObjectStoreGet(
312 const IndexedDBKey& key, 355 const IndexedDBKey& key,
313 WebIDBCallbacks* callbacks_ptr, 356 WebIDBCallbacks* callbacks_ptr,
314 int32 idb_object_store_id, 357 int32 idb_object_store_id,
315 const WebIDBTransaction& transaction, 358 const WebIDBTransaction& transaction,
316 WebExceptionCode* ec) { 359 WebExceptionCode* ec) {
317 ResetCursorPrefetchCaches(); 360 ResetCursorPrefetchCaches();
318 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 361 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
319 362
320 int32 response_id = pending_callbacks_.Add(callbacks.release()); 363 int32 response_id = pending_callbacks_.Add(callbacks.release());
321 Send(new IndexedDBHostMsg_ObjectStoreGet( 364 Send(new IndexedDBHostMsg_ObjectStoreGet(
322 idb_object_store_id, response_id, 365 idb_object_store_id, CurrentWorkerId(), response_id,
323 key, TransactionId(transaction), ec)); 366 key, TransactionId(transaction), ec));
324 if (*ec) 367 if (*ec)
325 pending_callbacks_.Remove(response_id); 368 pending_callbacks_.Remove(response_id);
326 } 369 }
327 370
328 void IndexedDBDispatcher::RequestIDBObjectStorePut( 371 void IndexedDBDispatcher::RequestIDBObjectStorePut(
329 const content::SerializedScriptValue& value, 372 const content::SerializedScriptValue& value,
330 const IndexedDBKey& key, 373 const IndexedDBKey& key,
331 WebKit::WebIDBObjectStore::PutMode put_mode, 374 WebKit::WebIDBObjectStore::PutMode put_mode,
332 WebIDBCallbacks* callbacks_ptr, 375 WebIDBCallbacks* callbacks_ptr,
333 int32 idb_object_store_id, 376 int32 idb_object_store_id,
334 const WebIDBTransaction& transaction, 377 const WebIDBTransaction& transaction,
335 WebExceptionCode* ec) { 378 WebExceptionCode* ec) {
336 ResetCursorPrefetchCaches(); 379 ResetCursorPrefetchCaches();
337 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 380 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
338 IndexedDBHostMsg_ObjectStorePut_Params params; 381 IndexedDBHostMsg_ObjectStorePut_Params params;
382 params.thread_id = CurrentWorkerId();
339 params.idb_object_store_id = idb_object_store_id; 383 params.idb_object_store_id = idb_object_store_id;
340 params.response_id = pending_callbacks_.Add(callbacks.release()); 384 params.response_id = pending_callbacks_.Add(callbacks.release());
341 params.serialized_value = value; 385 params.serialized_value = value;
342 params.key = key; 386 params.key = key;
343 params.put_mode = put_mode; 387 params.put_mode = put_mode;
344 params.transaction_id = TransactionId(transaction); 388 params.transaction_id = TransactionId(transaction);
345 Send(new IndexedDBHostMsg_ObjectStorePut(params, ec)); 389 Send(new IndexedDBHostMsg_ObjectStorePut(params, ec));
346 if (*ec) 390 if (*ec)
347 pending_callbacks_.Remove(params.response_id); 391 pending_callbacks_.Remove(params.response_id);
348 } 392 }
349 393
350 void IndexedDBDispatcher::RequestIDBObjectStoreDelete( 394 void IndexedDBDispatcher::RequestIDBObjectStoreDelete(
351 const IndexedDBKey& key, 395 const IndexedDBKey& key,
352 WebIDBCallbacks* callbacks_ptr, 396 WebIDBCallbacks* callbacks_ptr,
353 int32 idb_object_store_id, 397 int32 idb_object_store_id,
354 const WebIDBTransaction& transaction, 398 const WebIDBTransaction& transaction,
355 WebExceptionCode* ec) { 399 WebExceptionCode* ec) {
356 ResetCursorPrefetchCaches(); 400 ResetCursorPrefetchCaches();
357 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 401 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
358 402
359 int32 response_id = pending_callbacks_.Add(callbacks.release()); 403 int32 response_id = pending_callbacks_.Add(callbacks.release());
360 Send(new IndexedDBHostMsg_ObjectStoreDelete( 404 Send(new IndexedDBHostMsg_ObjectStoreDelete(
361 idb_object_store_id, response_id, key, TransactionId(transaction), ec)); 405 idb_object_store_id, CurrentWorkerId(), response_id, key,
406 TransactionId(transaction), ec));
362 if (*ec) 407 if (*ec)
363 pending_callbacks_.Remove(response_id); 408 pending_callbacks_.Remove(response_id);
364 } 409 }
365 410
366 void IndexedDBDispatcher::RequestIDBObjectStoreClear( 411 void IndexedDBDispatcher::RequestIDBObjectStoreClear(
367 WebIDBCallbacks* callbacks_ptr, 412 WebIDBCallbacks* callbacks_ptr,
368 int32 idb_object_store_id, 413 int32 idb_object_store_id,
369 const WebIDBTransaction& transaction, 414 const WebIDBTransaction& transaction,
370 WebExceptionCode* ec) { 415 WebExceptionCode* ec) {
371 ResetCursorPrefetchCaches(); 416 ResetCursorPrefetchCaches();
372 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 417 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
373 418
374 int32 response_id = pending_callbacks_.Add(callbacks.release()); 419 int32 response_id = pending_callbacks_.Add(callbacks.release());
375 Send(new IndexedDBHostMsg_ObjectStoreClear( 420 Send(new IndexedDBHostMsg_ObjectStoreClear(
376 idb_object_store_id, response_id, TransactionId(transaction), ec)); 421 idb_object_store_id, CurrentWorkerId(), response_id,
422 TransactionId(transaction), ec));
377 if (*ec) 423 if (*ec)
378 pending_callbacks_.Remove(response_id); 424 pending_callbacks_.Remove(response_id);
379 } 425 }
380 426
381 void IndexedDBDispatcher::RequestIDBObjectStoreOpenCursor( 427 void IndexedDBDispatcher::RequestIDBObjectStoreOpenCursor(
382 const WebIDBKeyRange& idb_key_range, 428 const WebIDBKeyRange& idb_key_range,
383 unsigned short direction, 429 unsigned short direction,
384 WebIDBCallbacks* callbacks_ptr, 430 WebIDBCallbacks* callbacks_ptr,
385 int32 idb_object_store_id, 431 int32 idb_object_store_id,
386 const WebIDBTransaction& transaction, 432 const WebIDBTransaction& transaction,
387 WebExceptionCode* ec) { 433 WebExceptionCode* ec) {
388 ResetCursorPrefetchCaches(); 434 ResetCursorPrefetchCaches();
389 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 435 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
390 IndexedDBHostMsg_ObjectStoreOpenCursor_Params params; 436 IndexedDBHostMsg_ObjectStoreOpenCursor_Params params;
437 params.thread_id = CurrentWorkerId();
391 params.response_id = pending_callbacks_.Add(callbacks.release()); 438 params.response_id = pending_callbacks_.Add(callbacks.release());
392 params.lower_key.Set(idb_key_range.lower()); 439 params.lower_key.Set(idb_key_range.lower());
393 params.upper_key.Set(idb_key_range.upper()); 440 params.upper_key.Set(idb_key_range.upper());
394 params.lower_open = idb_key_range.lowerOpen(); 441 params.lower_open = idb_key_range.lowerOpen();
395 params.upper_open = idb_key_range.upperOpen(); 442 params.upper_open = idb_key_range.upperOpen();
396 params.direction = direction; 443 params.direction = direction;
397 params.idb_object_store_id = idb_object_store_id; 444 params.idb_object_store_id = idb_object_store_id;
398 params.transaction_id = TransactionId(transaction); 445 params.transaction_id = TransactionId(transaction);
399 Send(new IndexedDBHostMsg_ObjectStoreOpenCursor(params, ec)); 446 Send(new IndexedDBHostMsg_ObjectStoreOpenCursor(params, ec));
400 if (*ec) 447 if (*ec)
(...skipping 10 matching lines...) Expand all
411 cursors_.erase(cursor_id); 458 cursors_.erase(cursor_id);
412 } 459 }
413 460
414 int32 IndexedDBDispatcher::TransactionId( 461 int32 IndexedDBDispatcher::TransactionId(
415 const WebIDBTransaction& transaction) { 462 const WebIDBTransaction& transaction) {
416 const RendererWebIDBTransactionImpl* impl = 463 const RendererWebIDBTransactionImpl* impl =
417 static_cast<const RendererWebIDBTransactionImpl*>(&transaction); 464 static_cast<const RendererWebIDBTransactionImpl*>(&transaction);
418 return impl->id(); 465 return impl->id();
419 } 466 }
420 467
421 void IndexedDBDispatcher::OnSuccessIDBDatabase(int32 response_id, 468 void IndexedDBDispatcher::OnSuccessIDBDatabase(int32 thread_id,
469 int32 response_id,
422 int32 object_id) { 470 int32 object_id) {
471 DCHECK_EQ(thread_id, CurrentWorkerId());
423 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 472 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
424 if (!callbacks) 473 if (!callbacks)
425 return; 474 return;
426 callbacks->onSuccess(new RendererWebIDBDatabaseImpl(object_id)); 475 callbacks->onSuccess(new RendererWebIDBDatabaseImpl(object_id));
427 pending_callbacks_.Remove(response_id); 476 pending_callbacks_.Remove(response_id);
428 } 477 }
429 478
430 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32 response_id, 479 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32 thread_id,
480 int32 response_id,
431 const IndexedDBKey& key) { 481 const IndexedDBKey& key) {
482 DCHECK_EQ(thread_id, CurrentWorkerId());
432 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 483 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
433 if (!callbacks) 484 if (!callbacks)
434 return; 485 return;
435 callbacks->onSuccess(key); 486 callbacks->onSuccess(key);
436 pending_callbacks_.Remove(response_id); 487 pending_callbacks_.Remove(response_id);
437 } 488 }
438 489
439 void IndexedDBDispatcher::OnSuccessIDBTransaction(int32 response_id, 490 void IndexedDBDispatcher::OnSuccessIDBTransaction(int32 thread_id,
491 int32 response_id,
440 int32 object_id) { 492 int32 object_id) {
493 DCHECK_EQ(thread_id, CurrentWorkerId());
441 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 494 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
442 if (!callbacks) 495 if (!callbacks)
443 return; 496 return;
444 callbacks->onSuccess(new RendererWebIDBTransactionImpl(object_id)); 497 callbacks->onSuccess(new RendererWebIDBTransactionImpl(object_id));
445 pending_callbacks_.Remove(response_id); 498 pending_callbacks_.Remove(response_id);
446 } 499 }
447 500
448 void IndexedDBDispatcher::OnSuccessStringList( 501 void IndexedDBDispatcher::OnSuccessStringList(
449 int32 response_id, const std::vector<string16>& value) { 502 int32 thread_id, int32 response_id, const std::vector<string16>& value) {
503 DCHECK_EQ(thread_id, CurrentWorkerId());
450 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 504 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
451 if (!callbacks) 505 if (!callbacks)
452 return; 506 return;
453 WebDOMStringList string_list; 507 WebDOMStringList string_list;
454 for (std::vector<string16>::const_iterator it = value.begin(); 508 for (std::vector<string16>::const_iterator it = value.begin();
455 it != value.end(); ++it) 509 it != value.end(); ++it)
456 string_list.append(*it); 510 string_list.append(*it);
457 callbacks->onSuccess(string_list); 511 callbacks->onSuccess(string_list);
458 pending_callbacks_.Remove(response_id); 512 pending_callbacks_.Remove(response_id);
459 } 513 }
460 514
461 void IndexedDBDispatcher::OnSuccessSerializedScriptValue( 515 void IndexedDBDispatcher::OnSuccessSerializedScriptValue(
462 int32 response_id, const content::SerializedScriptValue& value) { 516 int32 thread_id, int32 response_id,
517 const content::SerializedScriptValue& value) {
518 DCHECK_EQ(thread_id, CurrentWorkerId());
463 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 519 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
464 if (!callbacks) 520 if (!callbacks)
465 return; 521 return;
466 callbacks->onSuccess(value); 522 callbacks->onSuccess(value);
467 pending_callbacks_.Remove(response_id); 523 pending_callbacks_.Remove(response_id);
468 } 524 }
469 525
470 void IndexedDBDispatcher::OnSuccessOpenCursor(int32 repsonse_id, 526 void IndexedDBDispatcher::OnSuccessOpenCursor(
471 int32 object_id, const IndexedDBKey& key, const IndexedDBKey& primary_key, 527 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) {
472 const content::SerializedScriptValue& value) { 528 DCHECK_EQ(p.thread_id, CurrentWorkerId());
529 int32 response_id = p.response_id;
530 int32 object_id = p.cursor_id;
531 const IndexedDBKey& key = p.key;
532 const IndexedDBKey& primary_key = p.primary_key;
533 const content::SerializedScriptValue& value = p.serialized_value;
534
473 WebIDBCallbacks* callbacks = 535 WebIDBCallbacks* callbacks =
474 pending_callbacks_.Lookup(repsonse_id); 536 pending_callbacks_.Lookup(response_id);
475 if (!callbacks) 537 if (!callbacks)
476 return; 538 return;
477 539
478 RendererWebIDBCursorImpl* cursor = new RendererWebIDBCursorImpl(object_id); 540 RendererWebIDBCursorImpl* cursor = new RendererWebIDBCursorImpl(object_id);
479 cursors_[object_id] = cursor; 541 cursors_[object_id] = cursor;
480 cursor->SetKeyAndValue(key, primary_key, value); 542 cursor->SetKeyAndValue(key, primary_key, value);
481 callbacks->onSuccess(cursor); 543 callbacks->onSuccess(cursor);
482 544
483 pending_callbacks_.Remove(repsonse_id); 545 pending_callbacks_.Remove(response_id);
484 } 546 }
485 547
486 void IndexedDBDispatcher::OnSuccessCursorContinue( 548 void IndexedDBDispatcher::OnSuccessCursorContinue(
487 int32 response_id, 549 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
488 int32 cursor_id, 550 DCHECK_EQ(p.thread_id, CurrentWorkerId());
489 const IndexedDBKey& key, 551 int32 response_id = p.response_id;
490 const IndexedDBKey& primary_key, 552 int32 cursor_id = p.cursor_id;
491 const content::SerializedScriptValue& value) { 553 const IndexedDBKey& key = p.key;
554 const IndexedDBKey& primary_key = p.primary_key;
555 const content::SerializedScriptValue& value = p.serialized_value;
556
492 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id]; 557 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id];
493 DCHECK(cursor); 558 DCHECK(cursor);
494 cursor->SetKeyAndValue(key, primary_key, value); 559 cursor->SetKeyAndValue(key, primary_key, value);
495 560
496 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 561 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
497 if (!callbacks) 562 if (!callbacks)
498 return; 563 return;
499 callbacks->onSuccessWithContinuation(); 564 callbacks->onSuccessWithContinuation();
500 565
501 pending_callbacks_.Remove(response_id); 566 pending_callbacks_.Remove(response_id);
502 } 567 }
503 568
504 void IndexedDBDispatcher::OnSuccessCursorPrefetch( 569 void IndexedDBDispatcher::OnSuccessCursorPrefetch(
505 int32 response_id, 570 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
506 int32 cursor_id, 571 DCHECK_EQ(p.thread_id, CurrentWorkerId());
507 const std::vector<IndexedDBKey>& keys, 572 int32 response_id = p.response_id;
508 const std::vector<IndexedDBKey>& primary_keys, 573 int32 cursor_id = p.cursor_id;
509 const std::vector<content::SerializedScriptValue>& values) { 574 const std::vector<IndexedDBKey>& keys = p.keys;
575 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys;
576 const std::vector<content::SerializedScriptValue>& values = p.values;
510 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id]; 577 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id];
511 DCHECK(cursor); 578 DCHECK(cursor);
512 cursor->SetPrefetchData(keys, primary_keys, values); 579 cursor->SetPrefetchData(keys, primary_keys, values);
513 580
514 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 581 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
515 cursor->CachedContinue(callbacks); 582 cursor->CachedContinue(callbacks);
516 pending_callbacks_.Remove(response_id); 583 pending_callbacks_.Remove(response_id);
517 } 584 }
518 585
519 void IndexedDBDispatcher::OnBlocked(int32 response_id) { 586 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) {
587 DCHECK_EQ(thread_id, CurrentWorkerId());
520 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 588 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
521 callbacks->onBlocked(); 589 callbacks->onBlocked();
522 } 590 }
523 591
524 void IndexedDBDispatcher::OnError(int32 response_id, int code, 592 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code,
525 const string16& message) { 593 const string16& message) {
594 DCHECK_EQ(thread_id, CurrentWorkerId());
526 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 595 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
527 if (!callbacks) 596 if (!callbacks)
528 return; 597 return;
529 callbacks->onError(WebIDBDatabaseError(code, message)); 598 callbacks->onError(WebIDBDatabaseError(code, message));
530 pending_callbacks_.Remove(response_id); 599 pending_callbacks_.Remove(response_id);
531 } 600 }
532 601
533 void IndexedDBDispatcher::OnAbort(int32 transaction_id) { 602 void IndexedDBDispatcher::OnAbort(int32 thread_id, int32 transaction_id) {
603 DCHECK_EQ(thread_id, CurrentWorkerId());
534 WebIDBTransactionCallbacks* callbacks = 604 WebIDBTransactionCallbacks* callbacks =
535 pending_transaction_callbacks_.Lookup(transaction_id); 605 pending_transaction_callbacks_.Lookup(transaction_id);
536 if (!callbacks) 606 if (!callbacks)
537 return; 607 return;
538 callbacks->onAbort(); 608 callbacks->onAbort();
539 pending_transaction_callbacks_.Remove(transaction_id); 609 pending_transaction_callbacks_.Remove(transaction_id);
540 } 610 }
541 611
542 void IndexedDBDispatcher::OnComplete(int32 transaction_id) { 612 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) {
613 DCHECK_EQ(thread_id, CurrentWorkerId());
543 WebIDBTransactionCallbacks* callbacks = 614 WebIDBTransactionCallbacks* callbacks =
544 pending_transaction_callbacks_.Lookup(transaction_id); 615 pending_transaction_callbacks_.Lookup(transaction_id);
545 if (!callbacks) 616 if (!callbacks)
546 return; 617 return;
547 callbacks->onComplete(); 618 callbacks->onComplete();
548 pending_transaction_callbacks_.Remove(transaction_id); 619 pending_transaction_callbacks_.Remove(transaction_id);
549 } 620 }
550 621
551 void IndexedDBDispatcher::OnVersionChange(int32 database_id, 622 void IndexedDBDispatcher::OnVersionChange(int32 thread_id,
623 int32 database_id,
552 const string16& newVersion) { 624 const string16& newVersion) {
625 DCHECK_EQ(thread_id, CurrentWorkerId());
553 WebIDBDatabaseCallbacks* callbacks = 626 WebIDBDatabaseCallbacks* callbacks =
554 pending_database_callbacks_.Lookup(database_id); 627 pending_database_callbacks_.Lookup(database_id);
555 // callbacks would be NULL if a versionchange event is received after close 628 // callbacks would be NULL if a versionchange event is received after close
556 // has been called. 629 // has been called.
557 if (!callbacks) 630 if (!callbacks)
558 return; 631 return;
559 callbacks->onVersionChange(newVersion); 632 callbacks->onVersionChange(newVersion);
560 } 633 }
561 634
562 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { 635 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) {
563 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; 636 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator;
564 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 637 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
565 if (i->first == exception_cursor_id) 638 if (i->first == exception_cursor_id)
566 continue; 639 continue;
567 i->second->ResetPrefetchCache(); 640 i->second->ResetPrefetchCache();
568 } 641 }
569 } 642 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698