| 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 <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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 g_idb_dispatcher_tls.Pointer()->Set(this); | 54 g_idb_dispatcher_tls.Pointer()->Set(this); |
| 55 } | 55 } |
| 56 | 56 |
| 57 IndexedDBDispatcher::~IndexedDBDispatcher() { | 57 IndexedDBDispatcher::~IndexedDBDispatcher() { |
| 58 // Clear any pending callbacks - which may result in dispatch requests - | 58 // Clear any pending callbacks - which may result in dispatch requests - |
| 59 // before marking the dispatcher as deleted. | 59 // before marking the dispatcher as deleted. |
| 60 pending_callbacks_.Clear(); | 60 pending_callbacks_.Clear(); |
| 61 | 61 |
| 62 DCHECK(pending_callbacks_.IsEmpty()); | 62 DCHECK(pending_callbacks_.IsEmpty()); |
| 63 | 63 |
| 64 in_destructor_ = true; |
| 65 mojo_owned_callback_state_.clear(); |
| 66 mojo_owned_database_callback_state_.clear(); |
| 67 |
| 64 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 68 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
| 65 } | 69 } |
| 66 | 70 |
| 67 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( | 71 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance( |
| 68 ThreadSafeSender* thread_safe_sender) { | 72 ThreadSafeSender* thread_safe_sender) { |
| 69 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 73 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
| 70 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; | 74 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; |
| 71 g_idb_dispatcher_tls.Pointer()->Set(NULL); | 75 g_idb_dispatcher_tls.Pointer()->Set(NULL); |
| 72 } | 76 } |
| 73 if (g_idb_dispatcher_tls.Pointer()->Get()) | 77 if (g_idb_dispatcher_tls.Pointer()->Get()) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 DCHECK(!base::ContainsKey(cursors_, ipc_cursor_id)); | 193 DCHECK(!base::ContainsKey(cursors_, ipc_cursor_id)); |
| 190 cursors_[ipc_cursor_id] = cursor; | 194 cursors_[ipc_cursor_id] = cursor; |
| 191 } | 195 } |
| 192 | 196 |
| 193 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) { | 197 void IndexedDBDispatcher::CursorDestroyed(int32_t ipc_cursor_id) { |
| 194 cursors_.erase(ipc_cursor_id); | 198 cursors_.erase(ipc_cursor_id); |
| 195 } | 199 } |
| 196 | 200 |
| 197 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( | 201 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( |
| 198 IndexedDBCallbacksImpl::InternalState* callbacks) { | 202 IndexedDBCallbacksImpl::InternalState* callbacks) { |
| 199 mojo_owned_callback_state_.insert(callbacks); | 203 mojo_owned_callback_state_[callbacks] = base::WrapUnique(callbacks); |
| 200 } | 204 } |
| 201 | 205 |
| 202 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( | 206 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( |
| 203 IndexedDBCallbacksImpl::InternalState* callbacks) { | 207 IndexedDBCallbacksImpl::InternalState* callbacks) { |
| 204 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks)); | 208 if (in_destructor_) |
| 205 mojo_owned_callback_state_.erase(callbacks); | 209 return; |
| 210 |
| 211 auto it = mojo_owned_callback_state_.find(callbacks); |
| 212 DCHECK(it != mojo_owned_callback_state_.end()); |
| 213 it->second.release(); |
| 214 mojo_owned_callback_state_.erase(it); |
| 206 } | 215 } |
| 207 | 216 |
| 208 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( | 217 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( |
| 209 blink::WebIDBDatabaseCallbacks* callbacks) { | 218 blink::WebIDBDatabaseCallbacks* callbacks) { |
| 210 mojo_owned_database_callback_state_.insert(callbacks); | 219 mojo_owned_database_callback_state_[callbacks] = base::WrapUnique(callbacks); |
| 211 } | 220 } |
| 212 | 221 |
| 213 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( | 222 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( |
| 214 blink::WebIDBDatabaseCallbacks* callbacks) { | 223 blink::WebIDBDatabaseCallbacks* callbacks) { |
| 215 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks)); | 224 if (in_destructor_) |
| 216 mojo_owned_database_callback_state_.erase(callbacks); | 225 return; |
| 226 |
| 227 auto it = mojo_owned_database_callback_state_.find(callbacks); |
| 228 DCHECK(it != mojo_owned_database_callback_state_.end()); |
| 229 it->second.release(); |
| 230 mojo_owned_database_callback_state_.erase(it); |
| 217 } | 231 } |
| 218 | 232 |
| 219 // Populate some WebIDBValue members (data & blob info) from the supplied | 233 // Populate some WebIDBValue members (data & blob info) from the supplied |
| 220 // value message (IndexedDBMsg_Value or one that includes it). | 234 // value message (IndexedDBMsg_Value or one that includes it). |
| 221 template <class IndexedDBMsgValueType> | 235 template <class IndexedDBMsgValueType> |
| 222 static void PrepareWebValue(const IndexedDBMsgValueType& value, | 236 static void PrepareWebValue(const IndexedDBMsgValueType& value, |
| 223 WebIDBValue* web_value) { | 237 WebIDBValue* web_value) { |
| 224 if (value.bits.empty()) | 238 if (value.bits.empty()) |
| 225 return; | 239 return; |
| 226 | 240 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; | 372 typedef std::map<int32_t, WebIDBCursorImpl*>::iterator Iterator; |
| 359 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 373 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 360 if (i->first == ipc_exception_cursor_id || | 374 if (i->first == ipc_exception_cursor_id || |
| 361 i->second->transaction_id() != transaction_id) | 375 i->second->transaction_id() != transaction_id) |
| 362 continue; | 376 continue; |
| 363 i->second->ResetPrefetchCache(); | 377 i->second->ResetPrefetchCache(); |
| 364 } | 378 } |
| 365 } | 379 } |
| 366 | 380 |
| 367 } // namespace content | 381 } // namespace content |
| OLD | NEW |