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

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: Observer moved to connection 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(int32_t ipc_database_id,
172 int64_t transaction_id,
173 WebIDBObserver* observer) {
174 // TODO(palakj): Do I wrap WebIDBObserver with unique_ptr as in
dmurph 2016/06/22 01:09:49 unique_ptr
175 // WebIDBCallbacks.
176 int32_t observer_id = observers_.Add(observer);
177 Send(new IndexedDBHostMsg_DatabaseObserve(ipc_database_id, transaction_id,
178 observer_id));
179 return observer_id;
180 }
181
182 std::vector<int32_t> IndexedDBDispatcher::RemoveIDBObservers(
183 int32_t ipc_database_id,
184 WebIDBObserver* observer,
185 std::vector<int32_t> database_observers_id) {
186 std::vector<int32_t> observersToRemove;
dmurph 2016/06/22 01:09:49 no camelCase
187 for (uint32_t i = 0; i < database_observers_id.size(); i++) {
188 WebIDBObserver* obs = observers_.Lookup(database_observers_id[i]);
189 if (obs == observer) {
190 observers_.Remove(database_observers_id[i]);
191 observersToRemove.push_back(database_observers_id[i]);
192 }
193 }
194
195 Send(new IndexedDBHostMsg_DatabaseUnobserve(ipc_database_id,
196 observersToRemove));
197 return observersToRemove;
198 }
199
200 void IndexedDBDispatcher::ClearIDBObserver(
dmurph 2016/06/22 01:09:49 I don't think this method needs to unobserve on th
201 std::vector<int32_t> observersToRemove) {
202 for (uint32_t i = 0; i < observersToRemove.size(); i++) {
203 observers_.Remove(observersToRemove[i]);
204 }
205 }
206
170 void IndexedDBDispatcher::RequestIDBCursorAdvance( 207 void IndexedDBDispatcher::RequestIDBCursorAdvance(
171 unsigned long count, 208 unsigned long count,
172 WebIDBCallbacks* callbacks_ptr, 209 WebIDBCallbacks* callbacks_ptr,
173 int32_t ipc_cursor_id, 210 int32_t ipc_cursor_id,
174 int64_t transaction_id) { 211 int64_t transaction_id) {
175 // Reset all cursor prefetch caches except for this cursor. 212 // Reset all cursor prefetch caches except for this cursor.
176 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); 213 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id);
177 214
178 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 215 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
179 216
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; 837 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator;
801 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 838 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
802 if (i->first == ipc_exception_cursor_id || 839 if (i->first == ipc_exception_cursor_id ||
803 i->second->transaction_id() != transaction_id) 840 i->second->transaction_id() != transaction_id)
804 continue; 841 continue;
805 i->second->ResetPrefetchCache(); 842 i->second->ResetPrefetchCache();
806 } 843 }
807 } 844 }
808 845
809 } // namespace content 846 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698