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

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

Issue 16581002: IndexedDB: Eliminate interfaces for IndexedDB{Factory,Database,Cursor} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months 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 | Annotate | Revision Log
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_impl.h" 5 #include "content/browser/indexed_db/indexed_db_cursor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/indexed_db/indexed_db_backing_store.h" 8 #include "content/browser/indexed_db/indexed_db_backing_store.h"
9 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" 9 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h"
10 #include "content/browser/indexed_db/indexed_db_database.h"
10 #include "content/browser/indexed_db/indexed_db_database_error.h" 11 #include "content/browser/indexed_db/indexed_db_database_error.h"
11 #include "content/browser/indexed_db/indexed_db_database_impl.h"
12 #include "content/browser/indexed_db/indexed_db_tracing.h" 12 #include "content/browser/indexed_db/indexed_db_tracing.h"
13 #include "content/browser/indexed_db/indexed_db_transaction.h" 13 #include "content/browser/indexed_db/indexed_db_transaction.h"
14 #include "content/common/indexed_db/indexed_db_key_range.h" 14 #include "content/common/indexed_db/indexed_db_key_range.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 class IndexedDBCursorImpl::CursorIterationOperation 18 class IndexedDBCursor::CursorIterationOperation
19 : public IndexedDBTransaction::Operation { 19 : public IndexedDBTransaction::Operation {
20 public: 20 public:
21 CursorIterationOperation(scoped_refptr<IndexedDBCursorImpl> cursor, 21 CursorIterationOperation(scoped_refptr<IndexedDBCursor> cursor,
22 scoped_ptr<IndexedDBKey> key, 22 scoped_ptr<IndexedDBKey> key,
23 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) 23 scoped_refptr<IndexedDBCallbacksWrapper> callbacks)
24 : cursor_(cursor), key_(key.Pass()), callbacks_(callbacks) {} 24 : cursor_(cursor), key_(key.Pass()), callbacks_(callbacks) {}
25 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 25 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
26 26
27 private: 27 private:
28 scoped_refptr<IndexedDBCursorImpl> cursor_; 28 scoped_refptr<IndexedDBCursor> cursor_;
29 scoped_ptr<IndexedDBKey> key_; 29 scoped_ptr<IndexedDBKey> key_;
30 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; 30 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_;
31 }; 31 };
32 32
33 class IndexedDBCursorImpl::CursorAdvanceOperation 33 class IndexedDBCursor::CursorAdvanceOperation
34 : public IndexedDBTransaction::Operation { 34 : public IndexedDBTransaction::Operation {
35 public: 35 public:
36 CursorAdvanceOperation(scoped_refptr<IndexedDBCursorImpl> cursor, 36 CursorAdvanceOperation(scoped_refptr<IndexedDBCursor> cursor,
37 uint32 count, 37 uint32 count,
38 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) 38 scoped_refptr<IndexedDBCallbacksWrapper> callbacks)
39 : cursor_(cursor), count_(count), callbacks_(callbacks) {} 39 : cursor_(cursor), count_(count), callbacks_(callbacks) {}
40 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 40 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
41 41
42 private: 42 private:
43 scoped_refptr<IndexedDBCursorImpl> cursor_; 43 scoped_refptr<IndexedDBCursor> cursor_;
44 uint32 count_; 44 uint32 count_;
45 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; 45 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_;
46 }; 46 };
47 47
48 class IndexedDBCursorImpl::CursorPrefetchIterationOperation 48 class IndexedDBCursor::CursorPrefetchIterationOperation
49 : public IndexedDBTransaction::Operation { 49 : public IndexedDBTransaction::Operation {
50 public: 50 public:
51 CursorPrefetchIterationOperation( 51 CursorPrefetchIterationOperation(
52 scoped_refptr<IndexedDBCursorImpl> cursor, 52 scoped_refptr<IndexedDBCursor> cursor,
53 int number_to_fetch, 53 int number_to_fetch,
54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) 54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks)
55 : cursor_(cursor), 55 : cursor_(cursor),
56 number_to_fetch_(number_to_fetch), 56 number_to_fetch_(number_to_fetch),
57 callbacks_(callbacks) {} 57 callbacks_(callbacks) {}
58 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 58 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
59 59
60 private: 60 private:
61 scoped_refptr<IndexedDBCursorImpl> cursor_; 61 scoped_refptr<IndexedDBCursor> cursor_;
62 int number_to_fetch_; 62 int number_to_fetch_;
63 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; 63 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_;
64 }; 64 };
65 65
66 IndexedDBCursorImpl::IndexedDBCursorImpl( 66 IndexedDBCursor::IndexedDBCursor(
67 scoped_ptr<IndexedDBBackingStore::Cursor> cursor, 67 scoped_ptr<IndexedDBBackingStore::Cursor> cursor,
68 indexed_db::CursorType cursor_type, 68 indexed_db::CursorType cursor_type,
69 IndexedDBDatabase::TaskType task_type, 69 IndexedDBDatabase::TaskType task_type,
70 IndexedDBTransaction* transaction) 70 IndexedDBTransaction* transaction)
71 : task_type_(task_type), 71 : task_type_(task_type),
72 cursor_type_(cursor_type), 72 cursor_type_(cursor_type),
73 transaction_(transaction), 73 transaction_(transaction),
74 cursor_(cursor.Pass()), 74 cursor_(cursor.Pass()),
75 closed_(false) { 75 closed_(false) {
76 transaction_->RegisterOpenCursor(this); 76 transaction_->RegisterOpenCursor(this);
77 } 77 }
78 78
79 IndexedDBCursorImpl::~IndexedDBCursorImpl() { 79 IndexedDBCursor::~IndexedDBCursor() {
80 transaction_->UnregisterOpenCursor(this); 80 transaction_->UnregisterOpenCursor(this);
81 } 81 }
82 82
83 void IndexedDBCursorImpl::ContinueFunction( 83 void IndexedDBCursor::ContinueFunction(
84 scoped_ptr<IndexedDBKey> key, 84 scoped_ptr<IndexedDBKey> key,
85 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) { 85 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) {
86 IDB_TRACE("IndexedDBCursorImpl::continue"); 86 IDB_TRACE("IndexedDBCursor::continue");
87 87
88 transaction_->ScheduleTask( 88 transaction_->ScheduleTask(
89 task_type_, new CursorIterationOperation(this, key.Pass(), callbacks)); 89 task_type_, new CursorIterationOperation(this, key.Pass(), callbacks));
90 } 90 }
91 91
92 void IndexedDBCursorImpl::Advance( 92 void IndexedDBCursor::Advance(
93 uint32 count, 93 uint32 count,
94 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) { 94 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) {
95 IDB_TRACE("IndexedDBCursorImpl::advance"); 95 IDB_TRACE("IndexedDBCursor::advance");
96 96
97 transaction_->ScheduleTask( 97 transaction_->ScheduleTask(
98 new CursorAdvanceOperation(this, count, callbacks)); 98 new CursorAdvanceOperation(this, count, callbacks));
99 } 99 }
100 100
101 void IndexedDBCursorImpl::CursorAdvanceOperation::Perform( 101 void IndexedDBCursor::CursorAdvanceOperation::Perform(
102 IndexedDBTransaction* /*transaction*/) { 102 IndexedDBTransaction* /*transaction*/) {
103 IDB_TRACE("CursorAdvanceOperation"); 103 IDB_TRACE("CursorAdvanceOperation");
104 if (!cursor_->cursor_ || !cursor_->cursor_->Advance(count_)) { 104 if (!cursor_->cursor_ || !cursor_->cursor_->Advance(count_)) {
105 cursor_->cursor_.reset(); 105 cursor_->cursor_.reset();
106 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 106 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL));
107 return; 107 return;
108 } 108 }
109 109
110 callbacks_->OnSuccess( 110 callbacks_->OnSuccess(
111 cursor_->key(), cursor_->primary_key(), cursor_->Value()); 111 cursor_->key(), cursor_->primary_key(), cursor_->Value());
112 } 112 }
113 113
114 void IndexedDBCursorImpl::CursorIterationOperation::Perform( 114 void IndexedDBCursor::CursorIterationOperation::Perform(
115 IndexedDBTransaction* /*transaction*/) { 115 IndexedDBTransaction* /*transaction*/) {
116 IDB_TRACE("CursorIterationOperation"); 116 IDB_TRACE("CursorIterationOperation");
117 if (!cursor_->cursor_ || !cursor_->cursor_->ContinueFunction(key_.get())) { 117 if (!cursor_->cursor_ || !cursor_->cursor_->ContinueFunction(key_.get())) {
118 cursor_->cursor_.reset(); 118 cursor_->cursor_.reset();
119 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 119 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL));
120 return; 120 return;
121 } 121 }
122 122
123 callbacks_->OnSuccess( 123 callbacks_->OnSuccess(
124 cursor_->key(), cursor_->primary_key(), cursor_->Value()); 124 cursor_->key(), cursor_->primary_key(), cursor_->Value());
125 } 125 }
126 126
127 void IndexedDBCursorImpl::PrefetchContinue( 127 void IndexedDBCursor::PrefetchContinue(
128 int number_to_fetch, 128 int number_to_fetch,
129 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) { 129 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) {
130 IDB_TRACE("IndexedDBCursorImpl::prefetch_continue"); 130 IDB_TRACE("IndexedDBCursor::prefetch_continue");
131 131
132 transaction_->ScheduleTask( 132 transaction_->ScheduleTask(
133 task_type_, 133 task_type_,
134 new CursorPrefetchIterationOperation(this, number_to_fetch, callbacks)); 134 new CursorPrefetchIterationOperation(this, number_to_fetch, callbacks));
135 } 135 }
136 136
137 void IndexedDBCursorImpl::CursorPrefetchIterationOperation::Perform( 137 void IndexedDBCursor::CursorPrefetchIterationOperation::Perform(
138 IndexedDBTransaction* /*transaction*/) { 138 IndexedDBTransaction* /*transaction*/) {
139 IDB_TRACE("CursorPrefetchIterationOperation"); 139 IDB_TRACE("CursorPrefetchIterationOperation");
140 140
141 std::vector<IndexedDBKey> found_keys; 141 std::vector<IndexedDBKey> found_keys;
142 std::vector<IndexedDBKey> found_primary_keys; 142 std::vector<IndexedDBKey> found_primary_keys;
143 std::vector<std::vector<char> > found_values; 143 std::vector<std::vector<char> > found_values;
144 144
145 if (cursor_->cursor_) 145 if (cursor_->cursor_)
146 cursor_->saved_cursor_.reset(cursor_->cursor_->Clone()); 146 cursor_->saved_cursor_.reset(cursor_->cursor_->Clone());
147 const size_t max_size_estimate = 10 * 1024 * 1024; 147 const size_t max_size_estimate = 10 * 1024 * 1024;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 if (!found_keys.size()) { 180 if (!found_keys.size()) {
181 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL)); 181 callbacks_->OnSuccess(static_cast<std::vector<char>*>(NULL));
182 return; 182 return;
183 } 183 }
184 184
185 callbacks_->OnSuccessWithPrefetch( 185 callbacks_->OnSuccessWithPrefetch(
186 found_keys, found_primary_keys, found_values); 186 found_keys, found_primary_keys, found_values);
187 } 187 }
188 188
189 void IndexedDBCursorImpl::PrefetchReset(int used_prefetches, int) { 189 void IndexedDBCursor::PrefetchReset(int used_prefetches, int) {
190 IDB_TRACE("IndexedDBCursorImpl::prefetch_reset"); 190 IDB_TRACE("IndexedDBCursor::prefetch_reset");
191 cursor_.swap(saved_cursor_); 191 cursor_.swap(saved_cursor_);
192 saved_cursor_.reset(); 192 saved_cursor_.reset();
193 193
194 if (closed_) 194 if (closed_)
195 return; 195 return;
196 if (cursor_) { 196 if (cursor_) {
197 for (int i = 0; i < used_prefetches; ++i) { 197 for (int i = 0; i < used_prefetches; ++i) {
198 bool ok = cursor_->ContinueFunction(); 198 bool ok = cursor_->ContinueFunction();
199 DCHECK(ok); 199 DCHECK(ok);
200 } 200 }
201 } 201 }
202 } 202 }
203 203
204 void IndexedDBCursorImpl::Close() { 204 void IndexedDBCursor::Close() {
205 IDB_TRACE("IndexedDBCursorImpl::close"); 205 IDB_TRACE("IndexedDBCursor::close");
206 closed_ = true; 206 closed_ = true;
207 cursor_.reset(); 207 cursor_.reset();
208 saved_cursor_.reset(); 208 saved_cursor_.reset();
209 } 209 }
210 210
211 } // namespace content 211 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_cursor.h ('k') | content/browser/indexed_db/indexed_db_cursor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698