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

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: Units tests added Created 4 years, 5 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.get());
176 observer->setId(observer_id);
dmurph 2016/06/30 00:14:06 Move this to IDBObserver pls.
palakj1 2016/06/30 01:07:04 Done.
177 observer.release();
178 Send(new IndexedDBHostMsg_DatabaseObserve(ipc_database_id, transaction_id,
179 observer_id));
180 return observer_id;
181 }
182
183 void IndexedDBDispatcher::RemoveIDBObserversFromDatabase(
184 int32_t ipc_database_id,
185 const std::vector<int32_t>& observer_ids_to_remove) {
186 for (int32_t id_to_remove : observer_ids_to_remove) {
187 observers_.Remove(id_to_remove);
188 }
189 Send(new IndexedDBHostMsg_DatabaseUnobserve(ipc_database_id,
190 observer_ids_to_remove));
191 }
192
193 void IndexedDBDispatcher::RemoveIDBObservers(
194 const std::set<int32_t>& observer_ids_to_remove) {
195 for (int32_t id : observer_ids_to_remove)
196 observers_.Remove(id);
197 }
198
170 void IndexedDBDispatcher::RequestIDBCursorAdvance( 199 void IndexedDBDispatcher::RequestIDBCursorAdvance(
171 unsigned long count, 200 unsigned long count,
172 WebIDBCallbacks* callbacks_ptr, 201 WebIDBCallbacks* callbacks_ptr,
173 int32_t ipc_cursor_id, 202 int32_t ipc_cursor_id,
174 int64_t transaction_id) { 203 int64_t transaction_id) {
175 // Reset all cursor prefetch caches except for this cursor. 204 // Reset all cursor prefetch caches except for this cursor.
176 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id); 205 ResetCursorPrefetchCaches(transaction_id, ipc_cursor_id);
177 206
178 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 207 std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
179 208
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; 829 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator;
801 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 830 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
802 if (i->first == ipc_exception_cursor_id || 831 if (i->first == ipc_exception_cursor_id ||
803 i->second->transaction_id() != transaction_id) 832 i->second->transaction_id() != transaction_id)
804 continue; 833 continue;
805 i->second->ResetPrefetchCache(); 834 i->second->ResetPrefetchCache();
806 } 835 }
807 } 836 }
808 837
809 } // namespace content 838 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698