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

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

Issue 2506773002: [IndexedDB] Integrating failures and corruption with transaction (Closed)
Patch Set: 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..0d0b6223e02d93612d1ade6e6cf12754e1c725dd 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 {
@@ -40,6 +41,13 @@ void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key,
scoped_refptr<IndexedDBCallbacks> callbacks) {
IDB_TRACE("IndexedDBCursor::Continue");
+ if (closed_) {
cmumford 2016/11/21 18:29:22 No problem with your check, but Do you think we ne
dmurph 2016/11/22 23:33:10 Done.
+ callbacks->OnError(
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
+ "The cursor has been closed."));
+ return;
+ }
+
transaction_->ScheduleTask(
task_type_,
base::Bind(&IndexedDBCursor::CursorIterationOperation,
@@ -53,57 +61,80 @@ void IndexedDBCursor::Advance(uint32_t count,
scoped_refptr<IndexedDBCallbacks> callbacks) {
IDB_TRACE("IndexedDBCursor::Advance");
+ if (closed_) {
+ callbacks->OnError(
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
+ "The cursor has been closed."));
+ return;
+ }
+
transaction_->ScheduleTask(
task_type_,
base::Bind(
&IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks));
}
-void IndexedDBCursor::CursorAdvanceOperation(
+IndexedDBTransaction::OperationResult IndexedDBCursor::CursorAdvanceOperation(
uint32_t count,
scoped_refptr<IndexedDBCallbacks> callbacks,
IndexedDBTransaction* /*transaction*/) {
+ DCHECK(cursor_);
IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation");
- leveldb::Status s;
- // TODO(cmumford): Handle this error (crbug.com/363397). Although this will
- // properly fail, caller will not know why, and any corruption
- // will be ignored.
- if (!cursor_ || !cursor_->Advance(count, &s)) {
- cursor_.reset();
- callbacks->OnSuccess(nullptr);
- return;
+ leveldb::Status s = leveldb::Status::OK();
+
+ if (cursor_->Advance(count, &s)) {
+ callbacks->OnSuccess(key(), primary_key(), Value());
+ return s;
}
- callbacks->OnSuccess(key(), primary_key(), Value());
+ Close();
+ callbacks->OnError(IndexedDBDatabaseError(
+ blink::WebIDBDatabaseExceptionUnknownError, "Error advancing cursor"));
+
+ return s;
}
-void IndexedDBCursor::CursorIterationOperation(
+IndexedDBTransaction::OperationResult IndexedDBCursor::CursorIterationOperation(
std::unique_ptr<IndexedDBKey> key,
std::unique_ptr<IndexedDBKey> primary_key,
scoped_refptr<IndexedDBCallbacks> callbacks,
IndexedDBTransaction* /*transaction*/) {
+ DCHECK(cursor_);
IDB_TRACE("IndexedDBCursor::CursorIterationOperation");
- leveldb::Status s;
- // TODO(cmumford): Handle this error (crbug.com/363397). Although this will
- // properly fail, caller will not know why, and any corruption
- // will be ignored.
- if (!cursor_ || !cursor_->Continue(key.get(),
- primary_key.get(),
- IndexedDBBackingStore::Cursor::SEEK,
- &s) || !s.ok()) {
- cursor_.reset();
- callbacks->OnSuccess(nullptr);
- return;
+ leveldb::Status s = leveldb::Status::OK();
+
+ if (!cursor_->Continue(key.get(), primary_key.get(),
+ IndexedDBBackingStore::Cursor::SEEK, &s)) {
+ if (!s.ok()) {
+ Close();
+ callbacks->OnError(
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
+ "Error advancing cursor"));
cmumford 2016/11/21 18:29:22 Tweak error message - same as AdvanceOperation abo
dmurph 2016/11/22 23:33:10 Done.
+ } else {
+ // This happens if we reach the end of the iterator and can't continue.
+ // Current behavior (if it ever gets hit) is to return a null.
+ callbacks->OnSuccess(nullptr);
+ }
+ return s;
}
callbacks->OnSuccess(this->key(), this->primary_key(), Value());
+ return s;
}
void IndexedDBCursor::PrefetchContinue(
int number_to_fetch,
scoped_refptr<IndexedDBCallbacks> callbacks) {
+ DCHECK(cursor_);
IDB_TRACE("IndexedDBCursor::PrefetchContinue");
+ if (closed_) {
+ callbacks->OnError(
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
+ "The cursor has been closed."));
+ return;
+ }
+
transaction_->ScheduleTask(
task_type_,
base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation,
@@ -112,11 +143,13 @@ void IndexedDBCursor::PrefetchContinue(
callbacks));
}
-void IndexedDBCursor::CursorPrefetchIterationOperation(
+IndexedDBTransaction::OperationResult
+IndexedDBCursor::CursorPrefetchIterationOperation(
int number_to_fetch,
scoped_refptr<IndexedDBCallbacks> callbacks,
IndexedDBTransaction* /*transaction*/) {
IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation");
+ leveldb::Status s = leveldb::Status::OK();
std::vector<IndexedDBKey> found_keys;
std::vector<IndexedDBKey> found_primary_keys;
@@ -126,15 +159,21 @@ void IndexedDBCursor::CursorPrefetchIterationOperation(
// TODO(cmumford): Use IPC::Channel::kMaximumMessageSize
const size_t max_size_estimate = 10 * 1024 * 1024;
size_t size_estimate = 0;
- leveldb::Status s;
// TODO(cmumford): Handle this error (crbug.com/363397). Although this will
// properly fail, caller will not know why, and any corruption
// will be ignored.
for (int i = 0; i < number_to_fetch; ++i) {
- if (!cursor_ || !cursor_->Continue(&s)) {
- cursor_.reset();
- break;
+ if (!cursor_->Continue(&s)) {
+ if (s.ok()) {
+ // We've reached the end, so just return what we have.
+ break;
+ }
+ Close();
+ callbacks->OnError(
+ IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
+ "Error advancing cursor"));
+ return s;
}
if (i == 0) {
@@ -169,11 +208,12 @@ void IndexedDBCursor::CursorPrefetchIterationOperation(
if (found_keys.empty()) {
callbacks->OnSuccess(nullptr);
- return;
+ return s;
}
callbacks->OnSuccessWithPrefetch(
found_keys, found_primary_keys, &found_values);
+ return s;
}
leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches,

Powered by Google App Engine
This is Rietveld 408576698