OLD | NEW |
---|---|
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 Loading... | |
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 and can't be reset. | |
123 saved_cursor_.reset(cursor_->Clone()); | |
124 } | |
125 | |
122 found_keys.push_back(cursor_->key()); | 126 found_keys.push_back(cursor_->key()); |
123 found_primary_keys.push_back(cursor_->primary_key()); | 127 found_primary_keys.push_back(cursor_->primary_key()); |
124 | 128 |
125 switch (cursor_type_) { | 129 switch (cursor_type_) { |
126 case indexed_db::CURSOR_KEY_ONLY: | 130 case indexed_db::CURSOR_KEY_ONLY: |
127 found_values.push_back(std::string()); | 131 found_values.push_back(std::string()); |
128 break; | 132 break; |
129 case indexed_db::CURSOR_KEY_AND_VALUE: { | 133 case indexed_db::CURSOR_KEY_AND_VALUE: { |
130 std::string value; | 134 std::string value; |
131 value.swap(*cursor_->value()); | 135 value.swap(*cursor_->value()); |
(...skipping 13 matching lines...) Expand all Loading... | |
145 | 149 |
146 if (!found_keys.size()) { | 150 if (!found_keys.size()) { |
147 callbacks->OnSuccess(static_cast<std::string*>(NULL)); | 151 callbacks->OnSuccess(static_cast<std::string*>(NULL)); |
148 return; | 152 return; |
149 } | 153 } |
150 | 154 |
151 callbacks->OnSuccessWithPrefetch( | 155 callbacks->OnSuccessWithPrefetch( |
152 found_keys, found_primary_keys, found_values); | 156 found_keys, found_primary_keys, found_values); |
153 } | 157 } |
154 | 158 |
155 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) { | 159 void IndexedDBCursor::PrefetchReset(int used_prefetches, |
160 int /* unused_prefetches */) { | |
156 IDB_TRACE("IndexedDBCursor::PrefetchReset"); | 161 IDB_TRACE("IndexedDBCursor::PrefetchReset"); |
162 transaction_->ScheduleTask( | |
jsbell
2014/01/03 23:05:11
I haven't convinced myself one way or another whet
jsbell
2014/01/06 17:51:55
After further reflection, this shouldn't be necess
| |
163 task_type_, | |
164 base::Bind(&IndexedDBCursor::CursorPrefetchResetOperation, | |
165 this, | |
166 used_prefetches)); | |
167 } | |
168 | |
169 void IndexedDBCursor::CursorPrefetchResetOperation( | |
170 int used_prefetches, | |
171 IndexedDBTransaction* /*transaction*/) { | |
172 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); | |
173 | |
157 cursor_.swap(saved_cursor_); | 174 cursor_.swap(saved_cursor_); |
158 saved_cursor_.reset(); | 175 saved_cursor_.reset(); |
159 | 176 |
160 if (closed_) | 177 if (closed_) |
161 return; | 178 return; |
162 if (cursor_) { | 179 if (cursor_) { |
163 for (int i = 0; i < used_prefetches; ++i) { | 180 DCHECK_GT(used_prefetches, 0); |
181 for (int i = 0; i < used_prefetches - 1; ++i) { | |
164 bool ok = cursor_->Continue(); | 182 bool ok = cursor_->Continue(); |
165 DCHECK(ok); | 183 DCHECK(ok); |
166 } | 184 } |
167 } | 185 } |
168 } | 186 } |
169 | 187 |
170 void IndexedDBCursor::Close() { | 188 void IndexedDBCursor::Close() { |
171 IDB_TRACE("IndexedDBCursor::Close"); | 189 IDB_TRACE("IndexedDBCursor::Close"); |
172 closed_ = true; | 190 closed_ = true; |
173 cursor_.reset(); | 191 cursor_.reset(); |
174 saved_cursor_.reset(); | 192 saved_cursor_.reset(); |
175 } | 193 } |
176 | 194 |
177 } // namespace content | 195 } // namespace content |
OLD | NEW |