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

Side by Side Diff: trunk/src/content/browser/indexed_db/indexed_db_cursor.cc

Issue 126263003: Revert 243344 "IndexedDB: Fix cursor prefetching edge cases" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | trunk/src/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 saved_cursor_.reset(); 111 if (cursor_)
112 saved_cursor_.reset(cursor_->Clone());
112 const size_t max_size_estimate = 10 * 1024 * 1024; 113 const size_t max_size_estimate = 10 * 1024 * 1024;
113 size_t size_estimate = 0; 114 size_t size_estimate = 0;
114 115
115 for (int i = 0; i < number_to_fetch; ++i) { 116 for (int i = 0; i < number_to_fetch; ++i) {
116 if (!cursor_ || !cursor_->Continue()) { 117 if (!cursor_ || !cursor_->Continue()) {
117 cursor_.reset(); 118 cursor_.reset();
118 break; 119 break;
119 } 120 }
120 121
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
127 found_keys.push_back(cursor_->key()); 122 found_keys.push_back(cursor_->key());
128 found_primary_keys.push_back(cursor_->primary_key()); 123 found_primary_keys.push_back(cursor_->primary_key());
129 124
130 switch (cursor_type_) { 125 switch (cursor_type_) {
131 case indexed_db::CURSOR_KEY_ONLY: 126 case indexed_db::CURSOR_KEY_ONLY:
132 found_values.push_back(std::string()); 127 found_values.push_back(std::string());
133 break; 128 break;
134 case indexed_db::CURSOR_KEY_AND_VALUE: { 129 case indexed_db::CURSOR_KEY_AND_VALUE: {
135 std::string value; 130 std::string value;
136 value.swap(*cursor_->value()); 131 value.swap(*cursor_->value());
(...skipping 13 matching lines...) Expand all
150 145
151 if (!found_keys.size()) { 146 if (!found_keys.size()) {
152 callbacks->OnSuccess(static_cast<std::string*>(NULL)); 147 callbacks->OnSuccess(static_cast<std::string*>(NULL));
153 return; 148 return;
154 } 149 }
155 150
156 callbacks->OnSuccessWithPrefetch( 151 callbacks->OnSuccessWithPrefetch(
157 found_keys, found_primary_keys, found_values); 152 found_keys, found_primary_keys, found_values);
158 } 153 }
159 154
160 void IndexedDBCursor::PrefetchReset(int used_prefetches, 155 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) {
161 int /* unused_prefetches */) {
162 IDB_TRACE("IndexedDBCursor::PrefetchReset"); 156 IDB_TRACE("IndexedDBCursor::PrefetchReset");
163 cursor_.swap(saved_cursor_); 157 cursor_.swap(saved_cursor_);
164 saved_cursor_.reset(); 158 saved_cursor_.reset();
165 159
166 if (closed_) 160 if (closed_)
167 return; 161 return;
168 if (cursor_) { 162 if (cursor_) {
169 // First prefetched result is always used. 163 for (int i = 0; i < used_prefetches; ++i) {
170 DCHECK_GT(used_prefetches, 0);
171 for (int i = 0; i < used_prefetches - 1; ++i) {
172 bool ok = cursor_->Continue(); 164 bool ok = cursor_->Continue();
173 DCHECK(ok); 165 DCHECK(ok);
174 } 166 }
175 } 167 }
176 } 168 }
177 169
178 void IndexedDBCursor::Close() { 170 void IndexedDBCursor::Close() {
179 IDB_TRACE("IndexedDBCursor::Close"); 171 IDB_TRACE("IndexedDBCursor::Close");
180 closed_ = true; 172 closed_ = true;
181 cursor_.reset(); 173 cursor_.reset();
182 saved_cursor_.reset(); 174 saved_cursor_.reset();
183 } 175 }
184 176
185 } // namespace content 177 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | trunk/src/content/child/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698