Chromium Code Reviews| 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" |
| 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 |
| 13 using WebKit::WebExceptionCode; | 14 using WebKit::WebExceptionCode; |
| 14 using WebKit::WebIDBCallbacks; | 15 using WebKit::WebIDBCallbacks; |
| 15 using WebKit::WebIDBKey; | 16 using WebKit::WebIDBKey; |
| 16 using WebKit::WebSerializedScriptValue; | 17 using WebKit::WebSerializedScriptValue; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id) | 21 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id) |
| 21 : ipc_cursor_id_(ipc_cursor_id), | 22 : ipc_cursor_id_(ipc_cursor_id), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // If the onsuccess callback called continue() on the cursor again, | 102 // If the onsuccess callback called continue() on the cursor again, |
| 102 // and that continue was served by the prefetch cache, then | 103 // and that continue was served by the prefetch cache, then |
| 103 // pending_onsuccess_callbacks_ would be incremented. | 104 // pending_onsuccess_callbacks_ would be incremented. |
| 104 // If not, it means the callback did something else, or nothing at all, | 105 // If not, it means the callback did something else, or nothing at all, |
| 105 // in which case we need to reset the cache. | 106 // in which case we need to reset the cache. |
| 106 | 107 |
| 107 if (pending_onsuccess_callbacks_ == 0) | 108 if (pending_onsuccess_callbacks_ == 0) |
| 108 ResetPrefetchCache(); | 109 ResetPrefetchCache(); |
| 109 } | 110 } |
| 110 | 111 |
| 112 void RendererWebIDBCursorImpl::SetPrefetchDataOld( | |
| 113 const std::vector<IndexedDBKey>& keys, | |
| 114 const std::vector<IndexedDBKey>& primary_keys, | |
| 115 const std::vector<SerializedScriptValue>& values) { | |
| 116 prefetch_keys_.assign(keys.begin(), keys.end()); | |
| 117 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); | |
| 118 for (size_t i = 0; i < values.size(); ++i) { | |
| 119 // These casts are temporary as part of a refactoring. | |
| 120 // See https://code.google.com/p/chromium/issues/detail?id=156247 | |
| 121 const char* data = reinterpret_cast<const char*>(values[i].data().data()); | |
| 122 size_t size = values[i].data().length() / sizeof(string16::value_type); | |
| 123 | |
| 124 prefetch_values_.push_back(std::vector<char>(data, data + size)); | |
| 125 } | |
| 126 | |
| 127 used_prefetches_ = 0; | |
| 128 pending_onsuccess_callbacks_ = 0; | |
| 129 } | |
| 130 | |
| 111 void RendererWebIDBCursorImpl::SetPrefetchData( | 131 void RendererWebIDBCursorImpl::SetPrefetchData( |
| 112 const std::vector<IndexedDBKey>& keys, | 132 const std::vector<IndexedDBKey>& keys, |
| 113 const std::vector<IndexedDBKey>& primary_keys, | 133 const std::vector<IndexedDBKey>& primary_keys, |
| 114 const std::vector<SerializedScriptValue>& values) { | 134 const std::vector<WebKit::WebData>& values) { |
|
jsbell
2013/02/20 23:52:08
Add a using WebKit::WebData declaration up top to
alecflett
2013/02/21 00:14:16
Done.
| |
| 115 prefetch_keys_.assign(keys.begin(), keys.end()); | 135 prefetch_keys_.assign(keys.begin(), keys.end()); |
| 116 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); | 136 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); |
| 117 prefetch_values_.assign(values.begin(), values.end()); | 137 prefetch_values_.assign(values.begin(), values.end()); |
| 118 | 138 |
| 119 used_prefetches_ = 0; | 139 used_prefetches_ = 0; |
| 120 pending_onsuccess_callbacks_ = 0; | 140 pending_onsuccess_callbacks_ = 0; |
| 121 } | 141 } |
| 122 | 142 |
| 123 void RendererWebIDBCursorImpl::CachedContinue( | 143 void RendererWebIDBCursorImpl::CachedContinueOld( |
| 124 WebKit::WebIDBCallbacks* callbacks) { | 144 WebKit::WebIDBCallbacks* callbacks) { |
| 125 DCHECK_GT(prefetch_keys_.size(), 0ul); | 145 DCHECK_GT(prefetch_keys_.size(), 0ul); |
| 126 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); | 146 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); |
| 127 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); | 147 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); |
| 128 | 148 |
| 129 IndexedDBKey key = prefetch_keys_.front(); | 149 IndexedDBKey key = prefetch_keys_.front(); |
| 130 IndexedDBKey primary_key = prefetch_primary_keys_.front(); | 150 IndexedDBKey primary_key = prefetch_primary_keys_.front(); |
| 131 SerializedScriptValue value = prefetch_values_.front(); | 151 // These casts are temporary as part of a refactoring. |
| 152 // See https://code.google.com/p/chromium/issues/detail?id=156247 | |
| 153 WebKit::WebData prefetch_value = prefetch_values_.front(); | |
| 154 string16 prefetch_string( | |
| 155 reinterpret_cast<string16::const_pointer>(prefetch_value.data()), | |
| 156 reinterpret_cast<string16::const_pointer>(prefetch_value.data() + | |
| 157 prefetch_value.size())); | |
| 158 SerializedScriptValue value; value.set_data(prefetch_string); | |
| 132 | 159 |
| 133 prefetch_keys_.pop_front(); | 160 prefetch_keys_.pop_front(); |
| 134 prefetch_primary_keys_.pop_front(); | 161 prefetch_primary_keys_.pop_front(); |
| 135 prefetch_values_.pop_front(); | 162 prefetch_values_.pop_front(); |
| 136 used_prefetches_++; | 163 used_prefetches_++; |
| 137 | 164 |
| 138 pending_onsuccess_callbacks_++; | 165 pending_onsuccess_callbacks_++; |
| 139 | 166 |
| 140 callbacks->onSuccess(key, primary_key, | 167 callbacks->onSuccess(key, primary_key, |
| 141 WebSerializedScriptValue(value)); | 168 WebSerializedScriptValue(value)); |
| 142 } | 169 } |
| 143 | 170 |
| 171 void RendererWebIDBCursorImpl::CachedContinue( | |
| 172 WebKit::WebIDBCallbacks* callbacks) { | |
| 173 DCHECK_GT(prefetch_keys_.size(), 0ul); | |
| 174 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); | |
| 175 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); | |
| 176 | |
| 177 IndexedDBKey key = prefetch_keys_.front(); | |
| 178 IndexedDBKey primary_key = prefetch_primary_keys_.front(); | |
| 179 // this could be a real problem.. we need 2 CachedContinues | |
| 180 WebKit::WebData value = prefetch_values_.front(); | |
| 181 | |
| 182 prefetch_keys_.pop_front(); | |
| 183 prefetch_primary_keys_.pop_front(); | |
| 184 prefetch_values_.pop_front(); | |
| 185 used_prefetches_++; | |
| 186 | |
| 187 pending_onsuccess_callbacks_++; | |
| 188 | |
| 189 callbacks->onSuccess(key, primary_key, value); | |
| 190 } | |
| 191 | |
| 144 void RendererWebIDBCursorImpl::ResetPrefetchCache() { | 192 void RendererWebIDBCursorImpl::ResetPrefetchCache() { |
| 145 continue_count_ = 0; | 193 continue_count_ = 0; |
| 146 prefetch_amount_ = kMinPrefetchAmount; | 194 prefetch_amount_ = kMinPrefetchAmount; |
| 147 | 195 |
| 148 if (!prefetch_keys_.size()) { | 196 if (!prefetch_keys_.size()) { |
| 149 // No prefetch cache, so no need to reset the cursor in the back-end. | 197 // No prefetch cache, so no need to reset the cursor in the back-end. |
| 150 return; | 198 return; |
| 151 } | 199 } |
| 152 | 200 |
| 153 IndexedDBDispatcher* dispatcher = | 201 IndexedDBDispatcher* dispatcher = |
| 154 IndexedDBDispatcher::ThreadSpecificInstance(); | 202 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 155 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, | 203 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, |
| 156 prefetch_keys_.size(), | 204 prefetch_keys_.size(), |
| 157 ipc_cursor_id_); | 205 ipc_cursor_id_); |
| 158 prefetch_keys_.clear(); | 206 prefetch_keys_.clear(); |
| 159 prefetch_primary_keys_.clear(); | 207 prefetch_primary_keys_.clear(); |
| 160 prefetch_values_.clear(); | 208 prefetch_values_.clear(); |
| 161 | 209 |
| 162 pending_onsuccess_callbacks_ = 0; | 210 pending_onsuccess_callbacks_ = 0; |
| 163 } | 211 } |
| 164 | 212 |
| 165 } // namespace content | 213 } // namespace content |
| OLD | NEW |