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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 13 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 14 #include "content/browser/indexed_db/indexed_db_database_error.h" | 14 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 15 #include "content/browser/indexed_db/indexed_db_tracing.h" | 15 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 16 #include "content/browser/indexed_db/indexed_db_transaction.h" | 16 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 17 #include "content/browser/indexed_db/indexed_db_value.h" | 17 #include "content/browser/indexed_db/indexed_db_value.h" |
| 18 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" | |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 IndexedDBCursor::IndexedDBCursor( | 22 IndexedDBCursor::IndexedDBCursor( |
| 22 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, | 23 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, |
| 23 indexed_db::CursorType cursor_type, | 24 indexed_db::CursorType cursor_type, |
| 24 blink::WebIDBTaskType task_type, | 25 blink::WebIDBTaskType task_type, |
| 25 IndexedDBTransaction* transaction) | 26 IndexedDBTransaction* transaction) |
| 26 : task_type_(task_type), | 27 : task_type_(task_type), |
| 27 cursor_type_(cursor_type), | 28 cursor_type_(cursor_type), |
| 28 transaction_(transaction), | 29 transaction_(transaction), |
| 29 cursor_(std::move(cursor)), | 30 cursor_(std::move(cursor)), |
| 30 closed_(false) { | 31 closed_(false), |
| 31 transaction_->RegisterOpenCursor(this); | 32 ptr_factory_(this) {} |
| 32 } | |
| 33 | 33 |
| 34 IndexedDBCursor::~IndexedDBCursor() { | 34 IndexedDBCursor::~IndexedDBCursor() {} |
| 35 transaction_->UnregisterOpenCursor(this); | |
| 36 } | |
| 37 | 35 |
| 38 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key, | 36 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key, |
| 39 std::unique_ptr<IndexedDBKey> primary_key, | 37 std::unique_ptr<IndexedDBKey> primary_key, |
| 40 scoped_refptr<IndexedDBCallbacks> callbacks) { | 38 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 41 IDB_TRACE("IndexedDBCursor::Continue"); | 39 IDB_TRACE("IndexedDBCursor::Continue"); |
| 42 | 40 |
| 41 if (!transaction_) { | |
| 42 callbacks->OnError(IndexedDBDatabaseError( | |
|
cmumford
2016/11/04 23:33:12
nit: IndexedDBDatabaseError is created three times
dmurph
2016/11/07 20:05:23
Done.
| |
| 43 blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted.")); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 43 transaction_->ScheduleTask( | 47 transaction_->ScheduleTask( |
| 44 task_type_, | 48 task_type_, base::Bind(&IndexedDBCursor::CursorIterationOperation, |
| 45 base::Bind(&IndexedDBCursor::CursorIterationOperation, | 49 ptr_factory_.GetWeakPtr(), base::Passed(&key), |
| 46 this, | 50 base::Passed(&primary_key), callbacks)); |
| 47 base::Passed(&key), | |
| 48 base::Passed(&primary_key), | |
| 49 callbacks)); | |
| 50 } | 51 } |
| 51 | 52 |
| 52 void IndexedDBCursor::Advance(uint32_t count, | 53 void IndexedDBCursor::Advance(uint32_t count, |
| 53 scoped_refptr<IndexedDBCallbacks> callbacks) { | 54 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 54 IDB_TRACE("IndexedDBCursor::Advance"); | 55 IDB_TRACE("IndexedDBCursor::Advance"); |
| 55 | 56 |
| 57 if (!transaction_) { | |
| 58 callbacks->OnError(IndexedDBDatabaseError( | |
| 59 blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted.")); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 56 transaction_->ScheduleTask( | 63 transaction_->ScheduleTask( |
| 57 task_type_, | 64 task_type_, base::Bind(&IndexedDBCursor::CursorAdvanceOperation, |
| 58 base::Bind( | 65 ptr_factory_.GetWeakPtr(), count, callbacks)); |
| 59 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); | 66 } |
| 67 | |
| 68 void IndexedDBCursor::Close() { | |
| 69 IDB_TRACE("IndexedDBCursor::Close"); | |
| 70 closed_ = true; | |
| 71 cursor_.reset(); | |
| 72 saved_cursor_.reset(); | |
| 73 transaction_ = nullptr; | |
| 74 } | |
| 75 | |
| 76 void IndexedDBCursor::RemoveCursorFromTransaction() { | |
| 77 if (transaction_) | |
| 78 transaction_->UnregisterOpenCursor(this); | |
| 60 } | 79 } |
| 61 | 80 |
| 62 void IndexedDBCursor::CursorAdvanceOperation( | 81 void IndexedDBCursor::CursorAdvanceOperation( |
| 63 uint32_t count, | 82 uint32_t count, |
| 64 scoped_refptr<IndexedDBCallbacks> callbacks, | 83 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 65 IndexedDBTransaction* /*transaction*/) { | 84 IndexedDBTransaction* /*transaction*/) { |
| 66 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); | 85 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); |
| 67 leveldb::Status s; | 86 leveldb::Status s; |
| 68 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will | 87 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
| 69 // properly fail, caller will not know why, and any corruption | 88 // properly fail, caller will not know why, and any corruption |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 97 } | 116 } |
| 98 | 117 |
| 99 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); | 118 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); |
| 100 } | 119 } |
| 101 | 120 |
| 102 void IndexedDBCursor::PrefetchContinue( | 121 void IndexedDBCursor::PrefetchContinue( |
| 103 int number_to_fetch, | 122 int number_to_fetch, |
| 104 scoped_refptr<IndexedDBCallbacks> callbacks) { | 123 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 105 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); | 124 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); |
| 106 | 125 |
| 126 if (!transaction_) { | |
| 127 callbacks->OnError(IndexedDBDatabaseError( | |
| 128 blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted.")); | |
| 129 return; | |
| 130 } | |
| 131 | |
| 107 transaction_->ScheduleTask( | 132 transaction_->ScheduleTask( |
| 108 task_type_, | 133 task_type_, |
| 109 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, | 134 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, |
| 110 this, | 135 ptr_factory_.GetWeakPtr(), number_to_fetch, callbacks)); |
| 111 number_to_fetch, | |
| 112 callbacks)); | |
| 113 } | 136 } |
| 114 | 137 |
| 115 void IndexedDBCursor::CursorPrefetchIterationOperation( | 138 void IndexedDBCursor::CursorPrefetchIterationOperation( |
| 116 int number_to_fetch, | 139 int number_to_fetch, |
| 117 scoped_refptr<IndexedDBCallbacks> callbacks, | 140 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 118 IndexedDBTransaction* /*transaction*/) { | 141 IndexedDBTransaction* /*transaction*/) { |
| 119 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); | 142 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); |
| 120 | 143 |
| 121 std::vector<IndexedDBKey> found_keys; | 144 std::vector<IndexedDBKey> found_keys; |
| 122 std::vector<IndexedDBKey> found_primary_keys; | 145 std::vector<IndexedDBKey> found_primary_keys; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 DCHECK_GT(used_prefetches, 0); | 213 DCHECK_GT(used_prefetches, 0); |
| 191 for (int i = 0; i < used_prefetches - 1; ++i) { | 214 for (int i = 0; i < used_prefetches - 1; ++i) { |
| 192 bool ok = cursor_->Continue(&s); | 215 bool ok = cursor_->Continue(&s); |
| 193 DCHECK(ok); | 216 DCHECK(ok); |
| 194 } | 217 } |
| 195 } | 218 } |
| 196 | 219 |
| 197 return s; | 220 return s; |
| 198 } | 221 } |
| 199 | 222 |
| 200 void IndexedDBCursor::Close() { | |
| 201 IDB_TRACE("IndexedDBCursor::Close"); | |
| 202 closed_ = true; | |
| 203 cursor_.reset(); | |
| 204 saved_cursor_.reset(); | |
| 205 } | |
| 206 | |
| 207 } // namespace content | 223 } // namespace content |
| OLD | NEW |