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/proxy_webidbcursor_impl.h" | 5 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "content/child/child_thread.h" | 9 #include "content/child/thread_safe_sender.h" |
10 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 10 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
11 #include "content/common/indexed_db/indexed_db_messages.h" | 11 #include "content/common/indexed_db/indexed_db_messages.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( |
| 20 int32 ipc_cursor_id, |
| 21 ThreadSafeSender* thread_safe_sender) |
20 : ipc_cursor_id_(ipc_cursor_id), | 22 : ipc_cursor_id_(ipc_cursor_id), |
21 continue_count_(0), | 23 continue_count_(0), |
22 used_prefetches_(0), | 24 used_prefetches_(0), |
23 pending_onsuccess_callbacks_(0), | 25 pending_onsuccess_callbacks_(0), |
24 prefetch_amount_(kMinPrefetchAmount) {} | 26 prefetch_amount_(kMinPrefetchAmount), |
| 27 thread_safe_sender_(thread_safe_sender) {} |
25 | 28 |
26 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { | 29 RendererWebIDBCursorImpl::~RendererWebIDBCursorImpl() { |
27 // It's not possible for there to be pending callbacks that address this | 30 // It's not possible for there to be pending callbacks that address this |
28 // object since inside WebKit, they hold a reference to the object which owns | 31 // object since inside WebKit, they hold a reference to the object which owns |
29 // this object. But, if that ever changed, then we'd need to invalidate | 32 // this object. But, if that ever changed, then we'd need to invalidate |
30 // any such pointers. | 33 // any such pointers. |
31 | 34 |
32 if (ipc_cursor_id_ != kInvalidCursorId) { | 35 if (ipc_cursor_id_ != kInvalidCursorId) { |
33 // Invalid ID used in tests to avoid really sending this message. | 36 // Invalid ID used in tests to avoid really sending this message. |
34 IndexedDBDispatcher::Send( | 37 thread_safe_sender_->Send( |
35 new IndexedDBHostMsg_CursorDestroyed(ipc_cursor_id_)); | 38 new IndexedDBHostMsg_CursorDestroyed(ipc_cursor_id_)); |
36 } | 39 } |
37 IndexedDBDispatcher* dispatcher = | 40 IndexedDBDispatcher* dispatcher = |
38 IndexedDBDispatcher::ThreadSpecificInstance(); | 41 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_); |
39 dispatcher->CursorDestroyed(ipc_cursor_id_); | 42 dispatcher->CursorDestroyed(ipc_cursor_id_); |
40 } | 43 } |
41 | 44 |
42 void RendererWebIDBCursorImpl::advance(unsigned long count, | 45 void RendererWebIDBCursorImpl::advance(unsigned long count, |
43 WebIDBCallbacks* callbacks_ptr) { | 46 WebIDBCallbacks* callbacks_ptr) { |
44 IndexedDBDispatcher* dispatcher = | 47 IndexedDBDispatcher* dispatcher = |
45 IndexedDBDispatcher::ThreadSpecificInstance(); | 48 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_); |
46 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 49 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
47 ResetPrefetchCache(); | 50 ResetPrefetchCache(); |
48 dispatcher->RequestIDBCursorAdvance( | 51 dispatcher->RequestIDBCursorAdvance( |
49 count, callbacks.release(), ipc_cursor_id_); | 52 count, callbacks.release(), ipc_cursor_id_); |
50 } | 53 } |
51 | 54 |
52 void RendererWebIDBCursorImpl::continueFunction( | 55 void RendererWebIDBCursorImpl::continueFunction( |
53 const WebIDBKey& key, | 56 const WebIDBKey& key, |
54 WebIDBCallbacks* callbacks_ptr) { | 57 WebIDBCallbacks* callbacks_ptr) { |
55 IndexedDBDispatcher* dispatcher = | 58 IndexedDBDispatcher* dispatcher = |
56 IndexedDBDispatcher::ThreadSpecificInstance(); | 59 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_); |
57 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 60 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
58 | 61 |
59 if (key.type() == WebIDBKey::NullType) { | 62 if (key.type() == WebIDBKey::NullType) { |
60 // No key, so this would qualify for a prefetch. | 63 // No key, so this would qualify for a prefetch. |
61 ++continue_count_; | 64 ++continue_count_; |
62 | 65 |
63 if (!prefetch_keys_.empty()) { | 66 if (!prefetch_keys_.empty()) { |
64 // We have a prefetch cache, so serve the result from that. | 67 // We have a prefetch cache, so serve the result from that. |
65 CachedContinue(callbacks.get()); | 68 CachedContinue(callbacks.get()); |
66 return; | 69 return; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void RendererWebIDBCursorImpl::ResetPrefetchCache() { | 140 void RendererWebIDBCursorImpl::ResetPrefetchCache() { |
138 continue_count_ = 0; | 141 continue_count_ = 0; |
139 prefetch_amount_ = kMinPrefetchAmount; | 142 prefetch_amount_ = kMinPrefetchAmount; |
140 | 143 |
141 if (!prefetch_keys_.size()) { | 144 if (!prefetch_keys_.size()) { |
142 // No prefetch cache, so no need to reset the cursor in the back-end. | 145 // No prefetch cache, so no need to reset the cursor in the back-end. |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 IndexedDBDispatcher* dispatcher = | 149 IndexedDBDispatcher* dispatcher = |
147 IndexedDBDispatcher::ThreadSpecificInstance(); | 150 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_); |
148 dispatcher->RequestIDBCursorPrefetchReset( | 151 dispatcher->RequestIDBCursorPrefetchReset( |
149 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_); | 152 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_); |
150 prefetch_keys_.clear(); | 153 prefetch_keys_.clear(); |
151 prefetch_primary_keys_.clear(); | 154 prefetch_primary_keys_.clear(); |
152 prefetch_values_.clear(); | 155 prefetch_values_.clear(); |
153 | 156 |
154 pending_onsuccess_callbacks_ = 0; | 157 pending_onsuccess_callbacks_ = 0; |
155 } | 158 } |
156 | 159 |
157 } // namespace content | 160 } // namespace content |
OLD | NEW |