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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.cc

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unobserve functionality Created 4 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/indexed_db/indexed_db_dispatcher_host.h" 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 connection->Close(); 186 connection->Close();
187 delete connection; 187 delete connection;
188 return -1; 188 return -1;
189 } 189 }
190 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); 190 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection);
191 context()->ConnectionOpened(origin, connection); 191 context()->ConnectionOpened(origin, connection);
192 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; 192 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin;
193 return ipc_database_id; 193 return ipc_database_id;
194 } 194 }
195 195
196 int64_t IndexedDBDispatcherHost::HostObserverId(int64_t observer_id) { 196 int64_t IndexedDBDispatcherHost::DatabaseDispatcherHost::GenerateObserverId(
197 // Inject the renderer process id into the observer id, to 197 int32_t observer_id,
198 // uniquely identify this observer, and effectively bind it to 198 int32_t ipc_thread_id) {
199 // the renderer that initiated it. The lower 32 bits of 199 // Basic djb2 hash.
200 // observer_id are guaranteed to be unique within that renderer. 200 int64_t hash = 5381;
201 base::ProcessId pid = peer_pid(); 201 hash = ((hash << 5) + hash) + ipc_thread_id;
202 DCHECK(!(observer_id >> 32)) << "observer ids can only be 32 bits"; 202 hash = ((hash << 5) + hash) + observer_id;
203 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), 203 return hash;
204 "Process ID must fit in 32 bits");
205
206 return observer_id | (static_cast<uint64_t>(pid) << 32);
207 } 204 }
208 205
209 int64_t IndexedDBDispatcherHost::RendererObserverId(int64_t host_observer_id) {
210 DCHECK(host_observer_id >> 32 == peer_pid())
211 << "Invalid renderer target for observer id";
212 return host_observer_id & 0xffffffff;
213 }
214
215 // Do I need this for observer? origin?
216 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, 206 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id,
217 const url::Origin& origin) { 207 const url::Origin& origin) {
218 if (!database_dispatcher_host_) 208 if (!database_dispatcher_host_)
219 return; 209 return;
220 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; 210 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0;
221 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = 211 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] =
222 origin; 212 origin;
223 } 213 }
224 214
225 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { 215 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], 637 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id],
648 connection); 638 connection);
649 database_origin_map_.erase(ipc_object_id); 639 database_origin_map_.erase(ipc_object_id);
650 parent_->DestroyObject(&map_, ipc_object_id); 640 parent_->DestroyObject(&map_, ipc_object_id);
651 } 641 }
652 642
653 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( 643 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve(
654 int32_t ipc_thread_id, 644 int32_t ipc_thread_id,
655 int32_t ipc_database_id, 645 int32_t ipc_database_id,
656 int64_t transaction_id, 646 int64_t transaction_id,
657 int64_t observer_id) { 647 int32_t observer_id) {
658 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 648 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
659 IndexedDBConnection* connection = 649 IndexedDBConnection* connection =
660 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 650 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
661 if (!connection || !connection->IsConnected()) 651 if (!connection || !connection->IsConnected())
662 return; 652 return;
653 int64_t host_observer_id = GenerateObserverId(observer_id, ipc_thread_id);
654 observers_.push_back(host_observer_id);
655 connection->database()->Observe(parent_->HostTransactionId(transaction_id),
656 host_observer_id);
657 }
663 658
664 observers_.push_back(observer_id); 659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve(
665 connection->database()->Observe( // pass thread_id here 660 int32_t ipc_thread_id,
666 parent_->HostTransactionId(transaction_id), 661 int32_t ipc_database_id,
667 parent_->HostObserverId(observer_id)); 662 std::vector<int32_t> remove_observers) {
663 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
664 IndexedDBConnection* connection =
665 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
666 if (!connection || !connection->IsConnected())
667 return;
668 std::vector<int64_t> observersToRemove =
669 RemoveObservers(remove_observers, ipc_thread_id);
670 connection->database()->Unobserve(observersToRemove);
671 }
672
673 std::vector<int64_t>
674 IndexedDBDispatcherHost::DatabaseDispatcherHost::RemoveObservers(
675 std::vector<int32_t> remove_observers,
676 int32_t ipc_database_id) {
677 // TODO(palakj): remove from observers_ and return vector of the hashed id.
678 std::vector<int64_t> observersToRemove;
679 return observersToRemove;
668 } 680 }
669 681
670 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 682 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
671 const IndexedDBHostMsg_DatabaseGet_Params& params) { 683 const IndexedDBHostMsg_DatabaseGet_Params& params) {
672 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 684 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
673 IndexedDBConnection* connection = 685 IndexedDBConnection* connection =
674 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 686 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
675 if (!connection || !connection->IsConnected()) 687 if (!connection || !connection->IsConnected())
676 return; 688 return;
677 689
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 DLOG(ERROR) << "Unable to reset prefetch"; 1092 DLOG(ERROR) << "Unable to reset prefetch";
1081 } 1093 }
1082 1094
1083 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 1095 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1084 int32_t ipc_object_id) { 1096 int32_t ipc_object_id) {
1085 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 1097 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
1086 parent_->DestroyObject(&map_, ipc_object_id); 1098 parent_->DestroyObject(&map_, ipc_object_id);
1087 } 1099 }
1088 1100
1089 } // namespace content 1101 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698