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

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: Post dmurph review 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
197 IndexedDBDispatcherHost::DatabaseDispatcherHost::GenerateObserverAndThreadId(
198 int32_t observer_id,
199 int32_t ipc_thread_id) {
200 return observer_id | (static_cast<uint64_t>(ipc_thread_id) << 32);
201 }
202
196 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, 203 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id,
197 const url::Origin& origin) { 204 const url::Origin& origin) {
198 if (!database_dispatcher_host_) 205 if (!database_dispatcher_host_)
199 return; 206 return;
200 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; 207 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0;
201 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = 208 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] =
202 origin; 209 origin;
203 } 210 }
204 211
205 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { 212 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, 520 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
514 OnCreateObjectStore) 521 OnCreateObjectStore)
515 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, 522 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
516 OnDeleteObjectStore) 523 OnDeleteObjectStore)
517 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, 524 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
518 OnCreateTransaction) 525 OnCreateTransaction)
519 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) 526 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
520 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, 527 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored,
521 OnVersionChangeIgnored) 528 OnVersionChangeIgnored)
522 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) 529 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
530 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObserve, OnObserve)
523 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) 531 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet)
524 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) 532 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll)
525 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) 533 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper)
526 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) 534 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys)
527 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, 535 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady,
528 OnSetIndexesReady) 536 OnSetIndexesReady)
529 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) 537 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor)
530 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) 538 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount)
531 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) 539 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange)
532 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) 540 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (!connection) 630 if (!connection)
623 return; 631 return;
624 if (connection->IsConnected()) 632 if (connection->IsConnected())
625 connection->Close(); 633 connection->Close();
626 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], 634 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id],
627 connection); 635 connection);
628 database_origin_map_.erase(ipc_object_id); 636 database_origin_map_.erase(ipc_object_id);
629 parent_->DestroyObject(&map_, ipc_object_id); 637 parent_->DestroyObject(&map_, ipc_object_id);
630 } 638 }
631 639
640 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve(
641 int32_t ipc_thread_id,
642 int32_t ipc_database_id,
643 int64_t transaction_id,
644 int32_t observer_id) {
dmurph 2016/06/17 09:05:06 can your rename the int32_t version of observer_id
palakj1 2016/06/18 05:13:40 It's only local to the renderer thread right, not
645 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
646 IndexedDBConnection* connection =
647 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
648 if (!connection || !connection->IsConnected())
649 return;
650 int64_t observer_thread_id =
651 GenerateObserverAndThreadId(observer_id, ipc_thread_id);
652
653 observers_.push_back(std::make_pair(observer_id, observer_thread_id));
dmurph 2016/06/17 09:05:06 You need to figure out how to store these so that
654 connection->database()->Observe(parent_->HostTransactionId(transaction_id),
655 observer_thread_id);
656 }
657
658 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve(
659 int32_t ipc_thread_id,
660 int32_t ipc_database_id,
661 std::vector<int32_t> remove_observers) {
662 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
663 IndexedDBConnection* connection =
664 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
665 if (!connection || !connection->IsConnected())
666 return;
667 std::vector<int64_t> observersToRemove =
668 RemoveObservers(remove_observers, ipc_thread_id);
669 connection->database()->Unobserve(observersToRemove);
670 }
671
672 std::vector<int64_t>
673 IndexedDBDispatcherHost::DatabaseDispatcherHost::RemoveObservers(
674 std::vector<int32_t> remove_observers,
675 int32_t ipc_database_id) {
676 // TODO(palakj): remove from observers_ and return vector of the hashed id.
677 std::vector<int64_t> observersToRemove;
678 return observersToRemove;
679 }
680
632 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 681 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
633 const IndexedDBHostMsg_DatabaseGet_Params& params) { 682 const IndexedDBHostMsg_DatabaseGet_Params& params) {
634 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 683 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
635 IndexedDBConnection* connection = 684 IndexedDBConnection* connection =
636 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 685 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
637 if (!connection || !connection->IsConnected()) 686 if (!connection || !connection->IsConnected())
638 return; 687 return;
639 688
640 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 689 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
641 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 690 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 DLOG(ERROR) << "Unable to reset prefetch"; 1091 DLOG(ERROR) << "Unable to reset prefetch";
1043 } 1092 }
1044 1093
1045 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 1094 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1046 int32_t ipc_object_id) { 1095 int32_t ipc_object_id) {
1047 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 1096 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
1048 parent_->DestroyObject(&map_, ipc_object_id); 1097 parent_->DestroyObject(&map_, ipc_object_id);
1049 } 1098 }
1050 1099
1051 } // namespace content 1100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698