diff options
author | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-05 12:36:35 +0000 |
---|---|---|
committer | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-05 12:36:35 +0000 |
commit | d7b435d52e9bc68fc956c261164908b6d0282df4 (patch) | |
tree | 91948e2a29bbbcc09101fd5df1b5a584f2b488ec /content | |
parent | 4b0e343daec06152c02c6b8c59b01f9e887fe97f (diff) | |
download | chromium_src-d7b435d52e9bc68fc956c261164908b6d0282df4.zip chromium_src-d7b435d52e9bc68fc956c261164908b6d0282df4.tar.gz chromium_src-d7b435d52e9bc68fc956c261164908b6d0282df4.tar.bz2 |
IndexedDB: Recycle curosr objects when calling continue().
This is the Chromium side of https://bugs.webkit.org/show_bug.cgi?id=71115
Instead of creating a new IDBCursor wrapper each time continue() is called,
we should instead send back a new onSuccessCursorContinue() callback, and the
IDBRequest will know which cursor to return.
This patch implements the new callback.
For performance, we piggy-pick the cursor's current key, primary key and
value with the callback. To be able to do this, the IndexedDBDispatcherHost
must keep track of which cursor corresponds to which pending callback.
The IndexedDBDispatcher keeps the key, primary key and value cached
for each cursor.
BUG=98685
TEST=all current tests pass
Review URL: http://codereview.chromium.org/8400061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/in_process_webkit/indexed_db_callbacks.cc | 18 | ||||
-rw-r--r-- | content/browser/in_process_webkit/indexed_db_callbacks.h | 14 | ||||
-rw-r--r-- | content/browser/in_process_webkit/indexed_db_dispatcher_host.cc | 14 | ||||
-rw-r--r-- | content/browser/in_process_webkit/indexed_db_dispatcher_host.h | 2 | ||||
-rw-r--r-- | content/common/indexed_db_messages.h | 6 | ||||
-rw-r--r-- | content/renderer/indexed_db_dispatcher.cc | 32 | ||||
-rw-r--r-- | content/renderer/indexed_db_dispatcher.h | 13 | ||||
-rw-r--r-- | content/renderer/renderer_webidbcursor_impl.cc | 21 | ||||
-rw-r--r-- | content/renderer/renderer_webidbcursor_impl.h | 13 |
9 files changed, 110 insertions, 23 deletions
diff --git a/content/browser/in_process_webkit/indexed_db_callbacks.cc b/content/browser/in_process_webkit/indexed_db_callbacks.cc index 01b4b63..70e79ef 100644 --- a/content/browser/in_process_webkit/indexed_db_callbacks.cc +++ b/content/browser/in_process_webkit/indexed_db_callbacks.cc @@ -41,6 +41,24 @@ void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccess( response_id(), content::SerializedScriptValue(value))); } +void IndexedDBCallbacks<WebKit::WebIDBCursor>::onSuccessWithContinuation() { + DCHECK(cursor_id_ != -1); + WebKit::WebIDBCursor* idb_cursor = dispatcher_host()->GetCursorFromId( + cursor_id_); + + DCHECK(idb_cursor); + if (!idb_cursor) + return; + + dispatcher_host()->Send( + new IndexedDBMsg_CallbacksSuccessCursorContinue( + response_id(), + cursor_id_, + IndexedDBKey(idb_cursor->key()), + IndexedDBKey(idb_cursor->primaryKey()), + content::SerializedScriptValue(idb_cursor->value()))); +} + void IndexedDBCallbacks<WebKit::WebIDBKey>::onSuccess( const WebKit::WebIDBKey& value) { dispatcher_host()->Send( diff --git a/content/browser/in_process_webkit/indexed_db_callbacks.h b/content/browser/in_process_webkit/indexed_db_callbacks.h index a5ef7de..085bfa4 100644 --- a/content/browser/in_process_webkit/indexed_db_callbacks.h +++ b/content/browser/in_process_webkit/indexed_db_callbacks.h @@ -76,7 +76,8 @@ class IndexedDBCallbacks : public IndexedDBCallbacksBase { DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); }; -// WebIDBCursor uses onSuccess(WebIDBCursor*) to indicate it has data, and +// WebIDBCursor uses onSuccess(WebIDBCursor*) when a cursor has been opened, +// onSuccessWithContinuation() when a continue() call has succeeded, or // onSuccess() without params to indicate it does not contain any data, i.e., // there is no key within the key range, or it has reached the end. template <> @@ -84,13 +85,20 @@ class IndexedDBCallbacks<WebKit::WebIDBCursor> : public IndexedDBCallbacksBase { public: IndexedDBCallbacks( - IndexedDBDispatcherHost* dispatcher_host, int32 response_id) - : IndexedDBCallbacksBase(dispatcher_host, response_id) { } + IndexedDBDispatcherHost* dispatcher_host, int32 response_id, + int32 cursor_id) + : IndexedDBCallbacksBase(dispatcher_host, response_id), + cursor_id_(cursor_id) { } virtual void onSuccess(WebKit::WebIDBCursor* idb_object); virtual void onSuccess(const WebKit::WebSerializedScriptValue& value); + virtual void onSuccessWithContinuation(); private: + // The id of the cursor this callback concerns, or -1 if the cursor + // does not exist yet. + int32 cursor_id_; + DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks); }; diff --git a/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc b/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc index baa1410..953445c 100644 --- a/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc +++ b/content/browser/in_process_webkit/indexed_db_dispatcher_host.cc @@ -191,6 +191,11 @@ int32 IndexedDBDispatcherHost::Add(WebIDBTransaction* idb_transaction, return id; } +WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 cursor_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); + return cursor_dispatcher_host_->map_.Lookup(cursor_id); +} + void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); @@ -553,7 +558,7 @@ void IndexedDBDispatcherHost::IndexDispatcherHost::OnOpenObjectCursor( *ec = 0; scoped_ptr<WebIDBCallbacks> callbacks( - new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id)); + new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id, -1)); idb_index->openObjectCursor( WebIDBKeyRange(params.lower_key, params.upper_key, params.lower_open, params.upper_open), @@ -573,7 +578,7 @@ void IndexedDBDispatcherHost::IndexDispatcherHost::OnOpenKeyCursor( *ec = 0; scoped_ptr<WebIDBCallbacks> callbacks( - new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id)); + new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id, -1)); idb_index->openKeyCursor( WebIDBKeyRange(params.lower_key, params.upper_key, params.lower_open, params.upper_open), @@ -844,7 +849,7 @@ void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnOpenCursor( *ec = 0; scoped_ptr<WebIDBCallbacks> callbacks( - new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id)); + new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id, -1)); idb_object_store->openCursor( WebIDBKeyRange(params.lower_key, params.upper_key, params.lower_open, params.upper_open), @@ -954,7 +959,8 @@ void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( *ec = 0; idb_cursor->continueFunction( - key, new IndexedDBCallbacks<WebIDBCursor>(parent_, response_id), *ec); + key, new IndexedDBCallbacks<WebIDBCursor>(parent_, response_id, + cursor_id), *ec); } void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete( diff --git a/content/browser/in_process_webkit/indexed_db_dispatcher_host.h b/content/browser/in_process_webkit/indexed_db_dispatcher_host.h index 3494c62..5a7c0d8 100644 --- a/content/browser/in_process_webkit/indexed_db_dispatcher_host.h +++ b/content/browser/in_process_webkit/indexed_db_dispatcher_host.h @@ -65,6 +65,8 @@ class IndexedDBDispatcherHost : public BrowserMessageFilter { int32 Add(WebKit::WebIDBTransaction* idb_transaction, const GURL& origin_url); int32 Add(WebKit::WebDOMStringList* domStringList); + WebKit::WebIDBCursor* GetCursorFromId(int32 cursor_id); + private: virtual ~IndexedDBDispatcherHost(); diff --git a/content/common/indexed_db_messages.h b/content/common/indexed_db_messages.h index 03bb03a..4830f0e 100644 --- a/content/common/indexed_db_messages.h +++ b/content/common/indexed_db_messages.h @@ -147,6 +147,12 @@ IPC_MESSAGE_CONTROL5(IndexedDBMsg_CallbacksSuccessIDBCursor, IndexedDBKey /* key */, IndexedDBKey /* primary key */, content::SerializedScriptValue /* script_value */) +IPC_MESSAGE_CONTROL5(IndexedDBMsg_CallbacksSuccessCursorContinue, + int32 /* response_id */, + int32 /* cursor_id */, + IndexedDBKey /* key */, + IndexedDBKey /* primary key */, + content::SerializedScriptValue /* script_value */) IPC_MESSAGE_CONTROL2(IndexedDBMsg_CallbacksSuccessIDBDatabase, int32 /* response_id */, int32 /* idb_database_id */) diff --git a/content/renderer/indexed_db_dispatcher.cc b/content/renderer/indexed_db_dispatcher.cc index c3eea0e..115e2b2 100644 --- a/content/renderer/indexed_db_dispatcher.cc +++ b/content/renderer/indexed_db_dispatcher.cc @@ -42,6 +42,8 @@ bool IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg) IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor, OnSuccessOpenCursor) + IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue, + OnSuccessCursorContinue) IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase, OnSuccessIDBDatabase) IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, @@ -379,6 +381,10 @@ void IndexedDBDispatcher::RegisterWebIDBTransactionCallbacks( pending_transaction_callbacks_.AddWithID(callbacks, id); } +void IndexedDBDispatcher::CursorDestroyed(int32 cursor_id) { + cursors_.erase(cursor_id); +} + int32 IndexedDBDispatcher::TransactionId( const WebIDBTransaction& transaction) { const RendererWebIDBTransactionImpl* impl = @@ -426,15 +432,35 @@ void IndexedDBDispatcher::OnSuccessSerializedScriptValue( } void IndexedDBDispatcher::OnSuccessOpenCursor(int32 repsonse_id, - int32 object_id, const IndexedDBKey& key, const IndexedDBKey& primaryKey, + int32 object_id, const IndexedDBKey& key, const IndexedDBKey& primary_key, const content::SerializedScriptValue& value) { WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(repsonse_id); - callbacks->onSuccess(new RendererWebIDBCursorImpl(object_id, key, - primaryKey, value)); + + RendererWebIDBCursorImpl* cursor = new RendererWebIDBCursorImpl(object_id); + cursors_[object_id] = cursor; + cursor->SetKeyAndValue(key, primary_key, value); + callbacks->onSuccess(cursor); + pending_callbacks_.Remove(repsonse_id); } +void IndexedDBDispatcher::OnSuccessCursorContinue( + int32 response_id, + int32 cursor_id, + const IndexedDBKey& key, + const IndexedDBKey& primary_key, + const content::SerializedScriptValue& value) { + RendererWebIDBCursorImpl* cursor = cursors_[cursor_id]; + DCHECK(cursor); + cursor->SetKeyAndValue(key, primary_key, value); + + WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); + callbacks->onSuccessWithContinuation(); + + pending_callbacks_.Remove(response_id); +} + void IndexedDBDispatcher::OnBlocked(int32 response_id) { WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); callbacks->onBlocked(); diff --git a/content/renderer/indexed_db_dispatcher.h b/content/renderer/indexed_db_dispatcher.h index e30fa95..d779454 100644 --- a/content/renderer/indexed_db_dispatcher.h +++ b/content/renderer/indexed_db_dispatcher.h @@ -6,6 +6,8 @@ #define CONTENT_RENDERER_INDEXED_DB_DISPATCHER_H_ #pragma once +#include <map> + #include "base/id_map.h" #include "base/nullable_string16.h" #include "ipc/ipc_channel.h" @@ -16,6 +18,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransactionCallbacks.h" class IndexedDBKey; +class RendererWebIDBCursorImpl; namespace WebKit { class WebDOMStringList; @@ -151,6 +154,8 @@ class IndexedDBDispatcher : public IPC::Channel::Listener { WebKit::WebIDBTransactionCallbacks* callbacks, int32 id); + void CursorDestroyed(int32 cursor_id); + static int32 TransactionId(const WebKit::WebIDBTransaction& transaction); private: @@ -163,6 +168,11 @@ class IndexedDBDispatcher : public IPC::Channel::Listener { const IndexedDBKey& key, const IndexedDBKey& primary_key, const content::SerializedScriptValue& value); + void OnSuccessCursorContinue(int32 response_id, + int32 cursor_id, + const IndexedDBKey& key, + const IndexedDBKey& primary_key, + const content::SerializedScriptValue& value); void OnSuccessStringList(int32 response_id, const std::vector<string16>& value); void OnSuccessSerializedScriptValue( @@ -182,6 +192,9 @@ class IndexedDBDispatcher : public IPC::Channel::Listener { IDMap<WebKit::WebIDBDatabaseCallbacks, IDMapOwnPointer> pending_database_callbacks_; + // Map from cursor id to RendererWebIDBCursorImpl. + std::map<int32, RendererWebIDBCursorImpl*> cursors_; + DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); }; diff --git a/content/renderer/renderer_webidbcursor_impl.cc b/content/renderer/renderer_webidbcursor_impl.cc index 82996f4..8060040 100644 --- a/content/renderer/renderer_webidbcursor_impl.cc +++ b/content/renderer/renderer_webidbcursor_impl.cc @@ -13,13 +13,8 @@ using WebKit::WebIDBCallbacks; using WebKit::WebIDBKey; using WebKit::WebSerializedScriptValue; -RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id, - const IndexedDBKey& key, const IndexedDBKey& primary_key, - const content::SerializedScriptValue& value) - : idb_cursor_id_(idb_cursor_id), - key_(key), - primary_key_(primary_key), - value_(value) { +RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id) + : idb_cursor_id_(idb_cursor_id) { } RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { @@ -29,6 +24,9 @@ RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { // any such pointers. RenderThreadImpl::current()->Send(new IndexedDBHostMsg_CursorDestroyed( idb_cursor_id_)); + IndexedDBDispatcher* dispatcher = + RenderThreadImpl::current()->indexed_db_dispatcher(); + dispatcher->CursorDestroyed(idb_cursor_id_); } unsigned short RendererWebIDBCursorImpl::direction() const { @@ -74,3 +72,12 @@ void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks, RenderThreadImpl::current()->indexed_db_dispatcher(); dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec); } + +void RendererWebIDBCursorImpl::SetKeyAndValue( + const IndexedDBKey& key, + const IndexedDBKey& primary_key, + const content::SerializedScriptValue& value) { + key_ = key; + primary_key_ = primary_key; + value_ = value; +} diff --git a/content/renderer/renderer_webidbcursor_impl.h b/content/renderer/renderer_webidbcursor_impl.h index bb1c165..fbca6b2 100644 --- a/content/renderer/renderer_webidbcursor_impl.h +++ b/content/renderer/renderer_webidbcursor_impl.h @@ -15,9 +15,7 @@ class RendererWebIDBCursorImpl : public WebKit::WebIDBCursor { public: - RendererWebIDBCursorImpl(int32 idb_cursor_id, const IndexedDBKey& key, - const IndexedDBKey& primary_key, - const content::SerializedScriptValue& value); + RendererWebIDBCursorImpl(int32 idb_cursor_id); virtual ~RendererWebIDBCursorImpl(); virtual unsigned short direction() const; @@ -33,11 +31,14 @@ class RendererWebIDBCursorImpl : public WebKit::WebIDBCursor { virtual void deleteFunction(WebKit::WebIDBCallbacks* callback, WebKit::WebExceptionCode& ec); + void SetKeyAndValue(const IndexedDBKey& key, const IndexedDBKey& primary_key, + const content::SerializedScriptValue& value); + private: int32 idb_cursor_id_; - const IndexedDBKey key_; - const IndexedDBKey primary_key_; - const content::SerializedScriptValue value_; + IndexedDBKey key_; + IndexedDBKey primary_key_; + content::SerializedScriptValue value_; }; #endif // CONTENT_RENDERER_RENDERER_WEBIDBCURSOR_IMPL_H_ |