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

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

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (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
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"
11 #include "content/child/indexed_db/indexed_db_key_builders.h" 11 #include "content/child/indexed_db/indexed_db_key_builders.h"
12 #include "content/child/indexed_db/webidbcursor_impl.h" 12 #include "content/child/indexed_db/webidbcursor_impl.h"
13 #include "content/common/indexed_db/indexed_db_messages.h"
14 #include "ipc/ipc_channel.h" 13 #include "ipc/ipc_channel.h"
15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h" 14 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h"
16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation .h" 15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObservation .h"
17 16
18 using blink::WebIDBKey; 17 using blink::WebIDBKey;
19 using blink::WebIDBObservation; 18 using blink::WebIDBObservation;
20 using blink::WebIDBObserver;
21 using base::ThreadLocalPointer; 19 using base::ThreadLocalPointer;
22 20
23 namespace content { 21 namespace content {
24 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky 22 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky
25 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 23 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
26 24
27 namespace { 25 namespace {
28 26
29 IndexedDBDispatcher* const kHasBeenDeleted = 27 IndexedDBDispatcher* const kHasBeenDeleted =
30 reinterpret_cast<IndexedDBDispatcher*>(0x1); 28 reinterpret_cast<IndexedDBDispatcher*>(0x1);
(...skipping 19 matching lines...) Expand all
50 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher(); 48 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher();
51 if (WorkerThread::GetCurrentId()) 49 if (WorkerThread::GetCurrentId())
52 WorkerThread::AddObserver(dispatcher); 50 WorkerThread::AddObserver(dispatcher);
53 return dispatcher; 51 return dispatcher;
54 } 52 }
55 53
56 void IndexedDBDispatcher::WillStopCurrentWorkerThread() { 54 void IndexedDBDispatcher::WillStopCurrentWorkerThread() {
57 delete this; 55 delete this;
58 } 56 }
59 57
60 std::vector<WebIDBObservation> IndexedDBDispatcher::ConvertObservations(
61 const std::vector<IndexedDBMsg_Observation>& idb_observations) {
62 std::vector<WebIDBObservation> web_observations;
63 for (const auto& idb_observation : idb_observations) {
64 WebIDBObservation web_observation;
65 web_observation.objectStoreId = idb_observation.object_store_id;
66 web_observation.type = idb_observation.type;
67 web_observation.keyRange =
68 WebIDBKeyRangeBuilder::Build(idb_observation.key_range);
69 // TODO(palakj): Assign value to web_observation.
70 web_observations.push_back(std::move(web_observation));
71 }
72 return web_observations;
73 }
74
75 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
76 bool handled = true;
77 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
78 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksChanges,
79 OnDatabaseChanges)
80 IPC_MESSAGE_UNHANDLED(handled = false)
81 IPC_END_MESSAGE_MAP()
82 // If a message gets here, IndexedDBMessageFilter already determined that it
83 // is an IndexedDB message.
84 DCHECK(handled) << "Didn't handle a message defined at line "
85 << IPC_MESSAGE_ID_LINE(msg.type());
86 }
87
88 int32_t IndexedDBDispatcher::RegisterObserver(
89 std::unique_ptr<WebIDBObserver> observer) {
90 return observers_.Add(observer.release());
91 }
92
93 void IndexedDBDispatcher::RemoveObservers(
94 const std::vector<int32_t>& observer_ids_to_remove) {
95 for (int32_t id : observer_ids_to_remove)
96 observers_.Remove(id);
97 }
98
99 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks( 58 void IndexedDBDispatcher::RegisterMojoOwnedCallbacks(
100 IndexedDBCallbacksImpl::InternalState* callbacks) { 59 IndexedDBCallbacksImpl::InternalState* callbacks) {
101 mojo_owned_callback_state_.insert(callbacks); 60 mojo_owned_callback_state_.insert(callbacks);
102 } 61 }
103 62
104 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks( 63 void IndexedDBDispatcher::UnregisterMojoOwnedCallbacks(
105 IndexedDBCallbacksImpl::InternalState* callbacks) { 64 IndexedDBCallbacksImpl::InternalState* callbacks) {
106 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks)); 65 DCHECK(base::ContainsValue(mojo_owned_callback_state_, callbacks));
107 mojo_owned_callback_state_.erase(callbacks); 66 mojo_owned_callback_state_.erase(callbacks);
108 } 67 }
109 68
110 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks( 69 void IndexedDBDispatcher::RegisterMojoOwnedDatabaseCallbacks(
111 blink::WebIDBDatabaseCallbacks* callbacks) { 70 blink::WebIDBDatabaseCallbacks* callbacks) {
112 mojo_owned_database_callback_state_.insert(callbacks); 71 mojo_owned_database_callback_state_.insert(callbacks);
113 } 72 }
114 73
115 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks( 74 void IndexedDBDispatcher::UnregisterMojoOwnedDatabaseCallbacks(
116 blink::WebIDBDatabaseCallbacks* callbacks) { 75 blink::WebIDBDatabaseCallbacks* callbacks) {
117 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks)); 76 DCHECK(base::ContainsValue(mojo_owned_database_callback_state_, callbacks));
118 mojo_owned_database_callback_state_.erase(callbacks); 77 mojo_owned_database_callback_state_.erase(callbacks);
119 } 78 }
120 79
121 void IndexedDBDispatcher::OnDatabaseChanges(
122 int32_t ipc_thread_id,
123 const IndexedDBMsg_ObserverChanges& changes) {
124 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
125 std::vector<WebIDBObservation> observations(
126 ConvertObservations(changes.observations));
127 for (auto& it : changes.observation_index) {
128 WebIDBObserver* observer = observers_.Lookup(it.first);
129 // An observer can be removed from the renderer, but still exist in the
130 // backend. Moreover, observer might have recorded some changes before being
131 // removed from the backend and thus, have its id be present in changes.
132 if (!observer)
133 continue;
134 observer->onChange(observations, std::move(it.second));
135 }
136 }
137
138 void IndexedDBDispatcher::RegisterCursor(WebIDBCursorImpl* cursor) { 80 void IndexedDBDispatcher::RegisterCursor(WebIDBCursorImpl* cursor) {
139 DCHECK(!base::ContainsValue(cursors_, cursor)); 81 DCHECK(!base::ContainsValue(cursors_, cursor));
140 cursors_.insert(cursor); 82 cursors_.insert(cursor);
141 } 83 }
142 84
143 void IndexedDBDispatcher::UnregisterCursor(WebIDBCursorImpl* cursor) { 85 void IndexedDBDispatcher::UnregisterCursor(WebIDBCursorImpl* cursor) {
144 DCHECK(base::ContainsValue(cursors_, cursor)); 86 DCHECK(base::ContainsValue(cursors_, cursor));
145 cursors_.erase(cursor); 87 cursors_.erase(cursor);
146 } 88 }
147 89
148 void IndexedDBDispatcher::ResetCursorPrefetchCaches( 90 void IndexedDBDispatcher::ResetCursorPrefetchCaches(
149 int64_t transaction_id, 91 int64_t transaction_id,
150 WebIDBCursorImpl* exception_cursor) { 92 WebIDBCursorImpl* exception_cursor) {
151 for (WebIDBCursorImpl* cursor : cursors_) { 93 for (WebIDBCursorImpl* cursor : cursors_) {
152 if (cursor != exception_cursor && 94 if (cursor != exception_cursor &&
153 cursor->transaction_id() == transaction_id) 95 cursor->transaction_id() == transaction_id)
154 cursor->ResetPrefetchCache(); 96 cursor->ResetPrefetchCache();
155 } 97 }
156 } 98 }
157 99
158 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698