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

Side by Side Diff: content/browser/indexed_db/indexed_db_cursor.cc

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: comments & rebase 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 unified diff | Download patch
OLDNEW
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 {
21 namespace {
22 IndexedDBDatabaseError CreateTransactionAbortedError() {
23 return IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
24 "Transaction was aborted.");
25 }
26 } // namespace
20 27
21 IndexedDBCursor::IndexedDBCursor( 28 IndexedDBCursor::IndexedDBCursor(
22 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, 29 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor,
23 indexed_db::CursorType cursor_type, 30 indexed_db::CursorType cursor_type,
24 blink::WebIDBTaskType task_type, 31 blink::WebIDBTaskType task_type,
25 IndexedDBTransaction* transaction) 32 IndexedDBTransaction* transaction)
26 : task_type_(task_type), 33 : task_type_(task_type),
27 cursor_type_(cursor_type), 34 cursor_type_(cursor_type),
28 transaction_(transaction), 35 transaction_(transaction),
29 cursor_(std::move(cursor)), 36 cursor_(std::move(cursor)),
30 closed_(false) { 37 closed_(false),
31 transaction_->RegisterOpenCursor(this); 38 ptr_factory_(this) {}
32 }
33 39
34 IndexedDBCursor::~IndexedDBCursor() { 40 IndexedDBCursor::~IndexedDBCursor() {}
35 transaction_->UnregisterOpenCursor(this);
36 }
37 41
38 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key, 42 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key,
39 std::unique_ptr<IndexedDBKey> primary_key, 43 std::unique_ptr<IndexedDBKey> primary_key,
40 scoped_refptr<IndexedDBCallbacks> callbacks) { 44 scoped_refptr<IndexedDBCallbacks> callbacks) {
41 IDB_TRACE("IndexedDBCursor::Continue"); 45 IDB_TRACE("IndexedDBCursor::Continue");
42 46
47 if (!transaction_) {
48 callbacks->OnError(CreateTransactionAbortedError());
49 return;
50 }
51
43 transaction_->ScheduleTask( 52 transaction_->ScheduleTask(
44 task_type_, 53 task_type_, base::Bind(&IndexedDBCursor::CursorIterationOperation,
45 base::Bind(&IndexedDBCursor::CursorIterationOperation, 54 ptr_factory_.GetWeakPtr(), base::Passed(&key),
46 this, 55 base::Passed(&primary_key), callbacks));
47 base::Passed(&key),
48 base::Passed(&primary_key),
49 callbacks));
50 } 56 }
51 57
52 void IndexedDBCursor::Advance(uint32_t count, 58 void IndexedDBCursor::Advance(uint32_t count,
53 scoped_refptr<IndexedDBCallbacks> callbacks) { 59 scoped_refptr<IndexedDBCallbacks> callbacks) {
54 IDB_TRACE("IndexedDBCursor::Advance"); 60 IDB_TRACE("IndexedDBCursor::Advance");
55 61
62 if (!transaction_) {
63 callbacks->OnError(CreateTransactionAbortedError());
64 return;
65 }
66
56 transaction_->ScheduleTask( 67 transaction_->ScheduleTask(
57 task_type_, 68 task_type_, base::Bind(&IndexedDBCursor::CursorAdvanceOperation,
58 base::Bind( 69 ptr_factory_.GetWeakPtr(), count, callbacks));
59 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); 70 }
71
72 void IndexedDBCursor::Close() {
73 IDB_TRACE("IndexedDBCursor::Close");
74 closed_ = true;
75 cursor_.reset();
76 saved_cursor_.reset();
77 transaction_ = nullptr;
78 }
79
80 void IndexedDBCursor::RemoveCursorFromTransaction() {
81 if (transaction_)
82 transaction_->UnregisterOpenCursor(this);
60 } 83 }
61 84
62 void IndexedDBCursor::CursorAdvanceOperation( 85 void IndexedDBCursor::CursorAdvanceOperation(
63 uint32_t count, 86 uint32_t count,
64 scoped_refptr<IndexedDBCallbacks> callbacks, 87 scoped_refptr<IndexedDBCallbacks> callbacks,
65 IndexedDBTransaction* /*transaction*/) { 88 IndexedDBTransaction* /*transaction*/) {
66 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); 89 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation");
67 leveldb::Status s; 90 leveldb::Status s;
68 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will 91 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will
69 // properly fail, caller will not know why, and any corruption 92 // properly fail, caller will not know why, and any corruption
(...skipping 27 matching lines...) Expand all
97 } 120 }
98 121
99 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); 122 callbacks->OnSuccess(this->key(), this->primary_key(), Value());
100 } 123 }
101 124
102 void IndexedDBCursor::PrefetchContinue( 125 void IndexedDBCursor::PrefetchContinue(
103 int number_to_fetch, 126 int number_to_fetch,
104 scoped_refptr<IndexedDBCallbacks> callbacks) { 127 scoped_refptr<IndexedDBCallbacks> callbacks) {
105 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); 128 IDB_TRACE("IndexedDBCursor::PrefetchContinue");
106 129
130 if (!transaction_) {
131 callbacks->OnError(CreateTransactionAbortedError());
132 return;
133 }
134
107 transaction_->ScheduleTask( 135 transaction_->ScheduleTask(
108 task_type_, 136 task_type_,
109 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, 137 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation,
110 this, 138 ptr_factory_.GetWeakPtr(), number_to_fetch, callbacks));
111 number_to_fetch,
112 callbacks));
113 } 139 }
114 140
115 void IndexedDBCursor::CursorPrefetchIterationOperation( 141 void IndexedDBCursor::CursorPrefetchIterationOperation(
116 int number_to_fetch, 142 int number_to_fetch,
117 scoped_refptr<IndexedDBCallbacks> callbacks, 143 scoped_refptr<IndexedDBCallbacks> callbacks,
118 IndexedDBTransaction* /*transaction*/) { 144 IndexedDBTransaction* /*transaction*/) {
119 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); 145 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation");
120 146
121 std::vector<IndexedDBKey> found_keys; 147 std::vector<IndexedDBKey> found_keys;
122 std::vector<IndexedDBKey> found_primary_keys; 148 std::vector<IndexedDBKey> found_primary_keys;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 DCHECK_GT(used_prefetches, 0); 216 DCHECK_GT(used_prefetches, 0);
191 for (int i = 0; i < used_prefetches - 1; ++i) { 217 for (int i = 0; i < used_prefetches - 1; ++i) {
192 bool ok = cursor_->Continue(&s); 218 bool ok = cursor_->Continue(&s);
193 DCHECK(ok); 219 DCHECK(ok);
194 } 220 }
195 } 221 }
196 222
197 return s; 223 return s;
198 } 224 }
199 225
200 void IndexedDBCursor::Close() {
201 IDB_TRACE("IndexedDBCursor::Close");
202 closed_ = true;
203 cursor_.reset();
204 saved_cursor_.reset();
205 }
206
207 } // namespace content 226 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698