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

Side by Side Diff: content/common/indexed_db/proxy_webidbcursor_impl.cc

Issue 10854081: IndexedDB: Simplify cursor data callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
« no previous file with comments | « content/common/indexed_db/proxy_webidbcursor_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/indexed_db/proxy_webidbcursor_impl.h" 5 #include "content/common/indexed_db/proxy_webidbcursor_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "content/common/child_thread.h" 9 #include "content/common/child_thread.h"
10 #include "content/common/indexed_db/indexed_db_messages.h" 10 #include "content/common/indexed_db/indexed_db_messages.h"
(...skipping 19 matching lines...) Expand all
30 // object since inside WebKit, they hold a reference to the object wich owns 30 // object since inside WebKit, they hold a reference to the object wich owns
31 // this object. But, if that ever changed, then we'd need to invalidate 31 // this object. But, if that ever changed, then we'd need to invalidate
32 // any such pointers. 32 // any such pointers.
33 IndexedDBDispatcher::Send(new IndexedDBHostMsg_CursorDestroyed( 33 IndexedDBDispatcher::Send(new IndexedDBHostMsg_CursorDestroyed(
34 idb_cursor_id_)); 34 idb_cursor_id_));
35 IndexedDBDispatcher* dispatcher = 35 IndexedDBDispatcher* dispatcher =
36 IndexedDBDispatcher::ThreadSpecificInstance(); 36 IndexedDBDispatcher::ThreadSpecificInstance();
37 dispatcher->CursorDestroyed(idb_cursor_id_); 37 dispatcher->CursorDestroyed(idb_cursor_id_);
38 } 38 }
39 39
40 // TODO(jsbell): Remove the following method after WK92278 rolls.
41 WebIDBKey RendererWebIDBCursorImpl::key() const {
42 return key_;
43 }
44
45 // TODO(jsbell): Remove the following method after WK92278 rolls.
46 WebIDBKey RendererWebIDBCursorImpl::primaryKey() const {
47 return primary_key_;
48 }
49
50 // TODO(jsbell): Remove the following method after WK92278 rolls.
51 WebSerializedScriptValue RendererWebIDBCursorImpl::value() const {
52 return value_;
53 }
54
55 void RendererWebIDBCursorImpl::advance(unsigned long count, 40 void RendererWebIDBCursorImpl::advance(unsigned long count,
56 WebIDBCallbacks* callbacks_ptr, 41 WebIDBCallbacks* callbacks_ptr,
57 WebExceptionCode& ec) { 42 WebExceptionCode& ec) {
58 IndexedDBDispatcher* dispatcher = 43 IndexedDBDispatcher* dispatcher =
59 IndexedDBDispatcher::ThreadSpecificInstance(); 44 IndexedDBDispatcher::ThreadSpecificInstance();
60 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 45 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
61 ResetPrefetchCache(); 46 ResetPrefetchCache();
62 dispatcher->RequestIDBCursorAdvance(count, callbacks.release(), 47 dispatcher->RequestIDBCursorAdvance(count, callbacks.release(),
63 idb_cursor_id_, &ec); 48 idb_cursor_id_, &ec);
64 } 49 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // If the onsuccess callback called continue() on the cursor again, 101 // If the onsuccess callback called continue() on the cursor again,
117 // and that continue was served by the prefetch cache, then 102 // and that continue was served by the prefetch cache, then
118 // pending_onsuccess_callbacks_ would be incremented. 103 // pending_onsuccess_callbacks_ would be incremented.
119 // If not, it means the callback did something else, or nothing at all, 104 // If not, it means the callback did something else, or nothing at all,
120 // in which case we need to reset the cache. 105 // in which case we need to reset the cache.
121 106
122 if (pending_onsuccess_callbacks_ == 0) 107 if (pending_onsuccess_callbacks_ == 0)
123 ResetPrefetchCache(); 108 ResetPrefetchCache();
124 } 109 }
125 110
126 // TODO(jsbell): Remove the following method after WK92278 rolls.
127 void RendererWebIDBCursorImpl::SetKeyAndValue(
128 const IndexedDBKey& key,
129 const IndexedDBKey& primary_key,
130 const SerializedScriptValue& value) {
131 key_ = key;
132 primary_key_ = primary_key;
133 value_ = value;
134 }
135
136 void RendererWebIDBCursorImpl::SetPrefetchData( 111 void RendererWebIDBCursorImpl::SetPrefetchData(
137 const std::vector<IndexedDBKey>& keys, 112 const std::vector<IndexedDBKey>& keys,
138 const std::vector<IndexedDBKey>& primary_keys, 113 const std::vector<IndexedDBKey>& primary_keys,
139 const std::vector<SerializedScriptValue>& values) { 114 const std::vector<SerializedScriptValue>& values) {
140 prefetch_keys_.assign(keys.begin(), keys.end()); 115 prefetch_keys_.assign(keys.begin(), keys.end());
141 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); 116 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end());
142 prefetch_values_.assign(values.begin(), values.end()); 117 prefetch_values_.assign(values.begin(), values.end());
143 118
144 used_prefetches_ = 0; 119 used_prefetches_ = 0;
145 pending_onsuccess_callbacks_ = 0; 120 pending_onsuccess_callbacks_ = 0;
146 } 121 }
147 122
148 void RendererWebIDBCursorImpl::CachedContinue( 123 void RendererWebIDBCursorImpl::CachedContinue(
149 WebKit::WebIDBCallbacks* callbacks) { 124 WebKit::WebIDBCallbacks* callbacks) {
150 DCHECK_GT(prefetch_keys_.size(), 0ul); 125 DCHECK_GT(prefetch_keys_.size(), 0ul);
151 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); 126 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size());
152 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); 127 DCHECK(prefetch_values_.size() == prefetch_keys_.size());
153 128
154 // TODO(jsbell): Turn these three variables into locals after WK92278 rolls. 129 IndexedDBKey key = prefetch_keys_.front();
155 key_ = prefetch_keys_.front(); 130 IndexedDBKey primary_key = prefetch_primary_keys_.front();
156 primary_key_ = prefetch_primary_keys_.front(); 131 SerializedScriptValue value = prefetch_values_.front();
157 value_ = prefetch_values_.front();
158 132
159 prefetch_keys_.pop_front(); 133 prefetch_keys_.pop_front();
160 prefetch_primary_keys_.pop_front(); 134 prefetch_primary_keys_.pop_front();
161 prefetch_values_.pop_front(); 135 prefetch_values_.pop_front();
162 used_prefetches_++; 136 used_prefetches_++;
163 137
164 pending_onsuccess_callbacks_++; 138 pending_onsuccess_callbacks_++;
165 139
166 // TODO(jsbell): Remove the ...WithContinuation call after WK92278 rolls. 140 callbacks->onSuccess(key, primary_key, value);
167 callbacks->onSuccessWithContinuation();
168 callbacks->onSuccess(key_, primary_key_, value_);
169 } 141 }
170 142
171 void RendererWebIDBCursorImpl::ResetPrefetchCache() { 143 void RendererWebIDBCursorImpl::ResetPrefetchCache() {
172 continue_count_ = 0; 144 continue_count_ = 0;
173 prefetch_amount_ = kMinPrefetchAmount; 145 prefetch_amount_ = kMinPrefetchAmount;
174 146
175 if (!prefetch_keys_.size()) { 147 if (!prefetch_keys_.size()) {
176 // No prefetch cache, so no need to reset the cursor in the back-end. 148 // No prefetch cache, so no need to reset the cursor in the back-end.
177 return; 149 return;
178 } 150 }
179 151
180 IndexedDBDispatcher* dispatcher = 152 IndexedDBDispatcher* dispatcher =
181 IndexedDBDispatcher::ThreadSpecificInstance(); 153 IndexedDBDispatcher::ThreadSpecificInstance();
182 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, 154 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_,
183 prefetch_keys_.size(), 155 prefetch_keys_.size(),
184 idb_cursor_id_); 156 idb_cursor_id_);
185 prefetch_keys_.clear(); 157 prefetch_keys_.clear();
186 prefetch_primary_keys_.clear(); 158 prefetch_primary_keys_.clear();
187 prefetch_values_.clear(); 159 prefetch_values_.clear();
188 160
189 pending_onsuccess_callbacks_ = 0; 161 pending_onsuccess_callbacks_ = 0;
190 } 162 }
OLDNEW
« no previous file with comments | « content/common/indexed_db/proxy_webidbcursor_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698