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

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

Issue 9691021: IndexedDB: Fix prefetching; cache was always being bypassed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests to verify prefetch cache is used Created 8 years, 9 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) 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 "content/common/child_thread.h" 7 #include "content/common/child_thread.h"
8 #include "content/common/indexed_db/indexed_db_messages.h" 8 #include "content/common/indexed_db/indexed_db_messages.h"
9 #include "content/common/indexed_db/indexed_db_dispatcher.h" 9 #include "content/common/indexed_db/indexed_db_dispatcher.h"
10 10
11 using WebKit::WebExceptionCode; 11 using WebKit::WebExceptionCode;
12 using WebKit::WebIDBCallbacks; 12 using WebKit::WebIDBCallbacks;
13 using WebKit::WebIDBKey; 13 using WebKit::WebIDBKey;
14 using WebKit::WebSerializedScriptValue; 14 using WebKit::WebSerializedScriptValue;
15 15
16 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id) 16 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 idb_cursor_id)
17 : idb_cursor_id_(idb_cursor_id), 17 : idb_cursor_id_(idb_cursor_id),
18 continue_count_(0), 18 continue_count_(0),
19 used_prefetches_(0), 19 used_prefetches_(0),
20 pending_onsuccess_callbacks_(0), 20 pending_onsuccess_callbacks_(0),
21 prefetch_amount_(kMinPrefetchAmount) { 21 prefetch_amount_(kMinPrefetchAmount) {
22 } 22 }
23 23
24 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { 24 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() {
25 // It's not possible for there to be pending callbacks that address this 25 // It's not possible for there to be pending callbacks that address this
26 // object since inside WebKit, they hold a reference to the object wich owns 26 // object since inside WebKit, they hold a reference to the object wich owns
27 // this object. But, if that ever changed, then we'd need to invalidate 27 // this object. But, if that ever changed, then we'd need to invalidate
28 // any such pointers. 28 // any such pointers.
29 if (idb_cursor_id_ == kInvalidIDBCursorId)
30 return;
29 IndexedDBDispatcher::Send(new IndexedDBHostMsg_CursorDestroyed( 31 IndexedDBDispatcher::Send(new IndexedDBHostMsg_CursorDestroyed(
30 idb_cursor_id_)); 32 idb_cursor_id_));
31 IndexedDBDispatcher* dispatcher = 33 IndexedDBDispatcher* dispatcher =
32 IndexedDBDispatcher::ThreadSpecificInstance(); 34 IndexedDBDispatcher::ThreadSpecificInstance();
33 dispatcher->CursorDestroyed(idb_cursor_id_); 35 dispatcher->CursorDestroyed(idb_cursor_id_);
34 } 36 }
35 37
36 unsigned short RendererWebIDBCursorImpl::direction() const { 38 unsigned short RendererWebIDBCursorImpl::direction() const {
39 if (idb_cursor_id_ == kInvalidIDBCursorId)
40 return 0;
37 int direction; 41 int direction;
38 IndexedDBDispatcher::Send( 42 IndexedDBDispatcher::Send(
39 new IndexedDBHostMsg_CursorDirection(idb_cursor_id_, &direction)); 43 new IndexedDBHostMsg_CursorDirection(idb_cursor_id_, &direction));
40 return direction; 44 return direction;
41 } 45 }
42 46
43 WebIDBKey RendererWebIDBCursorImpl::key() const { 47 WebIDBKey RendererWebIDBCursorImpl::key() const {
44 return key_; 48 return key_;
45 } 49 }
46 50
47 WebIDBKey RendererWebIDBCursorImpl::primaryKey() const { 51 WebIDBKey RendererWebIDBCursorImpl::primaryKey() const {
48 return primary_key_; 52 return primary_key_;
49 } 53 }
50 54
51 WebSerializedScriptValue RendererWebIDBCursorImpl::value() const { 55 WebSerializedScriptValue RendererWebIDBCursorImpl::value() const {
52 return value_; 56 return value_;
53 } 57 }
54 58
55 void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value, 59 void RendererWebIDBCursorImpl::update(const WebSerializedScriptValue& value,
56 WebIDBCallbacks* callbacks, 60 WebIDBCallbacks* callbacks,
57 WebExceptionCode& ec) { 61 WebExceptionCode& ec) {
62 if (idb_cursor_id_ == kInvalidIDBCursorId)
63 return;
58 IndexedDBDispatcher* dispatcher = 64 IndexedDBDispatcher* dispatcher =
59 IndexedDBDispatcher::ThreadSpecificInstance(); 65 IndexedDBDispatcher::ThreadSpecificInstance();
60 dispatcher->RequestIDBCursorUpdate( 66 dispatcher->RequestIDBCursorUpdate(
61 content::SerializedScriptValue(value), callbacks, idb_cursor_id_, &ec); 67 content::SerializedScriptValue(value), callbacks, idb_cursor_id_, &ec);
62 } 68 }
63 69
64 void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key, 70 void RendererWebIDBCursorImpl::continueFunction(const WebIDBKey& key,
65 WebIDBCallbacks* callbacks, 71 WebIDBCallbacks* callbacks,
66 WebExceptionCode& ec) { 72 WebExceptionCode& ec) {
67 IndexedDBDispatcher* dispatcher = 73 IndexedDBDispatcher* dispatcher =
68 IndexedDBDispatcher::ThreadSpecificInstance(); 74 IndexedDBDispatcher::ThreadSpecificInstance();
69 75
70 if (key.type() == WebIDBKey::InvalidType) { 76 if (key.type() == WebIDBKey::NullType) {
71 // No key, so this would qualify for a prefetch. 77 // No key, so this would qualify for a prefetch.
72 ++continue_count_; 78 ++continue_count_;
73 79
74 if (!prefetch_keys_.empty()) { 80 if (!prefetch_keys_.empty()) {
75 // We have a prefetch cache, so serve the result from that. 81 // We have a prefetch cache, so serve the result from that.
76 CachedContinue(callbacks); 82 CachedContinue(callbacks);
77 return; 83 return;
78 } 84 }
79 85
86 if (idb_cursor_id_ == kInvalidIDBCursorId)
87 return;
88
80 if (continue_count_ > kPrefetchContinueThreshold) { 89 if (continue_count_ > kPrefetchContinueThreshold) {
81 // Request pre-fetch. 90 // Request pre-fetch.
82 dispatcher->RequestIDBCursorPrefetch(prefetch_amount_, callbacks, 91 dispatcher->RequestIDBCursorPrefetch(prefetch_amount_, callbacks,
83 idb_cursor_id_, &ec); 92 idb_cursor_id_, &ec);
84 93
85 // Increase prefetch_amount_ exponentially. 94 // Increase prefetch_amount_ exponentially.
86 prefetch_amount_ *= 2; 95 prefetch_amount_ *= 2;
87 if (prefetch_amount_ > kMaxPrefetchAmount) 96 if (prefetch_amount_ > kMaxPrefetchAmount)
88 prefetch_amount_ = kMaxPrefetchAmount; 97 prefetch_amount_ = kMaxPrefetchAmount;
89 98
90 return; 99 return;
91 } 100 }
92 } else { 101 } else {
93 // Key argument supplied. We couldn't prefetch this. 102 // Key argument supplied. We couldn't prefetch this.
94 ResetPrefetchCache(); 103 ResetPrefetchCache();
95 } 104 }
96 105
106 if (idb_cursor_id_ == kInvalidIDBCursorId)
107 return;
108
97 dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), callbacks, 109 dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), callbacks,
98 idb_cursor_id_, &ec); 110 idb_cursor_id_, &ec);
99 } 111 }
100 112
101 void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks, 113 void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks,
102 WebExceptionCode& ec) { 114 WebExceptionCode& ec) {
115 if (idb_cursor_id_ == kInvalidIDBCursorId)
116 return;
103 IndexedDBDispatcher* dispatcher = 117 IndexedDBDispatcher* dispatcher =
104 IndexedDBDispatcher::ThreadSpecificInstance(); 118 IndexedDBDispatcher::ThreadSpecificInstance();
105 dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec); 119 dispatcher->RequestIDBCursorDelete(callbacks, idb_cursor_id_, &ec);
106 } 120 }
107 121
108 void RendererWebIDBCursorImpl::postSuccessHandlerCallback() 122 void RendererWebIDBCursorImpl::postSuccessHandlerCallback()
109 { 123 {
110 pending_onsuccess_callbacks_--; 124 pending_onsuccess_callbacks_--;
111 125
112 // If the onsuccess callback called continue() on the cursor again, 126 // If the onsuccess callback called continue() on the cursor again,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 175
162 void RendererWebIDBCursorImpl::ResetPrefetchCache() { 176 void RendererWebIDBCursorImpl::ResetPrefetchCache() {
163 continue_count_ = 0; 177 continue_count_ = 0;
164 prefetch_amount_ = kMinPrefetchAmount; 178 prefetch_amount_ = kMinPrefetchAmount;
165 179
166 if (!prefetch_keys_.size()) { 180 if (!prefetch_keys_.size()) {
167 // No prefetch cache, so no need to reset the cursor in the back-end. 181 // No prefetch cache, so no need to reset the cursor in the back-end.
168 return; 182 return;
169 } 183 }
170 184
171 IndexedDBDispatcher* dispatcher = 185 if (idb_cursor_id_ != kInvalidIDBCursorId) {
172 IndexedDBDispatcher::ThreadSpecificInstance(); 186 IndexedDBDispatcher* dispatcher =
173 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, 187 IndexedDBDispatcher::ThreadSpecificInstance();
174 prefetch_keys_.size(), 188 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_,
175 idb_cursor_id_); 189 prefetch_keys_.size(),
190 idb_cursor_id_);
191 }
192
176 prefetch_keys_.clear(); 193 prefetch_keys_.clear();
177 prefetch_primary_keys_.clear(); 194 prefetch_primary_keys_.clear();
178 prefetch_values_.clear(); 195 prefetch_values_.clear();
179 196
180 pending_onsuccess_callbacks_ = 0; 197 pending_onsuccess_callbacks_ = 0;
181 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698