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

Side by Side Diff: content/browser/indexed_db/indexed_db_cursor.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
« no previous file with comments | « no previous file | content/child/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser/indexed_db/indexed_db_cursor.h" 5 #include "content/browser/indexed_db/indexed_db_cursor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/indexed_db/indexed_db_callbacks.h" 9 #include "content/browser/indexed_db/indexed_db_callbacks.h"
10 #include "content/browser/indexed_db/indexed_db_database_error.h" 10 #include "content/browser/indexed_db/indexed_db_database_error.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void IndexedDBCursor::CursorPrefetchIterationOperation( 101 void IndexedDBCursor::CursorPrefetchIterationOperation(
102 int number_to_fetch, 102 int number_to_fetch,
103 scoped_refptr<IndexedDBCallbacks> callbacks, 103 scoped_refptr<IndexedDBCallbacks> callbacks,
104 IndexedDBTransaction* /*transaction*/) { 104 IndexedDBTransaction* /*transaction*/) {
105 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); 105 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation");
106 106
107 std::vector<IndexedDBKey> found_keys; 107 std::vector<IndexedDBKey> found_keys;
108 std::vector<IndexedDBKey> found_primary_keys; 108 std::vector<IndexedDBKey> found_primary_keys;
109 std::vector<std::string> found_values; 109 std::vector<std::string> found_values;
110 110
111 if (cursor_) 111 saved_cursor_.reset();
112 saved_cursor_.reset(cursor_->Clone());
113 const size_t max_size_estimate = 10 * 1024 * 1024; 112 const size_t max_size_estimate = 10 * 1024 * 1024;
114 size_t size_estimate = 0; 113 size_t size_estimate = 0;
115 114
116 for (int i = 0; i < number_to_fetch; ++i) { 115 for (int i = 0; i < number_to_fetch; ++i) {
117 if (!cursor_ || !cursor_->Continue()) { 116 if (!cursor_ || !cursor_->Continue()) {
118 cursor_.reset(); 117 cursor_.reset();
119 break; 118 break;
120 } 119 }
121 120
121 if (i == 0) {
122 // First prefetched result is always used, so that's the position
123 // a cursor should be reset to if the prefetch is invalidated.
124 saved_cursor_.reset(cursor_->Clone());
125 }
126
122 found_keys.push_back(cursor_->key()); 127 found_keys.push_back(cursor_->key());
123 found_primary_keys.push_back(cursor_->primary_key()); 128 found_primary_keys.push_back(cursor_->primary_key());
124 129
125 switch (cursor_type_) { 130 switch (cursor_type_) {
126 case indexed_db::CURSOR_KEY_ONLY: 131 case indexed_db::CURSOR_KEY_ONLY:
127 found_values.push_back(std::string()); 132 found_values.push_back(std::string());
128 break; 133 break;
129 case indexed_db::CURSOR_KEY_AND_VALUE: { 134 case indexed_db::CURSOR_KEY_AND_VALUE: {
130 std::string value; 135 std::string value;
131 value.swap(*cursor_->value()); 136 value.swap(*cursor_->value());
(...skipping 13 matching lines...) Expand all
145 150
146 if (!found_keys.size()) { 151 if (!found_keys.size()) {
147 callbacks->OnSuccess(static_cast<std::string*>(NULL)); 152 callbacks->OnSuccess(static_cast<std::string*>(NULL));
148 return; 153 return;
149 } 154 }
150 155
151 callbacks->OnSuccessWithPrefetch( 156 callbacks->OnSuccessWithPrefetch(
152 found_keys, found_primary_keys, found_values); 157 found_keys, found_primary_keys, found_values);
153 } 158 }
154 159
155 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) { 160 void IndexedDBCursor::PrefetchReset(int used_prefetches,
161 int /* unused_prefetches */) {
156 IDB_TRACE("IndexedDBCursor::PrefetchReset"); 162 IDB_TRACE("IndexedDBCursor::PrefetchReset");
157 cursor_.swap(saved_cursor_); 163 cursor_.swap(saved_cursor_);
158 saved_cursor_.reset(); 164 saved_cursor_.reset();
159 165
160 if (closed_) 166 if (closed_)
161 return; 167 return;
162 if (cursor_) { 168 if (cursor_) {
163 for (int i = 0; i < used_prefetches; ++i) { 169 // First prefetched result is always used.
170 DCHECK_GT(used_prefetches, 0);
171 for (int i = 0; i < used_prefetches - 1; ++i) {
164 bool ok = cursor_->Continue(); 172 bool ok = cursor_->Continue();
165 DCHECK(ok); 173 DCHECK(ok);
166 } 174 }
167 } 175 }
168 } 176 }
169 177
170 void IndexedDBCursor::Close() { 178 void IndexedDBCursor::Close() {
171 IDB_TRACE("IndexedDBCursor::Close"); 179 IDB_TRACE("IndexedDBCursor::Close");
172 closed_ = true; 180 closed_ = true;
173 cursor_.reset(); 181 cursor_.reset();
174 saved_cursor_.reset(); 182 saved_cursor_.reset();
175 } 183 }
176 184
177 } // namespace content 185 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698