| 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_child/indexed_db/proxy_webidbcursor_impl.h" | 5 #include "content/common_child/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_child/indexed_db/indexed_db_dispatcher.h" | 11 #include "content/common_child/indexed_db/indexed_db_dispatcher.h" |
| 12 | 12 |
| 13 using WebKit::WebData; | 13 using WebKit::WebData; |
| 14 using WebKit::WebIDBCallbacks; | 14 using WebKit::WebIDBCallbacks; |
| 15 using WebKit::WebIDBKey; | 15 using WebKit::WebIDBKey; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id) | 19 RendererWebIDBCursorImpl::RendererWebIDBCursorImpl(int32 ipc_cursor_id) |
| 20 : ipc_cursor_id_(ipc_cursor_id), | 20 : ipc_cursor_id_(ipc_cursor_id), |
| 21 continue_count_(0), | 21 continue_count_(0), |
| 22 used_prefetches_(0), | 22 used_prefetches_(0), |
| 23 pending_onsuccess_callbacks_(0), | 23 pending_onsuccess_callbacks_(0), |
| 24 prefetch_amount_(kMinPrefetchAmount) { | 24 prefetch_amount_(kMinPrefetchAmount) {} |
| 25 } | |
| 26 | 25 |
| 27 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { | 26 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { |
| 28 // It's not possible for there to be pending callbacks that address this | 27 // It's not possible for there to be pending callbacks that address this |
| 29 // object since inside WebKit, they hold a reference to the object which owns | 28 // object since inside WebKit, they hold a reference to the object which owns |
| 30 // this object. But, if that ever changed, then we'd need to invalidate | 29 // this object. But, if that ever changed, then we'd need to invalidate |
| 31 // any such pointers. | 30 // any such pointers. |
| 32 | 31 |
| 33 if (ipc_cursor_id_ != kInvalidCursorId) { | 32 if (ipc_cursor_id_ != kInvalidCursorId) { |
| 34 // Invalid ID used in tests to avoid really sending this message. | 33 // Invalid ID used in tests to avoid really sending this message. |
| 35 IndexedDBDispatcher::Send(new IndexedDBHostMsg_CursorDestroyed( | 34 IndexedDBDispatcher::Send( |
| 36 ipc_cursor_id_)); | 35 new IndexedDBHostMsg_CursorDestroyed(ipc_cursor_id_)); |
| 37 } | 36 } |
| 38 IndexedDBDispatcher* dispatcher = | 37 IndexedDBDispatcher* dispatcher = |
| 39 IndexedDBDispatcher::ThreadSpecificInstance(); | 38 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 40 dispatcher->CursorDestroyed(ipc_cursor_id_); | 39 dispatcher->CursorDestroyed(ipc_cursor_id_); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void RendererWebIDBCursorImpl::advance(unsigned long count, | 42 void RendererWebIDBCursorImpl::advance(unsigned long count, |
| 44 WebIDBCallbacks* callbacks_ptr) { | 43 WebIDBCallbacks* callbacks_ptr) { |
| 45 IndexedDBDispatcher* dispatcher = | 44 IndexedDBDispatcher* dispatcher = |
| 46 IndexedDBDispatcher::ThreadSpecificInstance(); | 45 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 47 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 46 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 48 ResetPrefetchCache(); | 47 ResetPrefetchCache(); |
| 49 dispatcher->RequestIDBCursorAdvance(count, callbacks.release(), | 48 dispatcher->RequestIDBCursorAdvance( |
| 50 ipc_cursor_id_); | 49 count, callbacks.release(), ipc_cursor_id_); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void RendererWebIDBCursorImpl::continueFunction( | 52 void RendererWebIDBCursorImpl::continueFunction( |
| 54 const WebIDBKey& key, | 53 const WebIDBKey& key, |
| 55 WebIDBCallbacks* callbacks_ptr) { | 54 WebIDBCallbacks* callbacks_ptr) { |
| 56 IndexedDBDispatcher* dispatcher = | 55 IndexedDBDispatcher* dispatcher = |
| 57 IndexedDBDispatcher::ThreadSpecificInstance(); | 56 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 58 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 57 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
| 59 | 58 |
| 60 if (key.type() == WebIDBKey::NullType) { | 59 if (key.type() == WebIDBKey::NullType) { |
| 61 // No key, so this would qualify for a prefetch. | 60 // No key, so this would qualify for a prefetch. |
| 62 ++continue_count_; | 61 ++continue_count_; |
| 63 | 62 |
| 64 if (!prefetch_keys_.empty()) { | 63 if (!prefetch_keys_.empty()) { |
| 65 // We have a prefetch cache, so serve the result from that. | 64 // We have a prefetch cache, so serve the result from that. |
| 66 CachedContinue(callbacks.get()); | 65 CachedContinue(callbacks.get()); |
| 67 return; | 66 return; |
| 68 } | 67 } |
| 69 | 68 |
| 70 if (continue_count_ > kPrefetchContinueThreshold) { | 69 if (continue_count_ > kPrefetchContinueThreshold) { |
| 71 // Request pre-fetch. | 70 // Request pre-fetch. |
| 72 ++pending_onsuccess_callbacks_; | 71 ++pending_onsuccess_callbacks_; |
| 73 dispatcher->RequestIDBCursorPrefetch(prefetch_amount_, | 72 dispatcher->RequestIDBCursorPrefetch( |
| 74 callbacks.release(), | 73 prefetch_amount_, callbacks.release(), ipc_cursor_id_); |
| 75 ipc_cursor_id_); | |
| 76 | 74 |
| 77 // Increase prefetch_amount_ exponentially. | 75 // Increase prefetch_amount_ exponentially. |
| 78 prefetch_amount_ *= 2; | 76 prefetch_amount_ *= 2; |
| 79 if (prefetch_amount_ > kMaxPrefetchAmount) | 77 if (prefetch_amount_ > kMaxPrefetchAmount) |
| 80 prefetch_amount_ = kMaxPrefetchAmount; | 78 prefetch_amount_ = kMaxPrefetchAmount; |
| 81 | 79 |
| 82 return; | 80 return; |
| 83 } | 81 } |
| 84 } else { | 82 } else { |
| 85 // Key argument supplied. We couldn't prefetch this. | 83 // Key argument supplied. We couldn't prefetch this. |
| 86 ResetPrefetchCache(); | 84 ResetPrefetchCache(); |
| 87 } | 85 } |
| 88 | 86 |
| 89 dispatcher->RequestIDBCursorContinue(IndexedDBKey(key), | 87 dispatcher->RequestIDBCursorContinue( |
| 90 callbacks.release(), | 88 IndexedDBKey(key), callbacks.release(), ipc_cursor_id_); |
| 91 ipc_cursor_id_); | |
| 92 } | |
| 93 | |
| 94 void RendererWebIDBCursorImpl::deleteFunction(WebIDBCallbacks* callbacks) { | |
| 95 IndexedDBDispatcher* dispatcher = | |
| 96 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 97 dispatcher->RequestIDBCursorDelete(callbacks, ipc_cursor_id_); | |
| 98 } | 89 } |
| 99 | 90 |
| 100 void RendererWebIDBCursorImpl::postSuccessHandlerCallback() { | 91 void RendererWebIDBCursorImpl::postSuccessHandlerCallback() { |
| 101 pending_onsuccess_callbacks_--; | 92 pending_onsuccess_callbacks_--; |
| 102 | 93 |
| 103 // If the onsuccess callback called continue() on the cursor again, | 94 // If the onsuccess callback called continue() on the cursor again, |
| 104 // and that continue was served by the prefetch cache, then | 95 // and that continue was served by the prefetch cache, then |
| 105 // pending_onsuccess_callbacks_ would be incremented. | 96 // pending_onsuccess_callbacks_ would be incremented. |
| 106 // If not, it means the callback did something else, or nothing at all, | 97 // If not, it means the callback did something else, or nothing at all, |
| 107 // in which case we need to reset the cache. | 98 // in which case we need to reset the cache. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 continue_count_ = 0; | 138 continue_count_ = 0; |
| 148 prefetch_amount_ = kMinPrefetchAmount; | 139 prefetch_amount_ = kMinPrefetchAmount; |
| 149 | 140 |
| 150 if (!prefetch_keys_.size()) { | 141 if (!prefetch_keys_.size()) { |
| 151 // No prefetch cache, so no need to reset the cursor in the back-end. | 142 // No prefetch cache, so no need to reset the cursor in the back-end. |
| 152 return; | 143 return; |
| 153 } | 144 } |
| 154 | 145 |
| 155 IndexedDBDispatcher* dispatcher = | 146 IndexedDBDispatcher* dispatcher = |
| 156 IndexedDBDispatcher::ThreadSpecificInstance(); | 147 IndexedDBDispatcher::ThreadSpecificInstance(); |
| 157 dispatcher->RequestIDBCursorPrefetchReset(used_prefetches_, | 148 dispatcher->RequestIDBCursorPrefetchReset( |
| 158 prefetch_keys_.size(), | 149 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_); |
| 159 ipc_cursor_id_); | |
| 160 prefetch_keys_.clear(); | 150 prefetch_keys_.clear(); |
| 161 prefetch_primary_keys_.clear(); | 151 prefetch_primary_keys_.clear(); |
| 162 prefetch_values_.clear(); | 152 prefetch_values_.clear(); |
| 163 | 153 |
| 164 pending_onsuccess_callbacks_ = 0; | 154 pending_onsuccess_callbacks_ = 0; |
| 165 } | 155 } |
| 166 | 156 |
| 167 } // namespace content | 157 } // namespace content |
| OLD | NEW |