| OLD | NEW |
| 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 Loading... |
| 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. |
| 40 WebIDBKey RendererWebIDBCursorImpl::key() const { | 41 WebIDBKey RendererWebIDBCursorImpl::key() const { |
| 41 return key_; | 42 return key_; |
| 42 } | 43 } |
| 43 | 44 |
| 45 // TODO(jsbell): Remove the following method after WK92278 rolls. |
| 44 WebIDBKey RendererWebIDBCursorImpl::primaryKey() const { | 46 WebIDBKey RendererWebIDBCursorImpl::primaryKey() const { |
| 45 return primary_key_; | 47 return primary_key_; |
| 46 } | 48 } |
| 47 | 49 |
| 50 // TODO(jsbell): Remove the following method after WK92278 rolls. |
| 48 WebSerializedScriptValue RendererWebIDBCursorImpl::value() const { | 51 WebSerializedScriptValue RendererWebIDBCursorImpl::value() const { |
| 49 return value_; | 52 return value_; |
| 50 } | 53 } |
| 51 | 54 |
| 52 void RendererWebIDBCursorImpl::advance(unsigned long count, | 55 void RendererWebIDBCursorImpl::advance(unsigned long count, |
| 53 WebIDBCallbacks* callbacks_ptr, | 56 WebIDBCallbacks* callbacks_ptr, |
| 54 WebExceptionCode& ec) { | 57 WebExceptionCode& ec) { |
| 55 IndexedDBDispatcher* dispatcher = | 58 IndexedDBDispatcher* dispatcher = |
| 56 IndexedDBDispatcher::ThreadSpecificInstance(); | 59 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 57 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 60 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // If the onsuccess callback called continue() on the cursor again, | 116 // If the onsuccess callback called continue() on the cursor again, |
| 114 // and that continue was served by the prefetch cache, then | 117 // and that continue was served by the prefetch cache, then |
| 115 // pending_onsuccess_callbacks_ would be incremented. | 118 // pending_onsuccess_callbacks_ would be incremented. |
| 116 // If not, it means the callback did something else, or nothing at all, | 119 // If not, it means the callback did something else, or nothing at all, |
| 117 // in which case we need to reset the cache. | 120 // in which case we need to reset the cache. |
| 118 | 121 |
| 119 if (pending_onsuccess_callbacks_ == 0) | 122 if (pending_onsuccess_callbacks_ == 0) |
| 120 ResetPrefetchCache(); | 123 ResetPrefetchCache(); |
| 121 } | 124 } |
| 122 | 125 |
| 126 // TODO(jsbell): Remove the following method after WK92278 rolls. |
| 123 void RendererWebIDBCursorImpl::SetKeyAndValue( | 127 void RendererWebIDBCursorImpl::SetKeyAndValue( |
| 124 const IndexedDBKey& key, | 128 const IndexedDBKey& key, |
| 125 const IndexedDBKey& primary_key, | 129 const IndexedDBKey& primary_key, |
| 126 const SerializedScriptValue& value) { | 130 const SerializedScriptValue& value) { |
| 127 key_ = key; | 131 key_ = key; |
| 128 primary_key_ = primary_key; | 132 primary_key_ = primary_key; |
| 129 value_ = value; | 133 value_ = value; |
| 130 } | 134 } |
| 131 | 135 |
| 132 void RendererWebIDBCursorImpl::SetPrefetchData( | 136 void RendererWebIDBCursorImpl::SetPrefetchData( |
| 133 const std::vector<IndexedDBKey>& keys, | 137 const std::vector<IndexedDBKey>& keys, |
| 134 const std::vector<IndexedDBKey>& primary_keys, | 138 const std::vector<IndexedDBKey>& primary_keys, |
| 135 const std::vector<SerializedScriptValue>& values) { | 139 const std::vector<SerializedScriptValue>& values) { |
| 136 prefetch_keys_.assign(keys.begin(), keys.end()); | 140 prefetch_keys_.assign(keys.begin(), keys.end()); |
| 137 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); | 141 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); |
| 138 prefetch_values_.assign(values.begin(), values.end()); | 142 prefetch_values_.assign(values.begin(), values.end()); |
| 139 | 143 |
| 140 used_prefetches_ = 0; | 144 used_prefetches_ = 0; |
| 141 pending_onsuccess_callbacks_ = 0; | 145 pending_onsuccess_callbacks_ = 0; |
| 142 } | 146 } |
| 143 | 147 |
| 144 void RendererWebIDBCursorImpl::CachedContinue( | 148 void RendererWebIDBCursorImpl::CachedContinue( |
| 145 WebKit::WebIDBCallbacks* callbacks) { | 149 WebKit::WebIDBCallbacks* callbacks) { |
| 146 DCHECK_GT(prefetch_keys_.size(), 0ul); | 150 DCHECK_GT(prefetch_keys_.size(), 0ul); |
| 147 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); | 151 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); |
| 148 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); | 152 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); |
| 149 | 153 |
| 154 // TODO(jsbell): Turn these three variables into locals after WK92278 rolls. |
| 150 key_ = prefetch_keys_.front(); | 155 key_ = prefetch_keys_.front(); |
| 151 primary_key_ = prefetch_primary_keys_.front(); | 156 primary_key_ = prefetch_primary_keys_.front(); |
| 152 value_ = prefetch_values_.front(); | 157 value_ = prefetch_values_.front(); |
| 153 | 158 |
| 154 prefetch_keys_.pop_front(); | 159 prefetch_keys_.pop_front(); |
| 155 prefetch_primary_keys_.pop_front(); | 160 prefetch_primary_keys_.pop_front(); |
| 156 prefetch_values_.pop_front(); | 161 prefetch_values_.pop_front(); |
| 157 used_prefetches_++; | 162 used_prefetches_++; |
| 158 | 163 |
| 159 pending_onsuccess_callbacks_++; | 164 pending_onsuccess_callbacks_++; |
| 165 |
| 166 // TODO(jsbell): Remove the ...WithContinuation call after WK92278 rolls. |
| 160 callbacks->onSuccessWithContinuation(); | 167 callbacks->onSuccessWithContinuation(); |
| 168 callbacks->onSuccess(key_, primary_key_, value_); |
| 161 } | 169 } |
| 162 | 170 |
| 163 void RendererWebIDBCursorImpl::ResetPrefetchCache() { | 171 void RendererWebIDBCursorImpl::ResetPrefetchCache() { |
| 164 continue_count_ = 0; | 172 continue_count_ = 0; |
| 165 prefetch_amount_ = kMinPrefetchAmount; | 173 prefetch_amount_ = kMinPrefetchAmount; |
| 166 | 174 |
| 167 if (!prefetch_keys_.size()) { | 175 if (!prefetch_keys_.size()) { |
| 168 // No prefetch cache, so no need to reset the cursor in the back-end. | 176 // No prefetch cache, so no need to reset the cursor in the back-end. |
| 169 return; | 177 return; |
| 170 } | 178 } |
| 171 | 179 |
| 172 IndexedDBDispatcher* dispatcher = | 180 IndexedDBDispatcher* dispatcher = |
| 173 IndexedDBDispatcher::ThreadSpecificInstance(); | 181 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 174 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, | 182 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, |
| 175 prefetch_keys_.size(), | 183 prefetch_keys_.size(), |
| 176 idb_cursor_id_); | 184 idb_cursor_id_); |
| 177 prefetch_keys_.clear(); | 185 prefetch_keys_.clear(); |
| 178 prefetch_primary_keys_.clear(); | 186 prefetch_primary_keys_.clear(); |
| 179 prefetch_values_.clear(); | 187 prefetch_values_.clear(); |
| 180 | 188 |
| 181 pending_onsuccess_callbacks_ = 0; | 189 pending_onsuccess_callbacks_ = 0; |
| 182 } | 190 } |
| OLD | NEW |