| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/child/indexed_db/webidbcursor_impl.h" | 5 #include "content/child/indexed_db/webidbcursor_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 14 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 13 #include "content/child/indexed_db/indexed_db_key_builders.h" | 15 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 14 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
| 15 #include "content/common/indexed_db/indexed_db_messages.h" | 17 #include "content/common/indexed_db/indexed_db_messages.h" |
| 16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" | 18 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" |
| 17 | 19 |
| 18 using blink::WebBlobInfo; | 20 using blink::WebBlobInfo; |
| 19 using blink::WebData; | 21 using blink::WebData; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 void WebIDBCursorImpl::advance(unsigned long count, | 55 void WebIDBCursorImpl::advance(unsigned long count, |
| 54 WebIDBCallbacks* callbacks_ptr) { | 56 WebIDBCallbacks* callbacks_ptr) { |
| 55 IndexedDBDispatcher* dispatcher = | 57 IndexedDBDispatcher* dispatcher = |
| 56 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 58 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
| 57 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 59 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 58 if (count <= prefetch_keys_.size()) { | 60 if (count <= prefetch_keys_.size()) { |
| 59 CachedAdvance(count, callbacks.get()); | 61 CachedAdvance(count, callbacks.get()); |
| 60 return; | 62 return; |
| 61 } | 63 } |
| 62 ResetPrefetchCache(); | 64 ResetPrefetchCache(); |
| 63 dispatcher->RequestIDBCursorAdvance( | 65 dispatcher->RequestIDBCursorAdvance(count, std::move(callbacks), |
| 64 count, callbacks.release(), ipc_cursor_id_, transaction_id_); | 66 ipc_cursor_id_, transaction_id_); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void WebIDBCursorImpl::continueFunction(const WebIDBKey& key, | 69 void WebIDBCursorImpl::continueFunction(const WebIDBKey& key, |
| 68 WebIDBCallbacks* callbacks_ptr) { | 70 WebIDBCallbacks* callbacks_ptr) { |
| 69 continueFunction(key, WebIDBKey::createNull(), callbacks_ptr); | 71 continueFunction(key, WebIDBKey::createNull(), callbacks_ptr); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void WebIDBCursorImpl::continueFunction(const WebIDBKey& key, | 74 void WebIDBCursorImpl::continueFunction(const WebIDBKey& key, |
| 73 const WebIDBKey& primary_key, | 75 const WebIDBKey& primary_key, |
| 74 WebIDBCallbacks* callbacks_ptr) { | 76 WebIDBCallbacks* callbacks_ptr) { |
| 75 IndexedDBDispatcher* dispatcher = | 77 IndexedDBDispatcher* dispatcher = |
| 76 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 78 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
| 77 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 79 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 78 | 80 |
| 79 if (key.keyType() == blink::WebIDBKeyTypeNull && | 81 if (key.keyType() == blink::WebIDBKeyTypeNull && |
| 80 primary_key.keyType() == blink::WebIDBKeyTypeNull) { | 82 primary_key.keyType() == blink::WebIDBKeyTypeNull) { |
| 81 // No key(s), so this would qualify for a prefetch. | 83 // No key(s), so this would qualify for a prefetch. |
| 82 ++continue_count_; | 84 ++continue_count_; |
| 83 | 85 |
| 84 if (!prefetch_keys_.empty()) { | 86 if (!prefetch_keys_.empty()) { |
| 85 // We have a prefetch cache, so serve the result from that. | 87 // We have a prefetch cache, so serve the result from that. |
| 86 CachedContinue(callbacks.get()); | 88 CachedContinue(callbacks.get()); |
| 87 return; | 89 return; |
| 88 } | 90 } |
| 89 | 91 |
| 90 if (continue_count_ > kPrefetchContinueThreshold) { | 92 if (continue_count_ > kPrefetchContinueThreshold) { |
| 91 // Request pre-fetch. | 93 // Request pre-fetch. |
| 92 ++pending_onsuccess_callbacks_; | 94 ++pending_onsuccess_callbacks_; |
| 93 dispatcher->RequestIDBCursorPrefetch( | 95 dispatcher->RequestIDBCursorPrefetch( |
| 94 prefetch_amount_, callbacks.release(), ipc_cursor_id_); | 96 prefetch_amount_, std::move(callbacks), ipc_cursor_id_); |
| 95 | 97 |
| 96 // Increase prefetch_amount_ exponentially. | 98 // Increase prefetch_amount_ exponentially. |
| 97 prefetch_amount_ *= 2; | 99 prefetch_amount_ *= 2; |
| 98 if (prefetch_amount_ > kMaxPrefetchAmount) | 100 if (prefetch_amount_ > kMaxPrefetchAmount) |
| 99 prefetch_amount_ = kMaxPrefetchAmount; | 101 prefetch_amount_ = kMaxPrefetchAmount; |
| 100 | 102 |
| 101 return; | 103 return; |
| 102 } | 104 } |
| 103 } else { | 105 } else { |
| 104 // Key argument supplied. We couldn't prefetch this. | 106 // Key argument supplied. We couldn't prefetch this. |
| 105 ResetPrefetchCache(); | 107 ResetPrefetchCache(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 dispatcher->RequestIDBCursorContinue(IndexedDBKeyBuilder::Build(key), | 110 dispatcher->RequestIDBCursorContinue( |
| 109 IndexedDBKeyBuilder::Build(primary_key), | 111 IndexedDBKeyBuilder::Build(key), IndexedDBKeyBuilder::Build(primary_key), |
| 110 callbacks.release(), | 112 std::move(callbacks), ipc_cursor_id_, transaction_id_); |
| 111 ipc_cursor_id_, | |
| 112 transaction_id_); | |
| 113 } | 113 } |
| 114 | 114 |
| 115 void WebIDBCursorImpl::postSuccessHandlerCallback() { | 115 void WebIDBCursorImpl::postSuccessHandlerCallback() { |
| 116 pending_onsuccess_callbacks_--; | 116 pending_onsuccess_callbacks_--; |
| 117 | 117 |
| 118 // If the onsuccess callback called continue()/advance() on the cursor | 118 // If the onsuccess callback called continue()/advance() on the cursor |
| 119 // again, and that request was served by the prefetch cache, then | 119 // again, and that request was served by the prefetch cache, then |
| 120 // pending_onsuccess_callbacks_ would be incremented. If not, it means the | 120 // pending_onsuccess_callbacks_ would be incremented. If not, it means the |
| 121 // callback did something else, or nothing at all, in which case we need to | 121 // callback did something else, or nothing at all, in which case we need to |
| 122 // reset the cache. | 122 // reset the cache. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 // Reset the prefetch cache. | 209 // Reset the prefetch cache. |
| 210 prefetch_keys_.clear(); | 210 prefetch_keys_.clear(); |
| 211 prefetch_primary_keys_.clear(); | 211 prefetch_primary_keys_.clear(); |
| 212 prefetch_values_.clear(); | 212 prefetch_values_.clear(); |
| 213 | 213 |
| 214 pending_onsuccess_callbacks_ = 0; | 214 pending_onsuccess_callbacks_ = 0; |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace content | 217 } // namespace content |
| OLD | NEW |