| Index: content/browser/indexed_db/indexed_db_cursor.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_cursor.cc b/content/browser/indexed_db/indexed_db_cursor.cc
|
| index a029b08242f58b2e1acc888ce612f1f9e3760cda..f1713c56874c391c4b439f1ea4fb0ea9fb01b7ab 100644
|
| --- a/content/browser/indexed_db/indexed_db_cursor.cc
|
| +++ b/content/browser/indexed_db/indexed_db_cursor.cc
|
| @@ -15,8 +15,15 @@
|
| #include "content/browser/indexed_db/indexed_db_tracing.h"
|
| #include "content/browser/indexed_db/indexed_db_transaction.h"
|
| #include "content/browser/indexed_db/indexed_db_value.h"
|
| +#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
|
|
|
| namespace content {
|
| +namespace {
|
| +IndexedDBDatabaseError CreateTransactionAbortedError() {
|
| + return IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
|
| + "Transaction was aborted.");
|
| +}
|
| +} // namespace
|
|
|
| IndexedDBCursor::IndexedDBCursor(
|
| std::unique_ptr<IndexedDBBackingStore::Cursor> cursor,
|
| @@ -27,36 +34,52 @@ IndexedDBCursor::IndexedDBCursor(
|
| cursor_type_(cursor_type),
|
| transaction_(transaction),
|
| cursor_(std::move(cursor)),
|
| - closed_(false) {
|
| - transaction_->RegisterOpenCursor(this);
|
| -}
|
| + closed_(false),
|
| + ptr_factory_(this) {}
|
|
|
| -IndexedDBCursor::~IndexedDBCursor() {
|
| - transaction_->UnregisterOpenCursor(this);
|
| -}
|
| +IndexedDBCursor::~IndexedDBCursor() {}
|
|
|
| void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key,
|
| std::unique_ptr<IndexedDBKey> primary_key,
|
| scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| IDB_TRACE("IndexedDBCursor::Continue");
|
|
|
| + if (!transaction_) {
|
| + callbacks->OnError(CreateTransactionAbortedError());
|
| + return;
|
| + }
|
| +
|
| transaction_->ScheduleTask(
|
| - task_type_,
|
| - base::Bind(&IndexedDBCursor::CursorIterationOperation,
|
| - this,
|
| - base::Passed(&key),
|
| - base::Passed(&primary_key),
|
| - callbacks));
|
| + task_type_, base::Bind(&IndexedDBCursor::CursorIterationOperation,
|
| + ptr_factory_.GetWeakPtr(), base::Passed(&key),
|
| + base::Passed(&primary_key), callbacks));
|
| }
|
|
|
| void IndexedDBCursor::Advance(uint32_t count,
|
| scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| IDB_TRACE("IndexedDBCursor::Advance");
|
|
|
| + if (!transaction_) {
|
| + callbacks->OnError(CreateTransactionAbortedError());
|
| + return;
|
| + }
|
| +
|
| transaction_->ScheduleTask(
|
| - task_type_,
|
| - base::Bind(
|
| - &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks));
|
| + task_type_, base::Bind(&IndexedDBCursor::CursorAdvanceOperation,
|
| + ptr_factory_.GetWeakPtr(), count, callbacks));
|
| +}
|
| +
|
| +void IndexedDBCursor::Close() {
|
| + IDB_TRACE("IndexedDBCursor::Close");
|
| + closed_ = true;
|
| + cursor_.reset();
|
| + saved_cursor_.reset();
|
| + transaction_ = nullptr;
|
| +}
|
| +
|
| +void IndexedDBCursor::RemoveCursorFromTransaction() {
|
| + if (transaction_)
|
| + transaction_->UnregisterOpenCursor(this);
|
| }
|
|
|
| void IndexedDBCursor::CursorAdvanceOperation(
|
| @@ -104,12 +127,15 @@ void IndexedDBCursor::PrefetchContinue(
|
| scoped_refptr<IndexedDBCallbacks> callbacks) {
|
| IDB_TRACE("IndexedDBCursor::PrefetchContinue");
|
|
|
| + if (!transaction_) {
|
| + callbacks->OnError(CreateTransactionAbortedError());
|
| + return;
|
| + }
|
| +
|
| transaction_->ScheduleTask(
|
| task_type_,
|
| base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation,
|
| - this,
|
| - number_to_fetch,
|
| - callbacks));
|
| + ptr_factory_.GetWeakPtr(), number_to_fetch, callbacks));
|
| }
|
|
|
| void IndexedDBCursor::CursorPrefetchIterationOperation(
|
| @@ -197,11 +223,4 @@ leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches,
|
| return s;
|
| }
|
|
|
| -void IndexedDBCursor::Close() {
|
| - IDB_TRACE("IndexedDBCursor::Close");
|
| - closed_ = true;
|
| - cursor_.reset();
|
| - saved_cursor_.reset();
|
| -}
|
| -
|
| } // namespace content
|
|
|