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

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

Issue 12326023: Proxy new WebData-based onSuccess() calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more .data()-related android bustage Created 7 years, 10 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
« 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"
11 #include "content/common/indexed_db/indexed_db_dispatcher.h" 11 #include "content/common/indexed_db/indexed_db_dispatcher.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa lue.h"
12 13
14 using WebKit::WebData;
13 using WebKit::WebExceptionCode; 15 using WebKit::WebExceptionCode;
14 using WebKit::WebIDBCallbacks; 16 using WebKit::WebIDBCallbacks;
15 using WebKit::WebIDBKey; 17 using WebKit::WebIDBKey;
16 using WebKit::WebSerializedScriptValue; 18 using WebKit::WebSerializedScriptValue;
17 19
18 namespace content { 20 namespace content {
19 21
20 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id) 22 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id)
21 : ipc_cursor_id_(ipc_cursor_id), 23 : ipc_cursor_id_(ipc_cursor_id),
22 continue_count_(0), 24 continue_count_(0),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if (key.type() == WebIDBKey::NullType) { 60 if (key.type() == WebIDBKey::NullType) {
59 // No key, so this would qualify for a prefetch. 61 // No key, so this would qualify for a prefetch.
60 ++continue_count_; 62 ++continue_count_;
61 63
62 if (!prefetch_keys_.empty()) { 64 if (!prefetch_keys_.empty()) {
63 // We have a prefetch cache, so serve the result from that. 65 // We have a prefetch cache, so serve the result from that.
64 CachedContinue(callbacks.get()); 66 CachedContinue(callbacks.get());
65 return; 67 return;
66 } 68 }
67 69
68 if (continue_count_ > kPrefetchContinueThreshold) { 70 // TODO(alecflett): Reenable prefetching after
71 // https://bugs.webkit.org/show_bug.cgi?id=110398 lands.
72 if (false && continue_count_ > kPrefetchContinueThreshold) {
69 // Request pre-fetch. 73 // Request pre-fetch.
70 dispatcher->RequestIDBCursorPrefetch(prefetch_amount_, 74 dispatcher->RequestIDBCursorPrefetch(prefetch_amount_,
71 callbacks.release(), 75 callbacks.release(),
72 ipc_cursor_id_, &ec); 76 ipc_cursor_id_, &ec);
73 77
74 // Increase prefetch_amount_ exponentially. 78 // Increase prefetch_amount_ exponentially.
75 prefetch_amount_ *= 2; 79 prefetch_amount_ *= 2;
76 if (prefetch_amount_ > kMaxPrefetchAmount) 80 if (prefetch_amount_ > kMaxPrefetchAmount)
77 prefetch_amount_ = kMaxPrefetchAmount; 81 prefetch_amount_ = kMaxPrefetchAmount;
78 82
(...skipping 22 matching lines...) Expand all
101 // If the onsuccess callback called continue() on the cursor again, 105 // If the onsuccess callback called continue() on the cursor again,
102 // and that continue was served by the prefetch cache, then 106 // and that continue was served by the prefetch cache, then
103 // pending_onsuccess_callbacks_ would be incremented. 107 // pending_onsuccess_callbacks_ would be incremented.
104 // If not, it means the callback did something else, or nothing at all, 108 // If not, it means the callback did something else, or nothing at all,
105 // in which case we need to reset the cache. 109 // in which case we need to reset the cache.
106 110
107 if (pending_onsuccess_callbacks_ == 0) 111 if (pending_onsuccess_callbacks_ == 0)
108 ResetPrefetchCache(); 112 ResetPrefetchCache();
109 } 113 }
110 114
115 void RendererWebIDBCursorImpl::SetPrefetchDataOld(
116 const std::vector<IndexedDBKey>& keys,
117 const std::vector<IndexedDBKey>& primary_keys,
118 const std::vector<SerializedScriptValue>& values) {
119 NOTIMPLEMENTED();
120 }
121
111 void RendererWebIDBCursorImpl::SetPrefetchData( 122 void RendererWebIDBCursorImpl::SetPrefetchData(
112 const std::vector<IndexedDBKey>& keys, 123 const std::vector<IndexedDBKey>& keys,
113 const std::vector<IndexedDBKey>& primary_keys, 124 const std::vector<IndexedDBKey>& primary_keys,
114 const std::vector<SerializedScriptValue>& values) { 125 const std::vector<WebData>& values) {
115 prefetch_keys_.assign(keys.begin(), keys.end()); 126 prefetch_keys_.assign(keys.begin(), keys.end());
116 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); 127 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end());
117 prefetch_values_.assign(values.begin(), values.end()); 128 prefetch_values_.assign(values.begin(), values.end());
118 129
119 used_prefetches_ = 0; 130 used_prefetches_ = 0;
120 pending_onsuccess_callbacks_ = 0; 131 pending_onsuccess_callbacks_ = 0;
121 } 132 }
122 133
123 void RendererWebIDBCursorImpl::CachedContinue( 134 void RendererWebIDBCursorImpl::CachedContinueOld(
124 WebKit::WebIDBCallbacks* callbacks) { 135 WebKit::WebIDBCallbacks* callbacks) {
125 DCHECK_GT(prefetch_keys_.size(), 0ul); 136 DCHECK_GT(prefetch_keys_.size(), 0ul);
126 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); 137 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size());
127 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); 138 DCHECK(prefetch_values_.size() == prefetch_keys_.size());
128 139
129 IndexedDBKey key = prefetch_keys_.front(); 140 IndexedDBKey key = prefetch_keys_.front();
130 IndexedDBKey primary_key = prefetch_primary_keys_.front(); 141 IndexedDBKey primary_key = prefetch_primary_keys_.front();
131 SerializedScriptValue value = prefetch_values_.front(); 142 // These casts are temporary as part of a refactoring.
143 // See https://code.google.com/p/chromium/issues/detail?id=156247
144 WebData prefetch_value = prefetch_values_.front();
145 string16 prefetch_string(
146 reinterpret_cast<string16::const_pointer>(prefetch_value.data()),
147 reinterpret_cast<string16::const_pointer>(prefetch_value.data() +
148 prefetch_value.size()));
149 SerializedScriptValue value(false, false, prefetch_string);
132 150
133 prefetch_keys_.pop_front(); 151 prefetch_keys_.pop_front();
134 prefetch_primary_keys_.pop_front(); 152 prefetch_primary_keys_.pop_front();
135 prefetch_values_.pop_front(); 153 prefetch_values_.pop_front();
136 used_prefetches_++; 154 used_prefetches_++;
137 155
138 pending_onsuccess_callbacks_++; 156 pending_onsuccess_callbacks_++;
139 157
140 callbacks->onSuccess(key, primary_key, 158 callbacks->onSuccess(key, primary_key,
141 WebSerializedScriptValue(value)); 159 WebSerializedScriptValue(value));
142 } 160 }
143 161
162 void RendererWebIDBCursorImpl::CachedContinue(
163 WebKit::WebIDBCallbacks* callbacks) {
164 DCHECK_GT(prefetch_keys_.size(), 0ul);
165 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size());
166 DCHECK(prefetch_values_.size() == prefetch_keys_.size());
167
168 IndexedDBKey key = prefetch_keys_.front();
169 IndexedDBKey primary_key = prefetch_primary_keys_.front();
170 // this could be a real problem.. we need 2 CachedContinues
171 WebData value = prefetch_values_.front();
172
173 prefetch_keys_.pop_front();
174 prefetch_primary_keys_.pop_front();
175 prefetch_values_.pop_front();
176 used_prefetches_++;
177
178 pending_onsuccess_callbacks_++;
179
180 callbacks->onSuccess(key, primary_key, value);
181 }
182
144 void RendererWebIDBCursorImpl::ResetPrefetchCache() { 183 void RendererWebIDBCursorImpl::ResetPrefetchCache() {
145 continue_count_ = 0; 184 continue_count_ = 0;
146 prefetch_amount_ = kMinPrefetchAmount; 185 prefetch_amount_ = kMinPrefetchAmount;
147 186
148 if (!prefetch_keys_.size()) { 187 if (!prefetch_keys_.size()) {
149 // No prefetch cache, so no need to reset the cursor in the back-end. 188 // No prefetch cache, so no need to reset the cursor in the back-end.
150 return; 189 return;
151 } 190 }
152 191
153 IndexedDBDispatcher* dispatcher = 192 IndexedDBDispatcher* dispatcher =
154 IndexedDBDispatcher::ThreadSpecificInstance(); 193 IndexedDBDispatcher::ThreadSpecificInstance();
155 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, 194 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_,
156 prefetch_keys_.size(), 195 prefetch_keys_.size(),
157 ipc_cursor_id_); 196 ipc_cursor_id_);
158 prefetch_keys_.clear(); 197 prefetch_keys_.clear();
159 prefetch_primary_keys_.clear(); 198 prefetch_primary_keys_.clear();
160 prefetch_values_.clear(); 199 prefetch_values_.clear();
161 200
162 pending_onsuccess_callbacks_ = 0; 201 pending_onsuccess_callbacks_ = 0;
163 } 202 }
164 203
165 } // namespace content 204 } // namespace content
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