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/browser | |
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/browser')
4 files changed, 41 insertions, 7 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(); |