Chromium Code Reviews| Index: content/child/indexed_db/proxy_webidbcursor_impl.cc |
| diff --git a/content/child/indexed_db/proxy_webidbcursor_impl.cc b/content/child/indexed_db/proxy_webidbcursor_impl.cc |
| index db2a348dbc6550e4042ed97e8328070805d4b069..6b517e9dd57fcd058fbdb7c0eb6156452b8fd844 100644 |
| --- a/content/child/indexed_db/proxy_webidbcursor_impl.cc |
| +++ b/content/child/indexed_db/proxy_webidbcursor_impl.cc |
| @@ -48,6 +48,10 @@ void RendererWebIDBCursorImpl::advance(unsigned long count, |
| IndexedDBDispatcher* dispatcher = |
| IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
| scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| + if (count <= prefetch_keys_.size()) { |
| + CachedAdvance(count, callbacks.get()); |
| + return; |
| + } |
| ResetPrefetchCache(); |
| dispatcher->RequestIDBCursorAdvance( |
| count, callbacks.release(), ipc_cursor_id_); |
| @@ -105,11 +109,11 @@ void RendererWebIDBCursorImpl::continueFunction( |
| void RendererWebIDBCursorImpl::postSuccessHandlerCallback() { |
| pending_onsuccess_callbacks_--; |
| - // If the onsuccess callback called continue() on the cursor again, |
| - // and that continue was served by the prefetch cache, then |
| - // pending_onsuccess_callbacks_ would be incremented. |
| - // If not, it means the callback did something else, or nothing at all, |
| - // in which case we need to reset the cache. |
| + // If the onsuccess callback called continue()/advance() on the cursor |
| + // again, and that request was served by the prefetch cache, then |
| + // pending_onsuccess_callbacks_ would be incremented. If not, it means the |
| + // callback did something else, or nothing at all, in which case we need to |
| + // reset the cache. |
| if (pending_onsuccess_callbacks_ == 0) |
| ResetPrefetchCache(); |
| @@ -127,22 +131,38 @@ void RendererWebIDBCursorImpl::SetPrefetchData( |
| pending_onsuccess_callbacks_ = 0; |
| } |
| +void RendererWebIDBCursorImpl::CachedAdvance(unsigned long count, |
| + WebIDBCallbacks* callbacks) { |
| + DCHECK_GE(prefetch_keys_.size(), count); |
| + DCHECK_EQ(prefetch_primary_keys_.size(), prefetch_keys_.size()); |
| + DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size()); |
| + |
| + while (count > 1) { |
|
jsbell
2013/12/12 00:18:44
If we think this will be common we could replace t
alecflett
2013/12/19 00:41:39
I'd do that in another patch under the umbrella of
|
| + prefetch_keys_.pop_front(); |
| + prefetch_primary_keys_.pop_front(); |
| + prefetch_values_.pop_front(); |
| + ++used_prefetches_; |
| + --count; |
| + } |
| + |
| + CachedContinue(callbacks); |
| +} |
| + |
| void RendererWebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { |
| DCHECK_GT(prefetch_keys_.size(), 0ul); |
| - DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); |
| - DCHECK(prefetch_values_.size() == prefetch_keys_.size()); |
| + DCHECK_EQ(prefetch_primary_keys_.size(), prefetch_keys_.size()); |
| + DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size()); |
| IndexedDBKey key = prefetch_keys_.front(); |
| IndexedDBKey primary_key = prefetch_primary_keys_.front(); |
| - // this could be a real problem.. we need 2 CachedContinues |
| WebData value = prefetch_values_.front(); |
| prefetch_keys_.pop_front(); |
| prefetch_primary_keys_.pop_front(); |
| prefetch_values_.pop_front(); |
| - used_prefetches_++; |
| + ++used_prefetches_; |
| - pending_onsuccess_callbacks_++; |
| + ++pending_onsuccess_callbacks_; |
| callbacks->onSuccess(WebIDBKeyBuilder::Build(key), |
| WebIDBKeyBuilder::Build(primary_key), value); |