Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/child/indexed_db/webidbcursor_impl.cc

Issue 124323002: IndexedDB: Fix cursor prefetching edge cases (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test-only leak found by valgrind Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/child/indexed_db/webidbcursor_impl.h" 5 #include "content/child/indexed_db/webidbcursor_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "content/child/indexed_db/indexed_db_dispatcher.h" 9 #include "content/child/indexed_db/indexed_db_dispatcher.h"
10 #include "content/child/indexed_db/indexed_db_key_builders.h" 10 #include "content/child/indexed_db/indexed_db_key_builders.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 IndexedDBKey primary_key = prefetch_primary_keys_.front(); 154 IndexedDBKey primary_key = prefetch_primary_keys_.front();
155 WebData value = prefetch_values_.front(); 155 WebData value = prefetch_values_.front();
156 156
157 prefetch_keys_.pop_front(); 157 prefetch_keys_.pop_front();
158 prefetch_primary_keys_.pop_front(); 158 prefetch_primary_keys_.pop_front();
159 prefetch_values_.pop_front(); 159 prefetch_values_.pop_front();
160 ++used_prefetches_; 160 ++used_prefetches_;
161 161
162 ++pending_onsuccess_callbacks_; 162 ++pending_onsuccess_callbacks_;
163 163
164 if (!continue_count_) {
165 // The cache was invalidated by a call to ResetPrefetchCache()
166 // after the RequestIDBCursorPrefetch() was made. Now that the
167 // initiating continue() call has been satisfied, discard
168 // the rest of the cache.
169 ResetPrefetchCache();
170 }
171
164 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), 172 callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
165 WebIDBKeyBuilder::Build(primary_key), 173 WebIDBKeyBuilder::Build(primary_key),
166 value); 174 value);
167 } 175 }
168 176
169 void WebIDBCursorImpl::ResetPrefetchCache() { 177 void WebIDBCursorImpl::ResetPrefetchCache() {
170 continue_count_ = 0; 178 continue_count_ = 0;
171 prefetch_amount_ = kMinPrefetchAmount; 179 prefetch_amount_ = kMinPrefetchAmount;
172 180
173 if (!prefetch_keys_.size()) { 181 if (!prefetch_keys_.size()) {
174 // No prefetch cache, so no need to reset the cursor in the back-end. 182 // No prefetch cache, so no need to reset the cursor in the back-end.
175 return; 183 return;
176 } 184 }
177 185
178 IndexedDBDispatcher* dispatcher = 186 IndexedDBDispatcher* dispatcher =
179 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 187 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
180 dispatcher->RequestIDBCursorPrefetchReset( 188 dispatcher->RequestIDBCursorPrefetchReset(
181 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_); 189 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_);
182 prefetch_keys_.clear(); 190 prefetch_keys_.clear();
183 prefetch_primary_keys_.clear(); 191 prefetch_primary_keys_.clear();
184 prefetch_values_.clear(); 192 prefetch_values_.clear();
185 193
186 pending_onsuccess_callbacks_ = 0; 194 pending_onsuccess_callbacks_ = 0;
187 } 195 }
188 196
189 } // namespace content 197 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/webidbcursor_impl.h ('k') | content/child/indexed_db/webidbcursor_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698