Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1368)

Unified Diff: content/browser/indexed_db/indexed_db_cursor.cc

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: updated unittests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a8678ce90c539d1e2396fee207a9e76c3fa619c6 100644
--- a/content/browser/indexed_db/indexed_db_cursor.cc
+++ b/content/browser/indexed_db/indexed_db_cursor.cc
@@ -15,6 +15,7 @@
#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 {
@@ -27,36 +28,54 @@ 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(IndexedDBDatabaseError(
cmumford 2016/11/04 23:33:12 nit: IndexedDBDatabaseError is created three times
dmurph 2016/11/07 20:05:23 Done.
+ blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted."));
+ 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(IndexedDBDatabaseError(
+ blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted."));
+ 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 +123,16 @@ void IndexedDBCursor::PrefetchContinue(
scoped_refptr<IndexedDBCallbacks> callbacks) {
IDB_TRACE("IndexedDBCursor::PrefetchContinue");
+ if (!transaction_) {
+ callbacks->OnError(IndexedDBDatabaseError(
+ blink::WebIDBDatabaseExceptionAbortError, "Transaction was aborted."));
+ 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 +220,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

Powered by Google App Engine
This is Rietveld 408576698