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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_dispatcher_host.cc
diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.cc b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
index 6268ef02d5f4737490422dbb5b33d76695503290..553cfada19304f72b907884c49dd91a3ee8cc17e 100644
--- a/content/browser/indexed_db/indexed_db_dispatcher_host.cc
+++ b/content/browser/indexed_db/indexed_db_dispatcher_host.cc
@@ -193,26 +193,16 @@ int32_t IndexedDBDispatcherHost::Add(IndexedDBConnection* connection,
return ipc_database_id;
}
-int64_t IndexedDBDispatcherHost::HostObserverId(int64_t observer_id) {
- // Inject the renderer process id into the observer id, to
- // uniquely identify this observer, and effectively bind it to
- // the renderer that initiated it. The lower 32 bits of
- // observer_id are guaranteed to be unique within that renderer.
- base::ProcessId pid = peer_pid();
- DCHECK(!(observer_id >> 32)) << "observer ids can only be 32 bits";
- static_assert(sizeof(base::ProcessId) <= sizeof(int32_t),
- "Process ID must fit in 32 bits");
-
- return observer_id | (static_cast<uint64_t>(pid) << 32);
+int64_t IndexedDBDispatcherHost::DatabaseDispatcherHost::GenerateObserverId(
+ int32_t observer_id,
+ int32_t ipc_thread_id) {
+ // Basic djb2 hash.
+ int64_t hash = 5381;
+ hash = ((hash << 5) + hash) + ipc_thread_id;
+ hash = ((hash << 5) + hash) + observer_id;
+ return hash;
}
-int64_t IndexedDBDispatcherHost::RendererObserverId(int64_t host_observer_id) {
- DCHECK(host_observer_id >> 32 == peer_pid())
- << "Invalid renderer target for observer id";
- return host_observer_id & 0xffffffff;
-}
-
-// Do I need this for observer? origin?
void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id,
const url::Origin& origin) {
if (!database_dispatcher_host_)
@@ -654,17 +644,39 @@ void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve(
int32_t ipc_thread_id,
int32_t ipc_database_id,
int64_t transaction_id,
- int64_t observer_id) {
+ int32_t observer_id) {
+ DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
+ IndexedDBConnection* connection =
+ parent_->GetOrTerminateProcess(&map_, ipc_database_id);
+ if (!connection || !connection->IsConnected())
+ return;
+ int64_t host_observer_id = GenerateObserverId(observer_id, ipc_thread_id);
+ observers_.push_back(host_observer_id);
+ connection->database()->Observe(parent_->HostTransactionId(transaction_id),
+ host_observer_id);
+}
+
+void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve(
+ int32_t ipc_thread_id,
+ int32_t ipc_database_id,
+ std::vector<int32_t> remove_observers) {
DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
IndexedDBConnection* connection =
parent_->GetOrTerminateProcess(&map_, ipc_database_id);
if (!connection || !connection->IsConnected())
return;
+ std::vector<int64_t> observersToRemove =
+ RemoveObservers(remove_observers, ipc_thread_id);
+ connection->database()->Unobserve(observersToRemove);
+}
- observers_.push_back(observer_id);
- connection->database()->Observe( // pass thread_id here
- parent_->HostTransactionId(transaction_id),
- parent_->HostObserverId(observer_id));
+std::vector<int64_t>
+IndexedDBDispatcherHost::DatabaseDispatcherHost::RemoveObservers(
+ std::vector<int32_t> remove_observers,
+ int32_t ipc_database_id) {
+ // TODO(palakj): remove from observers_ and return vector of the hashed id.
+ std::vector<int64_t> observersToRemove;
+ return observersToRemove;
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(

Powered by Google App Engine
This is Rietveld 408576698