Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.cc

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Post dmurph review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 12 matching lines...) Expand all
23 23
24 using blink::WebBlobInfo; 24 using blink::WebBlobInfo;
25 using blink::WebData; 25 using blink::WebData;
26 using blink::WebIDBCallbacks; 26 using blink::WebIDBCallbacks;
27 using blink::WebIDBCursor; 27 using blink::WebIDBCursor;
28 using blink::WebIDBDatabase; 28 using blink::WebIDBDatabase;
29 using blink::WebIDBDatabaseCallbacks; 29 using blink::WebIDBDatabaseCallbacks;
30 using blink::WebIDBDatabaseError; 30 using blink::WebIDBDatabaseError;
31 using blink::WebIDBKey; 31 using blink::WebIDBKey;
32 using blink::WebIDBMetadata; 32 using blink::WebIDBMetadata;
33 using blink::WebIDBObserver;
33 using blink::WebIDBValue; 34 using blink::WebIDBValue;
34 using blink::WebString; 35 using blink::WebString;
35 using blink::WebVector; 36 using blink::WebVector;
36 using base::ThreadLocalPointer; 37 using base::ThreadLocalPointer;
37 38
38 namespace content { 39 namespace content {
39 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky 40 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky
40 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 41 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
41 42
42 namespace { 43 namespace {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // If a message gets here, IndexedDBMessageFilter already determined that it 161 // If a message gets here, IndexedDBMessageFilter already determined that it
161 // is an IndexedDB message. 162 // is an IndexedDB message.
162 DCHECK(handled) << "Didn't handle a message defined at line " 163 DCHECK(handled) << "Didn't handle a message defined at line "
163 << IPC_MESSAGE_ID_LINE(msg.type()); 164 << IPC_MESSAGE_ID_LINE(msg.type());
164 } 165 }
165 166
166 bool IndexedDBDispatcher::Send(IPC::Message* msg) { 167 bool IndexedDBDispatcher::Send(IPC::Message* msg) {
167 return thread_safe_sender_->Send(msg); 168 return thread_safe_sender_->Send(msg);
168 } 169 }
169 170
171 int32_t IndexedDBDispatcher::AddIDBObserver(
172 int32_t ipc_database_id,
173 int64_t transaction_id,
174 std::unique_ptr<WebIDBObserver> observer) {
175 int32_t observer_id = observers_.Add(observer.release());
176 Send(new IndexedDBHostMsg_DatabaseObserve(ipc_database_id, transaction_id,
177 observer_id));
178 return observer_id;
179 }
180
181 std::vector<int32_t> IndexedDBDispatcher::RemoveIDBObserversFromDatabase(
182 int32_t ipc_database_id,
183 std::unique_ptr<WebIDBObserver> observer,
184 const std::vector<int32_t>& database_observer_ids) {
185 std::vector<int32_t> observer_ids_to_remove;
186 for (uint32_t i = 0; i < database_observer_ids.size(); i++) {
187 if (observers_.Lookup(database_observer_ids[i]) == observer.get()) {
Marijn Kruisselbrink 2016/06/24 00:48:09 I'm confused about this check. observers_ owns Web
188 observers_.Remove(database_observer_ids[i]);
189 observer_ids_to_remove.push_back(database_observer_ids[i]);
190 }
191 }
192 Send(new IndexedDBHostMsg_DatabaseUnobserve(ipc_database_id,
193 observer_ids_to_remove));
194 return observer_ids_to_remove;
195 }
196
197 void IndexedDBDispatcher::RemoveIDBObservers(
198 const std::vector<int32_t>& observer_ids_to_remove) {
199 for (uint32_t i = 0; i < observer_ids_to_remove.size(); i++) {
200 observers_.Remove(observer_ids_to_remove[i]);
201 }
202 }
203
170 void IndexedDBDispatcher::RequestIDBCursorAdvance( 204 void IndexedDBDispatcher::RequestIDBCursorAdvance(
171 unsigned long count, 205 unsigned long count,
172 WebIDBCallbacks* callbacks_ptr, 206 WebIDBCallbacks* callbacks_ptr,
173 int32_t ipc_cursor_id, 207 int32_t ipc_cursor_id,
174 int64_t transaction_id) { 208 int64_t transaction_id) {
175 // Reset all cursor prefetch caches except for this cursor. 209 // Reset all cursor prefetch caches except for this cursor.
176 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); 210 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id);
177 211
178 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 212 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
179 213
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; 834 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator;
801 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 835 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
802 if (i->first == ipc_exception_cursor_id || 836 if (i->first == ipc_exception_cursor_id ||
803 i->second->transaction_id() != transaction_id) 837 i->second->transaction_id() != transaction_id)
804 continue; 838 continue;
805 i->second->ResetPrefetchCache(); 839 i->second->ResetPrefetchCache();
806 } 840 }
807 } 841 }
808 842
809 } // namespace content 843 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698