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

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

Issue 2524823002: Reland: [IndexedDB] Delete callbacks state on worker thread exit. (Closed)
Patch Set: Rebased. Created 4 years, 1 month 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
« no previous file with comments | « content/child/indexed_db/indexed_db_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 18 matching lines...) Expand all
29 IndexedDBDispatcher* const kHasBeenDeleted = 29 IndexedDBDispatcher* const kHasBeenDeleted =
30 reinterpret_cast<IndexedDBDispatcher*>(0x1); 30 reinterpret_cast<IndexedDBDispatcher*>(0x1);
31 31
32 } // unnamed namespace 32 } // unnamed namespace
33 33
34 IndexedDBDispatcher::IndexedDBDispatcher() { 34 IndexedDBDispatcher::IndexedDBDispatcher() {
35 g_idb_dispatcher_tls.Pointer()->Set(this); 35 g_idb_dispatcher_tls.Pointer()->Set(this);
36 } 36 }
37 37
38 IndexedDBDispatcher::~IndexedDBDispatcher() { 38 IndexedDBDispatcher::~IndexedDBDispatcher() {
39 in_destructor_ = true;
40 mojo_owned_callback_state_.clear();
41 mojo_owned_database_callback_state_.clear();
42
39 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); 43 g_idb_dispatcher_tls.Pointer()->Set(kHasBeenDeleted);
40 } 44 }
41 45
42 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() { 46 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() {
43 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { 47 if (g_idb_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) {
44 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; 48 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher.";
45 g_idb_dispatcher_tls.Pointer()->Set(NULL); 49 g_idb_dispatcher_tls.Pointer()->Set(NULL);
46 } 50 }
47 if (g_idb_dispatcher_tls.Pointer()->Get()) 51 if (g_idb_dispatcher_tls.Pointer()->Get())
48 return g_idb_dispatcher_tls.Pointer()->Get(); 52 return g_idb_dispatcher_tls.Pointer()->Get();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 95 }
92 96
93 void IndexedDBDispatcher::RemoveObservers( 97 void IndexedDBDispatcher::RemoveObservers(
94 const std::vector<int32_t>& observer_ids_to_remove) { 98 const std::vector<int32_t>& observer_ids_to_remove) {
95 for (int32_t id : observer_ids_to_remove) 99 for (int32_t id : observer_ids_to_remove)
96 observers_.Remove(id); 100 observers_.Remove(id);
97 } 101 }
98 102
99 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( 103 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks(
100 IndexedDBCallbacksImpl::InternalState* callbacks) { 104 IndexedDBCallbacksImpl::InternalState* callbacks) {
101 mojo_owned_callback_state_.insert(callbacks); 105 mojo_owned_callback_state_[callbacks] = base::WrapUnique(callbacks);
102 } 106 }
103 107
104 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( 108 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks(
105 IndexedDBCallbacksImpl::InternalState* callbacks) { 109 IndexedDBCallbacksImpl::InternalState* callbacks) {
106 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks)); 110 if (in_destructor_)
107 mojo_owned_callback_state_.erase(callbacks); 111 return;
112
113 auto it = mojo_owned_callback_state_.find(callbacks);
114 DCHECK(it != mojo_owned_callback_state_.end());
115 it->second.release();
116 mojo_owned_callback_state_.erase(it);
108 } 117 }
109 118
110 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( 119 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks(
111 blink::WebIDBDatabaseCallbacks* callbacks) { 120 blink::WebIDBDatabaseCallbacks* callbacks) {
112 mojo_owned_database_callback_state_.insert(callbacks); 121 mojo_owned_database_callback_state_[callbacks] = base::WrapUnique(callbacks);
113 } 122 }
114 123
115 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( 124 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks(
116 blink::WebIDBDatabaseCallbacks* callbacks) { 125 blink::WebIDBDatabaseCallbacks* callbacks) {
117 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks)); 126 if (in_destructor_)
118 mojo_owned_database_callback_state_.erase(callbacks); 127 return;
128
129 auto it = mojo_owned_database_callback_state_.find(callbacks);
130 DCHECK(it != mojo_owned_database_callback_state_.end());
131 it->second.release();
132 mojo_owned_database_callback_state_.erase(it);
119 } 133 }
120 134
121 void IndexedDBDispatcher::OnDatabaseChanges( 135 void IndexedDBDispatcher::OnDatabaseChanges(
122 int32_t ipc_thread_id, 136 int32_t ipc_thread_id,
123 const IndexedDBMsg_ObserverChanges& changes) { 137 const IndexedDBMsg_ObserverChanges& changes) {
124 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 138 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
125 std::vector<WebIDBObservation> observations( 139 std::vector<WebIDBObservation> observations(
126 ConvertObservations(changes.observations)); 140 ConvertObservations(changes.observations));
127 for (auto& it : changes.observation_index) { 141 for (auto& it : changes.observation_index) {
128 WebIDBObserver* observer = observers_.Lookup(it.first); 142 WebIDBObserver* observer = observers_.Lookup(it.first);
(...skipping 20 matching lines...) Expand all
149 int64_t transaction_id, 163 int64_t transaction_id,
150 WebIDBCursorImpl* exception_cursor) { 164 WebIDBCursorImpl* exception_cursor) {
151 for (WebIDBCursorImpl* cursor : cursors_) { 165 for (WebIDBCursorImpl* cursor : cursors_) {
152 if (cursor != exception_cursor && 166 if (cursor != exception_cursor &&
153 cursor->transaction_id() == transaction_id) 167 cursor->transaction_id() == transaction_id)
154 cursor->ResetPrefetchCache(); 168 cursor->ResetPrefetchCache();
155 } 169 }
156 } 170 }
157 171
158 } // namespace content 172 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/indexed_db_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698