Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { | |
| 197 // Inject the renderer process id into the observer id, to | |
| 198 // uniquely identify this observer, and effectively bind it to | |
| 199 // the renderer that initiated it. The lower 32 bits of | |
| 200 // observer_id are guaranteed to be unique within that renderer. | |
|
Marijn Kruisselbrink
2016/06/15 13:14:57
There is no such guarantee. There is a separate In
palakj1
2016/06/16 07:05:40
Oh, I was trying to imitate the way host transacti
| |
| 201 base::ProcessId pid = peer_pid(); | |
| 202 DCHECK(!(observer_id >> 32)) << "observer ids can only be 32 bits"; | |
| 203 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), | |
| 204 "Process ID must fit in 32 bits"); | |
| 205 | |
| 206 return observer_id | (static_cast<uint64_t>(pid) << 32); | |
| 207 } | |
| 208 | |
| 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? | |
| 196 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | 216 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, |
| 197 const url::Origin& origin) { | 217 const url::Origin& origin) { |
| 198 if (!database_dispatcher_host_) | 218 if (!database_dispatcher_host_) |
| 199 return; | 219 return; |
| 200 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; | 220 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; |
| 201 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = | 221 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = |
| 202 origin; | 222 origin; |
| 203 } | 223 } |
| 204 | 224 |
| 205 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { | 225 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, | 533 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, |
| 514 OnCreateObjectStore) | 534 OnCreateObjectStore) |
| 515 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, | 535 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, |
| 516 OnDeleteObjectStore) | 536 OnDeleteObjectStore) |
| 517 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, | 537 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, |
| 518 OnCreateTransaction) | 538 OnCreateTransaction) |
| 519 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) | 539 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) |
| 520 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, | 540 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, |
| 521 OnVersionChangeIgnored) | 541 OnVersionChangeIgnored) |
| 522 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) | 542 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) |
| 543 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObserve, OnObserve) | |
| 523 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) | 544 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) |
| 524 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) | 545 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) |
| 525 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) | 546 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) |
| 526 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) | 547 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) |
| 527 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, | 548 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, |
| 528 OnSetIndexesReady) | 549 OnSetIndexesReady) |
| 529 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) | 550 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) |
| 530 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) | 551 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) |
| 531 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) | 552 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) |
| 532 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) | 553 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 if (!connection) | 643 if (!connection) |
| 623 return; | 644 return; |
| 624 if (connection->IsConnected()) | 645 if (connection->IsConnected()) |
| 625 connection->Close(); | 646 connection->Close(); |
| 626 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], | 647 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], |
| 627 connection); | 648 connection); |
| 628 database_origin_map_.erase(ipc_object_id); | 649 database_origin_map_.erase(ipc_object_id); |
| 629 parent_->DestroyObject(&map_, ipc_object_id); | 650 parent_->DestroyObject(&map_, ipc_object_id); |
| 630 } | 651 } |
| 631 | 652 |
| 653 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( | |
| 654 const IndexedDBHostMsg_DatabaseObserve_Params& params) { | |
| 655 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 656 IndexedDBConnection* connection = | |
| 657 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | |
| 658 if (!connection || !connection->IsConnected()) | |
| 659 return; | |
| 660 | |
| 661 observers_.push_back(params.observer_id); | |
| 662 connection->database()->Observe( | |
| 663 parent_->HostTransactionId(params.transaction_id), | |
| 664 parent_->HostObserverId(params.observer_id)); | |
| 665 } | |
| 666 | |
| 632 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | 667 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( |
| 633 const IndexedDBHostMsg_DatabaseGet_Params& params) { | 668 const IndexedDBHostMsg_DatabaseGet_Params& params) { |
| 634 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 669 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 635 IndexedDBConnection* connection = | 670 IndexedDBConnection* connection = |
| 636 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 671 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 637 if (!connection || !connection->IsConnected()) | 672 if (!connection || !connection->IsConnected()) |
| 638 return; | 673 return; |
| 639 | 674 |
| 640 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 675 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 641 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 676 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 DLOG(ERROR) << "Unable to reset prefetch"; | 1077 DLOG(ERROR) << "Unable to reset prefetch"; |
| 1043 } | 1078 } |
| 1044 | 1079 |
| 1045 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1080 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 1046 int32_t ipc_object_id) { | 1081 int32_t ipc_object_id) { |
| 1047 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 1082 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 1048 parent_->DestroyObject(&map_, ipc_object_id); | 1083 parent_->DestroyObject(&map_, ipc_object_id); |
| 1049 } | 1084 } |
| 1050 | 1085 |
| 1051 } // namespace content | 1086 } // namespace content |
| OLD | NEW |