Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/common/indexed_db_messages.h" | 7 #include "content/common/indexed_db_messages.h" |
| 8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
| 9 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
| 10 #include "content/renderer/renderer_webidbcursor_impl.h" | 10 #include "content/renderer/renderer_webidbcursor_impl.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 } | 35 } |
| 36 | 36 |
| 37 IndexedDBDispatcher::~IndexedDBDispatcher() { | 37 IndexedDBDispatcher::~IndexedDBDispatcher() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { | 40 bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 41 bool handled = true; | 41 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) | 42 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) |
| 43 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, | 43 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, |
| 44 OnSuccessOpenCursor) | 44 OnSuccessOpenCursor) |
| 45 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, | |
| 46 OnSuccessCursorContinue) | |
| 45 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, | 47 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, |
| 46 OnSuccessIDBDatabase) | 48 OnSuccessIDBDatabase) |
| 47 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 49 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
| 48 OnSuccessIndexedDBKey) | 50 OnSuccessIndexedDBKey) |
| 49 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, | 51 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, |
| 50 OnSuccessIDBTransaction) | 52 OnSuccessIDBTransaction) |
| 51 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 53 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
| 52 OnSuccessStringList) | 54 OnSuccessStringList) |
| 53 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, | 55 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, |
| 54 OnSuccessSerializedScriptValue) | 56 OnSuccessSerializedScriptValue) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 78 } | 80 } |
| 79 | 81 |
| 80 void IndexedDBDispatcher::RequestIDBCursorContinue( | 82 void IndexedDBDispatcher::RequestIDBCursorContinue( |
| 81 const IndexedDBKey& key, | 83 const IndexedDBKey& key, |
| 82 WebIDBCallbacks* callbacks_ptr, | 84 WebIDBCallbacks* callbacks_ptr, |
| 83 int32 idb_cursor_id, | 85 int32 idb_cursor_id, |
| 84 WebExceptionCode* ec) { | 86 WebExceptionCode* ec) { |
| 85 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 87 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 86 | 88 |
| 87 int32 response_id = pending_callbacks_.Add(callbacks.release()); | 89 int32 response_id = pending_callbacks_.Add(callbacks.release()); |
| 90 pending_cursor_continues_[response_id] = idb_cursor_id; | |
| 88 RenderThreadImpl::current()->Send( | 91 RenderThreadImpl::current()->Send( |
| 89 new IndexedDBHostMsg_CursorContinue(idb_cursor_id, response_id, key, ec)); | 92 new IndexedDBHostMsg_CursorContinue(idb_cursor_id, response_id, key, ec)); |
| 90 if (*ec) | 93 if (*ec) { |
| 91 pending_callbacks_.Remove(response_id); | 94 pending_callbacks_.Remove(response_id); |
| 95 pending_cursor_continues_.erase(idb_cursor_id); | |
| 96 } | |
| 92 } | 97 } |
| 93 | 98 |
| 94 void IndexedDBDispatcher::RequestIDBCursorDelete( | 99 void IndexedDBDispatcher::RequestIDBCursorDelete( |
| 95 WebIDBCallbacks* callbacks_ptr, | 100 WebIDBCallbacks* callbacks_ptr, |
| 96 int32 idb_cursor_id, | 101 int32 idb_cursor_id, |
| 97 WebExceptionCode* ec) { | 102 WebExceptionCode* ec) { |
| 98 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 103 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 99 | 104 |
| 100 int32 response_id = pending_callbacks_.Add(callbacks.release()); | 105 int32 response_id = pending_callbacks_.Add(callbacks.release()); |
| 101 RenderThreadImpl::current()->Send( | 106 RenderThreadImpl::current()->Send( |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 callbacks->onSuccess(value); | 429 callbacks->onSuccess(value); |
| 425 pending_callbacks_.Remove(response_id); | 430 pending_callbacks_.Remove(response_id); |
| 426 } | 431 } |
| 427 | 432 |
| 428 void IndexedDBDispatcher::OnSuccessOpenCursor(int32 repsonse_id, | 433 void IndexedDBDispatcher::OnSuccessOpenCursor(int32 repsonse_id, |
| 429 int32 object_id, const IndexedDBKey& key, const IndexedDBKey& primaryKey, | 434 int32 object_id, const IndexedDBKey& key, const IndexedDBKey& primaryKey, |
| 430 const content::SerializedScriptValue& value) { | 435 const content::SerializedScriptValue& value) { |
| 431 WebIDBCallbacks* callbacks = | 436 WebIDBCallbacks* callbacks = |
| 432 pending_callbacks_.Lookup(repsonse_id); | 437 pending_callbacks_.Lookup(repsonse_id); |
| 433 callbacks->onSuccess(new RendererWebIDBCursorImpl(object_id, key, | 438 callbacks->onSuccess(new RendererWebIDBCursorImpl(object_id, key, |
| 434 primaryKey, value)); | 439 primaryKey, value)); |
|
dgrogan
2011/10/29 00:54:28
You can remove the non-object_id parameters.
hans
2011/10/31 16:11:52
Done.
| |
| 440 | |
| 441 cursor_key_[object_id] = key; | |
|
dgrogan
2011/10/29 00:54:28
If the onSuccess call is synchronous, shouldn't th
hans
2011/10/31 16:11:52
It's not synchronous, but it certainly looks weird
| |
| 442 cursor_primary_key_[object_id] = primaryKey; | |
| 443 cursor_value_[object_id] = value; | |
| 444 | |
| 435 pending_callbacks_.Remove(repsonse_id); | 445 pending_callbacks_.Remove(repsonse_id); |
| 436 } | 446 } |
| 437 | 447 |
| 448 void IndexedDBDispatcher::OnSuccessCursorContinue( | |
| 449 int32 response_id, | |
|
michaeln
2011/10/30 21:54:06
cursor_id could be a useful here, i think you woul
hans
2011/10/31 16:11:52
Done.
| |
| 450 const IndexedDBKey& key, | |
| 451 const IndexedDBKey& primary_key, | |
| 452 const content::SerializedScriptValue& value) { | |
| 453 int32 cursor_id = pending_cursor_continues_[response_id]; | |
| 454 | |
|
michaeln
2011/10/30 21:54:06
Is there any chance the cursor was deleted prior t
hans
2011/10/31 16:11:52
No, according to the comment in ~RendererWebIDBCur
| |
| 455 cursor_key_[cursor_id] = key; | |
| 456 cursor_primary_key_[cursor_id] = primary_key; | |
| 457 cursor_value_[cursor_id] = value; | |
|
michaeln
2011/10/30 21:54:06
The RendererWebIDBCursorImpl has data members for
hans
2011/10/31 16:11:52
Yes, doing that.
| |
| 458 | |
| 459 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | |
| 460 callbacks->onSuccessCursorContinue(); | |
| 461 | |
| 462 pending_callbacks_.Remove(response_id); | |
| 463 pending_cursor_continues_.erase(response_id); | |
| 464 } | |
| 465 | |
| 438 void IndexedDBDispatcher::OnBlocked(int32 response_id) { | 466 void IndexedDBDispatcher::OnBlocked(int32 response_id) { |
| 439 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 467 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
| 440 callbacks->onBlocked(); | 468 callbacks->onBlocked(); |
| 441 } | 469 } |
| 442 | 470 |
| 443 void IndexedDBDispatcher::OnError(int32 response_id, int code, | 471 void IndexedDBDispatcher::OnError(int32 response_id, int code, |
| 444 const string16& message) { | 472 const string16& message) { |
| 445 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 473 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
| 446 callbacks->onError(WebIDBDatabaseError(code, message)); | 474 callbacks->onError(WebIDBDatabaseError(code, message)); |
| 447 pending_callbacks_.Remove(response_id); | 475 pending_callbacks_.Remove(response_id); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 463 | 491 |
| 464 void IndexedDBDispatcher::OnVersionChange(int32 database_id, | 492 void IndexedDBDispatcher::OnVersionChange(int32 database_id, |
| 465 const string16& newVersion) { | 493 const string16& newVersion) { |
| 466 WebIDBDatabaseCallbacks* callbacks = | 494 WebIDBDatabaseCallbacks* callbacks = |
| 467 pending_database_callbacks_.Lookup(database_id); | 495 pending_database_callbacks_.Lookup(database_id); |
| 468 // callbacks would be NULL if a versionchange event is received after close | 496 // callbacks would be NULL if a versionchange event is received after close |
| 469 // has been called. | 497 // has been called. |
| 470 if (callbacks) | 498 if (callbacks) |
| 471 callbacks->onVersionChange(newVersion); | 499 callbacks->onVersionChange(newVersion); |
| 472 } | 500 } |
| 501 | |
| 502 IndexedDBKey IndexedDBDispatcher::getCursorKey(int32 cursor_id) { | |
| 503 return cursor_key_[cursor_id]; | |
| 504 } | |
| 505 | |
| 506 IndexedDBKey IndexedDBDispatcher::getCursorPrimaryKey(int32 cursor_id) { | |
| 507 return cursor_primary_key_[cursor_id]; | |
| 508 } | |
| 509 | |
| 510 content::SerializedScriptValue IndexedDBDispatcher::getCursorValue( | |
| 511 int32 cursor_id) { | |
| 512 return cursor_value_[cursor_id]; | |
| 513 } | |
| 514 | |
| 515 void IndexedDBDispatcher::CursorDestroyed(int32 cursor_id) { | |
| 516 cursor_key_.erase(cursor_id); | |
| 517 cursor_primary_key_.erase(cursor_id); | |
| 518 cursor_value_.erase(cursor_id); | |
| 519 } | |
| OLD | NEW |