| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 task_type_, | 53 task_type_, |
| 54 base::Bind( | 54 base::Bind( |
| 55 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); | 55 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void IndexedDBCursor::CursorAdvanceOperation( | 58 void IndexedDBCursor::CursorAdvanceOperation( |
| 59 uint32 count, | 59 uint32 count, |
| 60 scoped_refptr<IndexedDBCallbacks> callbacks, | 60 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 61 IndexedDBTransaction* /*transaction*/) { | 61 IndexedDBTransaction* /*transaction*/) { |
| 62 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); | 62 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); |
| 63 if (!cursor_ || !cursor_->Advance(count)) { | 63 leveldb::Status s; |
| 64 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
| 65 // properly fail, caller will not know why, and any corruption |
| 66 // will be ignored. |
| 67 if (!cursor_ || !cursor_->Advance(count, &s)) { |
| 64 cursor_.reset(); | 68 cursor_.reset(); |
| 65 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 69 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 66 return; | 70 return; |
| 67 } | 71 } |
| 68 | 72 |
| 69 callbacks->OnSuccess(key(), primary_key(), Value()); | 73 callbacks->OnSuccess(key(), primary_key(), Value()); |
| 70 } | 74 } |
| 71 | 75 |
| 72 void IndexedDBCursor::CursorIterationOperation( | 76 void IndexedDBCursor::CursorIterationOperation( |
| 73 scoped_ptr<IndexedDBKey> key, | 77 scoped_ptr<IndexedDBKey> key, |
| 74 scoped_ptr<IndexedDBKey> primary_key, | 78 scoped_ptr<IndexedDBKey> primary_key, |
| 75 scoped_refptr<IndexedDBCallbacks> callbacks, | 79 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 76 IndexedDBTransaction* /*transaction*/) { | 80 IndexedDBTransaction* /*transaction*/) { |
| 77 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); | 81 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); |
| 78 if (!cursor_ || | 82 leveldb::Status s; |
| 79 !cursor_->Continue( | 83 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
| 80 key.get(), primary_key.get(), IndexedDBBackingStore::Cursor::SEEK)) { | 84 // properly fail, caller will not know why, and any corruption |
| 85 // will be ignored. |
| 86 if (!cursor_ || !cursor_->Continue(key.get(), |
| 87 primary_key.get(), |
| 88 IndexedDBBackingStore::Cursor::SEEK, |
| 89 &s) || !s.ok()) { |
| 81 cursor_.reset(); | 90 cursor_.reset(); |
| 82 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 91 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 83 return; | 92 return; |
| 84 } | 93 } |
| 85 | 94 |
| 86 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); | 95 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); |
| 87 } | 96 } |
| 88 | 97 |
| 89 void IndexedDBCursor::PrefetchContinue( | 98 void IndexedDBCursor::PrefetchContinue( |
| 90 int number_to_fetch, | 99 int number_to_fetch, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 IndexedDBTransaction* /*transaction*/) { | 114 IndexedDBTransaction* /*transaction*/) { |
| 106 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); | 115 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); |
| 107 | 116 |
| 108 std::vector<IndexedDBKey> found_keys; | 117 std::vector<IndexedDBKey> found_keys; |
| 109 std::vector<IndexedDBKey> found_primary_keys; | 118 std::vector<IndexedDBKey> found_primary_keys; |
| 110 std::vector<IndexedDBValue> found_values; | 119 std::vector<IndexedDBValue> found_values; |
| 111 | 120 |
| 112 saved_cursor_.reset(); | 121 saved_cursor_.reset(); |
| 113 const size_t max_size_estimate = 10 * 1024 * 1024; | 122 const size_t max_size_estimate = 10 * 1024 * 1024; |
| 114 size_t size_estimate = 0; | 123 size_t size_estimate = 0; |
| 124 leveldb::Status s; |
| 115 | 125 |
| 126 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
| 127 // properly fail, caller will not know why, and any corruption |
| 128 // will be ignored. |
| 116 for (int i = 0; i < number_to_fetch; ++i) { | 129 for (int i = 0; i < number_to_fetch; ++i) { |
| 117 if (!cursor_ || !cursor_->Continue()) { | 130 if (!cursor_ || !cursor_->Continue(&s)) { |
| 118 cursor_.reset(); | 131 cursor_.reset(); |
| 119 break; | 132 break; |
| 120 } | 133 } |
| 121 | 134 |
| 122 if (i == 0) { | 135 if (i == 0) { |
| 123 // First prefetched result is always used, so that's the position | 136 // First prefetched result is always used, so that's the position |
| 124 // a cursor should be reset to if the prefetch is invalidated. | 137 // a cursor should be reset to if the prefetch is invalidated. |
| 125 saved_cursor_.reset(cursor_->Clone()); | 138 saved_cursor_.reset(cursor_->Clone()); |
| 126 } | 139 } |
| 127 | 140 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 151 | 164 |
| 152 if (!found_keys.size()) { | 165 if (!found_keys.size()) { |
| 153 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 166 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 154 return; | 167 return; |
| 155 } | 168 } |
| 156 | 169 |
| 157 callbacks->OnSuccessWithPrefetch( | 170 callbacks->OnSuccessWithPrefetch( |
| 158 found_keys, found_primary_keys, found_values); | 171 found_keys, found_primary_keys, found_values); |
| 159 } | 172 } |
| 160 | 173 |
| 161 void IndexedDBCursor::PrefetchReset(int used_prefetches, | 174 leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches, |
| 162 int /* unused_prefetches */) { | 175 int /* unused_prefetches */) { |
| 163 IDB_TRACE("IndexedDBCursor::PrefetchReset"); | 176 IDB_TRACE("IndexedDBCursor::PrefetchReset"); |
| 164 cursor_.swap(saved_cursor_); | 177 cursor_.swap(saved_cursor_); |
| 165 saved_cursor_.reset(); | 178 saved_cursor_.reset(); |
| 179 leveldb::Status s; |
| 166 | 180 |
| 167 if (closed_) | 181 if (closed_) |
| 168 return; | 182 return s; |
| 169 if (cursor_) { | 183 if (cursor_) { |
| 170 // First prefetched result is always used. | 184 // First prefetched result is always used. |
| 171 DCHECK_GT(used_prefetches, 0); | 185 DCHECK_GT(used_prefetches, 0); |
| 172 for (int i = 0; i < used_prefetches - 1; ++i) { | 186 for (int i = 0; i < used_prefetches - 1; ++i) { |
| 173 bool ok = cursor_->Continue(); | 187 bool ok = cursor_->Continue(&s); |
| 174 DCHECK(ok); | 188 DCHECK(ok); |
| 175 } | 189 } |
| 176 } | 190 } |
| 191 |
| 192 return s; |
| 177 } | 193 } |
| 178 | 194 |
| 179 void IndexedDBCursor::Close() { | 195 void IndexedDBCursor::Close() { |
| 180 IDB_TRACE("IndexedDBCursor::Close"); | 196 IDB_TRACE("IndexedDBCursor::Close"); |
| 181 closed_ = true; | 197 closed_ = true; |
| 182 cursor_.reset(); | 198 cursor_.reset(); |
| 183 saved_cursor_.reset(); | 199 saved_cursor_.reset(); |
| 184 } | 200 } |
| 185 | 201 |
| 186 } // namespace content | 202 } // namespace content |
| OLD | NEW |