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