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/indexed_db_dispatcher.h" | 5 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
13 #include "content/child/indexed_db/indexed_db_key_builders.h" | 14 #include "content/child/indexed_db/indexed_db_key_builders.h" |
14 #include "content/child/indexed_db/webidbcursor_impl.h" | 15 #include "content/child/indexed_db/webidbcursor_impl.h" |
15 #include "content/child/indexed_db/webidbdatabase_impl.h" | 16 #include "content/child/indexed_db/webidbdatabase_impl.h" |
16 #include "content/child/thread_safe_sender.h" | 17 #include "content/child/thread_safe_sender.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 DCHECK(handled) << "Didn't handle a message defined at line " | 120 DCHECK(handled) << "Didn't handle a message defined at line " |
120 << IPC_MESSAGE_ID_LINE(msg.type()); | 121 << IPC_MESSAGE_ID_LINE(msg.type()); |
121 } | 122 } |
122 | 123 |
123 bool IndexedDBDispatcher::Send(IPC::Message* msg) { | 124 bool IndexedDBDispatcher::Send(IPC::Message* msg) { |
124 return thread_safe_sender_->Send(msg); | 125 return thread_safe_sender_->Send(msg); |
125 } | 126 } |
126 | 127 |
127 int32_t IndexedDBDispatcher::RegisterObserver( | 128 int32_t IndexedDBDispatcher::RegisterObserver( |
128 std::unique_ptr<WebIDBObserver> observer) { | 129 std::unique_ptr<WebIDBObserver> observer) { |
129 return observers_.Add(observer.release()); | 130 return observers_.Add(std::move(observer)); |
130 } | 131 } |
131 | 132 |
132 void IndexedDBDispatcher::RemoveObservers( | 133 void IndexedDBDispatcher::RemoveObservers( |
133 const std::vector<int32_t>& observer_ids_to_remove) { | 134 const std::vector<int32_t>& observer_ids_to_remove) { |
134 for (int32_t id : observer_ids_to_remove) | 135 for (int32_t id : observer_ids_to_remove) |
135 observers_.Remove(id); | 136 observers_.Remove(id); |
136 } | 137 } |
137 | 138 |
138 void IndexedDBDispatcher::RequestIDBCursorAdvance( | 139 void IndexedDBDispatcher::RequestIDBCursorAdvance( |
139 unsigned long count, | 140 unsigned long count, |
140 WebIDBCallbacks* callbacks_ptr, | 141 std::unique_ptr<WebIDBCallbacks> callbacks_ptr, |
141 int32_t ipc_cursor_id, | 142 int32_t ipc_cursor_id, |
142 int64_t transaction_id) { | 143 int64_t transaction_id) { |
143 // Reset all cursor prefetch caches except for this cursor. | 144 // Reset all cursor prefetch caches except for this cursor. |
144 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); | 145 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); |
145 | 146 |
146 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 147 int32_t ipc_callbacks_id = pending_callbacks_.Add(std::move(callbacks_ptr)); |
147 | |
148 int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
149 Send(new IndexedDBHostMsg_CursorAdvance( | 148 Send(new IndexedDBHostMsg_CursorAdvance( |
150 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, count)); | 149 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, count)); |
151 } | 150 } |
152 | 151 |
153 void IndexedDBDispatcher::RequestIDBCursorContinue( | 152 void IndexedDBDispatcher::RequestIDBCursorContinue( |
154 const IndexedDBKey& key, | 153 const IndexedDBKey& key, |
155 const IndexedDBKey& primary_key, | 154 const IndexedDBKey& primary_key, |
156 WebIDBCallbacks* callbacks_ptr, | 155 std::unique_ptr<WebIDBCallbacks> callbacks_ptr, |
157 int32_t ipc_cursor_id, | 156 int32_t ipc_cursor_id, |
158 int64_t transaction_id) { | 157 int64_t transaction_id) { |
159 // Reset all cursor prefetch caches except for this cursor. | 158 // Reset all cursor prefetch caches except for this cursor. |
160 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); | 159 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); |
161 | 160 |
162 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 161 int32_t ipc_callbacks_id = pending_callbacks_.Add(std::move(callbacks_ptr)); |
163 | |
164 int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
165 Send(new IndexedDBHostMsg_CursorContinue( | 162 Send(new IndexedDBHostMsg_CursorContinue( |
166 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, key, primary_key)); | 163 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, key, primary_key)); |
167 } | 164 } |
168 | 165 |
169 void IndexedDBDispatcher::RequestIDBCursorPrefetch( | 166 void IndexedDBDispatcher::RequestIDBCursorPrefetch( |
170 int n, | 167 int n, |
171 WebIDBCallbacks* callbacks_ptr, | 168 std::unique_ptr<WebIDBCallbacks> callbacks_ptr, |
172 int32_t ipc_cursor_id) { | 169 int32_t ipc_cursor_id) { |
173 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 170 int32_t ipc_callbacks_id = pending_callbacks_.Add(std::move(callbacks_ptr)); |
174 | |
175 int32_t ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); | |
176 Send(new IndexedDBHostMsg_CursorPrefetch( | 171 Send(new IndexedDBHostMsg_CursorPrefetch( |
177 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n)); | 172 ipc_cursor_id, CurrentWorkerId(), ipc_callbacks_id, n)); |
178 } | 173 } |
179 | 174 |
180 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, | 175 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(int used_prefetches, |
181 int unused_prefetches, | 176 int unused_prefetches, |
182 int32_t ipc_cursor_id) { | 177 int32_t ipc_cursor_id) { |
183 Send(new IndexedDBHostMsg_CursorPrefetchReset( | 178 Send(new IndexedDBHostMsg_CursorPrefetchReset( |
184 ipc_cursor_id, used_prefetches, unused_prefetches)); | 179 ipc_cursor_id, used_prefetches, unused_prefetches)); |
185 } | 180 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 353 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
359 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 354 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
360 if (i->first == ipc_exception_cursor_id || | 355 if (i->first == ipc_exception_cursor_id || |
361 i->second->transaction_id() != transaction_id) | 356 i->second->transaction_id() != transaction_id) |
362 continue; | 357 continue; |
363 i->second->ResetPrefetchCache(); | 358 i->second->ResetPrefetchCache(); |
364 } | 359 } |
365 } | 360 } |
366 | 361 |
367 } // namespace content | 362 } // namespace content |
OLD | NEW |