OLD | NEW |
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" | |
14 #include "content/browser/indexed_db/indexed_db_database_error.h" | 13 #include "content/browser/indexed_db/indexed_db_database_error.h" |
15 #include "content/browser/indexed_db/indexed_db_tracing.h" | 14 #include "content/browser/indexed_db/indexed_db_tracing.h" |
16 #include "content/browser/indexed_db/indexed_db_transaction.h" | 15 #include "content/browser/indexed_db/indexed_db_transaction.h" |
17 #include "content/browser/indexed_db/indexed_db_value.h" | 16 #include "content/browser/indexed_db/indexed_db_value.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 IndexedDBCursor::IndexedDBCursor( | 20 IndexedDBCursor::IndexedDBCursor( |
22 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, | 21 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, |
23 indexed_db::CursorType cursor_type, | 22 indexed_db::CursorType cursor_type, |
24 blink::WebIDBTaskType task_type, | 23 blink::WebIDBTaskType task_type, |
25 IndexedDBTransaction* transaction) | 24 IndexedDBTransaction* transaction) |
26 : task_type_(task_type), | 25 : task_type_(task_type), |
27 cursor_type_(cursor_type), | 26 cursor_type_(cursor_type), |
28 transaction_(transaction), | 27 transaction_(transaction), |
29 cursor_(std::move(cursor)), | 28 cursor_(std::move(cursor)), |
30 closed_(false) { | 29 closed_(false) { |
31 transaction_->RegisterOpenCursor(this); | 30 transaction_->RegisterOpenCursor(this); |
32 } | 31 } |
33 | 32 |
34 IndexedDBCursor::~IndexedDBCursor() { | 33 IndexedDBCursor::~IndexedDBCursor() { |
35 transaction_->UnregisterOpenCursor(this); | 34 transaction_->UnregisterOpenCursor(this); |
36 } | 35 } |
37 | 36 |
38 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key, | 37 void IndexedDBCursor::Continue(std::unique_ptr<IndexedDBKey> key, |
39 std::unique_ptr<IndexedDBKey> primary_key, | 38 std::unique_ptr<IndexedDBKey> primary_key) { |
40 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
41 IDB_TRACE("IndexedDBCursor::Continue"); | 39 IDB_TRACE("IndexedDBCursor::Continue"); |
42 | 40 |
43 transaction_->ScheduleTask( | 41 transaction_->ScheduleTask( |
44 task_type_, | 42 task_type_, base::Bind(&IndexedDBCursor::CursorIterationOperation, this, |
45 base::Bind(&IndexedDBCursor::CursorIterationOperation, | 43 base::Passed(&key), base::Passed(&primary_key))); |
46 this, | |
47 base::Passed(&key), | |
48 base::Passed(&primary_key), | |
49 callbacks)); | |
50 } | 44 } |
51 | 45 |
52 void IndexedDBCursor::Advance(uint32_t count, | 46 void IndexedDBCursor::Advance(uint32_t count) { |
53 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
54 IDB_TRACE("IndexedDBCursor::Advance"); | 47 IDB_TRACE("IndexedDBCursor::Advance"); |
55 | 48 |
56 transaction_->ScheduleTask( | 49 transaction_->ScheduleTask( |
57 task_type_, | 50 task_type_, |
58 base::Bind( | 51 base::Bind(&IndexedDBCursor::CursorAdvanceOperation, this, count)); |
59 &IndexedDBCursor::CursorAdvanceOperation, this, count, callbacks)); | |
60 } | 52 } |
61 | 53 |
62 void IndexedDBCursor::CursorAdvanceOperation( | 54 void IndexedDBCursor::CursorAdvanceOperation( |
63 uint32_t count, | 55 uint32_t count, |
64 scoped_refptr<IndexedDBCallbacks> callbacks, | |
65 IndexedDBTransaction* /*transaction*/) { | 56 IndexedDBTransaction* /*transaction*/) { |
66 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); | 57 IDB_TRACE("IndexedDBCursor::CursorAdvanceOperation"); |
67 leveldb::Status s; | 58 leveldb::Status s; |
68 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will | 59 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
69 // properly fail, caller will not know why, and any corruption | 60 // properly fail, caller will not know why, and any corruption |
70 // will be ignored. | 61 // will be ignored. |
71 if (!cursor_ || !cursor_->Advance(count, &s)) { | 62 if (!cursor_ || !cursor_->Advance(count, &s)) { |
72 cursor_.reset(); | 63 cursor_.reset(); |
| 64 #ifdef CJM_NEED_CALLBACK |
73 callbacks->OnSuccess(nullptr); | 65 callbacks->OnSuccess(nullptr); |
| 66 #endif |
74 return; | 67 return; |
75 } | 68 } |
76 | 69 |
| 70 #ifdef CJM_NEED_CALLBACK |
77 callbacks->OnSuccess(key(), primary_key(), Value()); | 71 callbacks->OnSuccess(key(), primary_key(), Value()); |
| 72 #endif |
78 } | 73 } |
79 | 74 |
80 void IndexedDBCursor::CursorIterationOperation( | 75 void IndexedDBCursor::CursorIterationOperation( |
81 std::unique_ptr<IndexedDBKey> key, | 76 std::unique_ptr<IndexedDBKey> key, |
82 std::unique_ptr<IndexedDBKey> primary_key, | 77 std::unique_ptr<IndexedDBKey> primary_key, |
83 scoped_refptr<IndexedDBCallbacks> callbacks, | |
84 IndexedDBTransaction* /*transaction*/) { | 78 IndexedDBTransaction* /*transaction*/) { |
85 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); | 79 IDB_TRACE("IndexedDBCursor::CursorIterationOperation"); |
86 leveldb::Status s; | 80 leveldb::Status s; |
87 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will | 81 // TODO(cmumford): Handle this error (crbug.com/363397). Although this will |
88 // properly fail, caller will not know why, and any corruption | 82 // properly fail, caller will not know why, and any corruption |
89 // will be ignored. | 83 // will be ignored. |
90 if (!cursor_ || !cursor_->Continue(key.get(), | 84 if (!cursor_ || !cursor_->Continue(key.get(), |
91 primary_key.get(), | 85 primary_key.get(), |
92 IndexedDBBackingStore::Cursor::SEEK, | 86 IndexedDBBackingStore::Cursor::SEEK, |
93 &s) || !s.ok()) { | 87 &s) || !s.ok()) { |
94 cursor_.reset(); | 88 cursor_.reset(); |
| 89 #ifdef CJM_NEED_CALLBACK |
95 callbacks->OnSuccess(nullptr); | 90 callbacks->OnSuccess(nullptr); |
| 91 #endif |
96 return; | 92 return; |
97 } | 93 } |
98 | 94 |
| 95 #ifdef CJM_NEED_CALLBACK |
99 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); | 96 callbacks->OnSuccess(this->key(), this->primary_key(), Value()); |
| 97 #endif |
100 } | 98 } |
101 | 99 |
102 void IndexedDBCursor::PrefetchContinue( | 100 void IndexedDBCursor::PrefetchContinue(int number_to_fetch) { |
103 int number_to_fetch, | |
104 scoped_refptr<IndexedDBCallbacks> callbacks) { | |
105 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); | 101 IDB_TRACE("IndexedDBCursor::PrefetchContinue"); |
106 | 102 |
107 transaction_->ScheduleTask( | 103 transaction_->ScheduleTask( |
108 task_type_, | 104 task_type_, base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, |
109 base::Bind(&IndexedDBCursor::CursorPrefetchIterationOperation, | 105 this, number_to_fetch)); |
110 this, | |
111 number_to_fetch, | |
112 callbacks)); | |
113 } | 106 } |
114 | 107 |
115 void IndexedDBCursor::CursorPrefetchIterationOperation( | 108 void IndexedDBCursor::CursorPrefetchIterationOperation( |
116 int number_to_fetch, | 109 int number_to_fetch, |
117 scoped_refptr<IndexedDBCallbacks> callbacks, | |
118 IndexedDBTransaction* /*transaction*/) { | 110 IndexedDBTransaction* /*transaction*/) { |
119 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); | 111 IDB_TRACE("IndexedDBCursor::CursorPrefetchIterationOperation"); |
120 | 112 |
121 std::vector<IndexedDBKey> found_keys; | 113 std::vector<IndexedDBKey> found_keys; |
122 std::vector<IndexedDBKey> found_primary_keys; | 114 std::vector<IndexedDBKey> found_primary_keys; |
123 std::vector<IndexedDBValue> found_values; | 115 std::vector<IndexedDBValue> found_values; |
124 | 116 |
125 saved_cursor_.reset(); | 117 saved_cursor_.reset(); |
126 // TODO(cmumford): Use IPC::Channel::kMaximumMessageSize | 118 // TODO(cmumford): Use IPC::Channel::kMaximumMessageSize |
127 const size_t max_size_estimate = 10 * 1024 * 1024; | 119 const size_t max_size_estimate = 10 * 1024 * 1024; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 NOTREACHED(); | 153 NOTREACHED(); |
162 } | 154 } |
163 size_estimate += cursor_->key().size_estimate(); | 155 size_estimate += cursor_->key().size_estimate(); |
164 size_estimate += cursor_->primary_key().size_estimate(); | 156 size_estimate += cursor_->primary_key().size_estimate(); |
165 | 157 |
166 if (size_estimate > max_size_estimate) | 158 if (size_estimate > max_size_estimate) |
167 break; | 159 break; |
168 } | 160 } |
169 | 161 |
170 if (found_keys.empty()) { | 162 if (found_keys.empty()) { |
| 163 #ifdef CJM_NEED_CALLBACK |
171 callbacks->OnSuccess(nullptr); | 164 callbacks->OnSuccess(nullptr); |
| 165 #endif |
172 return; | 166 return; |
173 } | 167 } |
174 | 168 |
| 169 #ifdef CJM_NEED_CALLBACK |
175 callbacks->OnSuccessWithPrefetch( | 170 callbacks->OnSuccessWithPrefetch( |
176 found_keys, found_primary_keys, &found_values); | 171 found_keys, found_primary_keys, &found_values); |
| 172 #endif |
177 } | 173 } |
178 | 174 |
179 leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches, | 175 leveldb::Status IndexedDBCursor::PrefetchReset(int used_prefetches, |
180 int /* unused_prefetches */) { | 176 int /* unused_prefetches */) { |
181 IDB_TRACE("IndexedDBCursor::PrefetchReset"); | 177 IDB_TRACE("IndexedDBCursor::PrefetchReset"); |
182 cursor_.swap(saved_cursor_); | 178 cursor_.swap(saved_cursor_); |
183 saved_cursor_.reset(); | 179 saved_cursor_.reset(); |
184 leveldb::Status s; | 180 leveldb::Status s; |
185 | 181 |
186 if (closed_) | 182 if (closed_) |
(...skipping 11 matching lines...) Expand all Loading... |
198 } | 194 } |
199 | 195 |
200 void IndexedDBCursor::Close() { | 196 void IndexedDBCursor::Close() { |
201 IDB_TRACE("IndexedDBCursor::Close"); | 197 IDB_TRACE("IndexedDBCursor::Close"); |
202 closed_ = true; | 198 closed_ = true; |
203 cursor_.reset(); | 199 cursor_.reset(); |
204 saved_cursor_.reset(); | 200 saved_cursor_.reset(); |
205 } | 201 } |
206 | 202 |
207 } // namespace content | 203 } // namespace content |
OLD | NEW |