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

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

Issue 2525443002: [IndexedDB] Delete callbacks state on worker thread exit. (Closed)
Patch Set: Created 4 years 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 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 IndexedDBCallbacksImpl::InternalState* callback_state); 120 IndexedDBCallbacksImpl::InternalState* callback_state);
121 void RegisterMojoOwnedDatabaseCallbacks( 121 void RegisterMojoOwnedDatabaseCallbacks(
122 blink::WebIDBDatabaseCallbacks* callback_state); 122 blink::WebIDBDatabaseCallbacks* callback_state);
123 void UnregisterMojoOwnedDatabaseCallbacks( 123 void UnregisterMojoOwnedDatabaseCallbacks(
124 blink::WebIDBDatabaseCallbacks* callback_state); 124 blink::WebIDBDatabaseCallbacks* callback_state);
125 125
126 private: 126 private:
127 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); 127 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset);
128 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); 128 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId);
129 129
130 // Looking up move-only entries in an std::unordered_set and removing them
131 // with out freeing them seems to be impossible so use a map instead so that
jsbell 2016/11/21 22:38:06 nit: "...impossible so use a map..." -> "...imposs
132 // the key type can remain a raw pointer.
133 using CallbackStateSet = std::unordered_map<
134 IndexedDBCallbacksImpl::InternalState*,
135 std::unique_ptr<IndexedDBCallbacksImpl::InternalState>>;
136 using DatabaseCallbackStateSet =
137 std::unordered_map<blink::WebIDBDatabaseCallbacks*,
138 std::unique_ptr<blink::WebIDBDatabaseCallbacks>>;
139
130 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); } 140 static int32_t CurrentWorkerId() { return WorkerThread::GetCurrentId(); }
131 141
132 template <typename T> 142 template <typename T>
133 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) { 143 void init_params(T* params, blink::WebIDBCallbacks* callbacks_ptr) {
134 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr); 144 std::unique_ptr<blink::WebIDBCallbacks> callbacks(callbacks_ptr);
135 params->ipc_thread_id = CurrentWorkerId(); 145 params->ipc_thread_id = CurrentWorkerId();
136 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release()); 146 params->ipc_callbacks_id = pending_callbacks_.Add(callbacks.release());
137 } 147 }
138 148
139 // IDBCallback message handlers. 149 // IDBCallback message handlers.
(...skipping 17 matching lines...) Expand all
157 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be 167 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
158 // destroyed and used on the same thread it was created on. 168 // destroyed and used on the same thread it was created on.
159 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; 169 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_;
160 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_; 170 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_;
161 171
162 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl 172 // Holds pointers to the worker-thread owned state of IndexedDBCallbacksImpl
163 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is 173 // and IndexedDBDatabaseCallbacksImpl objects to makes sure that it is
164 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the 174 // destroyed on thread exit if the Mojo pipe is not yet closed. Otherwise the
165 // object will leak because the thread's task runner is no longer executing 175 // object will leak because the thread's task runner is no longer executing
166 // tasks. 176 // tasks.
167 std::unordered_set<IndexedDBCallbacksImpl::InternalState*> 177 CallbackStateSet mojo_owned_callback_state_;
168 mojo_owned_callback_state_; 178 DatabaseCallbackStateSet mojo_owned_database_callback_state_;
169 std::unordered_set<blink::WebIDBDatabaseCallbacks*>
170 mojo_owned_database_callback_state_;
171 179
172 // Maps the ipc_callback_id from an open cursor request to the request's 180 // Maps the ipc_callback_id from an open cursor request to the request's
173 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl 181 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl
174 // when it is created. 182 // when it is created.
175 std::map<int32_t, int64_t> cursor_transaction_ids_; 183 std::map<int32_t, int64_t> cursor_transaction_ids_;
176 184
177 // Map from cursor id to WebIDBCursorImpl. 185 // Map from cursor id to WebIDBCursorImpl.
178 std::map<int32_t, WebIDBCursorImpl*> cursors_; 186 std::map<int32_t, WebIDBCursorImpl*> cursors_;
179 187
180 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 188 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
181 }; 189 };
182 190
183 } // namespace content 191 } // namespace content
184 192
185 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 193 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | content/child/indexed_db/indexed_db_dispatcher.cc » ('j') | content/child/indexed_db/indexed_db_dispatcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698