Chromium Code Reviews| 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 if (!cursor_ || !cursor_->Advance(count, s)) { | |
| 64 cursor_.reset(); | 65 cursor_.reset(); |
| 65 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 66 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 66 return; | 67 return; |
| 67 } | 68 } |
| 68 | 69 |
| 70 if (!s.ok()) { | |
|
jsbell
2014/04/14 20:44:20
Won't Advance() return false if !s.ok() ?
cmumford
2014/04/14 23:39:23
Done.
| |
| 71 // TODO(cmumford): Handle corruption | |
| 72 if (s.IsCorruption()) { | |
|
jsbell
2014/04/14 20:44:20
Remove this placeholder code, make the TODO more v
cmumford
2014/04/14 23:39:23
Yeah, I shouldn't have left this block in there. I
| |
| 73 } | |
| 74 return; | |
|
jsbell
2014/04/14 20:44:20
Wouldn't this mean that the callbacks (i.e. reques
cmumford
2014/04/14 23:39:23
Done.
| |
| 75 } | |
| 76 | |
| 69 callbacks->OnSuccess(key(), primary_key(), Value()); | 77 callbacks->OnSuccess(key(), primary_key(), Value()); |
| 70 } | 78 } |
| 71 | 79 |
| 72 void IndexedDBCursor::CursorIterationOperation( | 80 void IndexedDBCursor::CursorIterationOperation( |
| 73 scoped_ptr<IndexedDBKey> key, | 81 scoped_ptr<IndexedDBKey> key, |
| 74 scoped_ptr<IndexedDBKey> primary_key, | 82 scoped_ptr<IndexedDBKey> primary_key, |
| 75 scoped_refptr<IndexedDBCallbacks> callbacks, | 83 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 76 IndexedDBTransaction* /*transaction*/) { | 84 IndexedDBTransaction* /*transaction*/) { |
| 77 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); | 85 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); |
| 78 if (!cursor_ || | 86 leveldb::Status s; |
| 79 !cursor_->Continue( | 87 if (!cursor_ || !cursor_->Continue(key.get(), |
| 80 key.get(), primary_key.get(), IndexedDBBackingStore::Cursor::SEEK)) { | 88 primary_key.get(), |
| 89 IndexedDBBackingStore::Cursor::SEEK, | |
| 90 s)) { | |
|
jsbell
2014/04/14 20:44:20
Does this need a corresponding check for s.ok() ?
cmumford
2014/04/14 23:39:23
Done. Also added TODO for handling of corrupted db
| |
| 81 cursor_.reset(); | 91 cursor_.reset(); |
| 82 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 92 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 83 return; | 93 return; |
| 84 } | 94 } |
| 85 | 95 |
| 86 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); | 96 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); |
| 87 } | 97 } |
| 88 | 98 |
| 89 void IndexedDBCursor::PrefetchContinue( | 99 void IndexedDBCursor::PrefetchContinue( |
| 90 int number_to_fetch, | 100 int number_to_fetch, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 105 IndexedDBTransaction* /*transaction*/) { | 115 IndexedDBTransaction* /*transaction*/) { |
| 106 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); | 116 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); |
| 107 | 117 |
| 108 std::vector<IndexedDBKey> found_keys; | 118 std::vector<IndexedDBKey> found_keys; |
| 109 std::vector<IndexedDBKey> found_primary_keys; | 119 std::vector<IndexedDBKey> found_primary_keys; |
| 110 std::vector<IndexedDBValue> found_values; | 120 std::vector<IndexedDBValue> found_values; |
| 111 | 121 |
| 112 saved_cursor_.reset(); | 122 saved_cursor_.reset(); |
| 113 const size_t max_size_estimate = 10 * 1024 * 1024; | 123 const size_t max_size_estimate = 10 * 1024 * 1024; |
| 114 size_t size_estimate = 0; | 124 size_t size_estimate = 0; |
| 125 leveldb::Status s; | |
| 115 | 126 |
| 116 for (int i = 0; i < number_to_fetch; ++i) { | 127 for (int i = 0; i < number_to_fetch; ++i) { |
| 117 if (!cursor_ || !cursor_->Continue()) { | 128 if (!cursor_ || !cursor_->Continue(s)) { |
| 118 cursor_.reset(); | 129 cursor_.reset(); |
| 119 break; | 130 break; |
| 120 } | 131 } |
| 121 | 132 |
| 122 if (i == 0) { | 133 if (i == 0) { |
| 123 // First prefetched result is always used, so that's the position | 134 // First prefetched result is always used, so that's the position |
| 124 // a cursor should be reset to if the prefetch is invalidated. | 135 // a cursor should be reset to if the prefetch is invalidated. |
| 125 saved_cursor_.reset(cursor_->Clone()); | 136 saved_cursor_.reset(cursor_->Clone()); |
| 126 } | 137 } |
| 127 | 138 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 142 default: | 153 default: |
| 143 NOTREACHED(); | 154 NOTREACHED(); |
| 144 } | 155 } |
| 145 size_estimate += cursor_->key().size_estimate(); | 156 size_estimate += cursor_->key().size_estimate(); |
| 146 size_estimate += cursor_->primary_key().size_estimate(); | 157 size_estimate += cursor_->primary_key().size_estimate(); |
| 147 | 158 |
| 148 if (size_estimate > max_size_estimate) | 159 if (size_estimate > max_size_estimate) |
| 149 break; | 160 break; |
| 150 } | 161 } |
| 151 | 162 |
| 163 if (!s.ok()) { | |
|
jsbell
2014/04/14 20:44:20
As above.
cmumford
2014/04/14 23:39:23
Done.
| |
| 164 // TODO(cmumford): Handle corruption | |
| 165 if (s.IsCorruption()) { | |
| 166 } | |
| 167 return; | |
| 168 } | |
| 169 | |
| 152 if (!found_keys.size()) { | 170 if (!found_keys.size()) { |
| 153 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); | 171 callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
| 154 return; | 172 return; |
| 155 } | 173 } |
| 156 | 174 |
| 157 callbacks->OnSuccessWithPrefetch( | 175 callbacks->OnSuccessWithPrefetch( |
| 158 found_keys, found_primary_keys, found_values); | 176 found_keys, found_primary_keys, found_values); |
| 159 } | 177 } |
| 160 | 178 |
| 161 void IndexedDBCursor::PrefetchReset(int used_prefetches, | 179 leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches, |
| 162 int /* unused_prefetches */) { | 180 int /* unused_prefetches */) { |
| 163 IDB_TRACE("IndexedDBCursor::PrefetchReset"); | 181 IDB_TRACE("IndexedDBCursor::PrefetchReset"); |
| 164 cursor_.swap(saved_cursor_); | 182 cursor_.swap(saved_cursor_); |
| 165 saved_cursor_.reset(); | 183 saved_cursor_.reset(); |
| 184 leveldb::Status s; | |
|
jsbell
2014/04/14 20:44:20
Initialized to the default here (i.e. OK), but els
cmumford
2014/04/14 23:39:23
Else where I've been setting to Status::OK() only
| |
| 166 | 185 |
| 167 if (closed_) | 186 if (closed_) |
| 168 return; | 187 return s; |
| 169 if (cursor_) { | 188 if (cursor_) { |
| 170 // First prefetched result is always used. | 189 // First prefetched result is always used. |
| 171 DCHECK_GT(used_prefetches, 0); | 190 DCHECK_GT(used_prefetches, 0); |
| 172 for (int i = 0; i < used_prefetches - 1; ++i) { | 191 for (int i = 0; i < used_prefetches - 1; ++i) { |
| 173 bool ok = cursor_->Continue(); | 192 bool ok = cursor_->Continue(s); |
| 174 DCHECK(ok); | 193 DCHECK(ok); |
|
jsbell
2014/04/14 20:44:20
Is this DCHECK is invalid in the face of corruptio
cmumford
2014/04/14 23:39:23
Yes, but false is also returned on other errors. I
| |
| 175 } | 194 } |
| 176 } | 195 } |
| 196 | |
| 197 return s; | |
| 177 } | 198 } |
| 178 | 199 |
| 179 void IndexedDBCursor::Close() { | 200 void IndexedDBCursor::Close() { |
| 180 IDB_TRACE("IndexedDBCursor::Close"); | 201 IDB_TRACE("IndexedDBCursor::Close"); |
| 181 closed_ = true; | 202 closed_ = true; |
| 182 cursor_.reset(); | 203 cursor_.reset(); |
| 183 saved_cursor_.reset(); | 204 saved_cursor_.reset(); |
| 184 } | 205 } |
| 185 | 206 |
| 186 } // namespace content | 207 } // namespace content |
| OLD | NEW |