| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "content/browser/bad_message.h" | 18 #include "content/browser/bad_message.h" |
| 19 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 20 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 20 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 21 #include "content/browser/indexed_db/indexed_db_connection.h" | 21 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 22 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 22 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 23 #include "content/browser/indexed_db/indexed_db_cursor.h" | 23 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 24 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 24 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 25 #include "content/browser/indexed_db/indexed_db_metadata.h" | 25 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 26 #include "content/browser/indexed_db/indexed_db_observation.h" |
| 27 #include "content/browser/indexed_db/indexed_db_observation.h" |
| 28 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
| 26 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 29 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 27 #include "content/browser/indexed_db/indexed_db_value.h" | 30 #include "content/browser/indexed_db/indexed_db_value.h" |
| 28 #include "content/browser/renderer_host/render_message_filter.h" | 31 #include "content/browser/renderer_host/render_message_filter.h" |
| 29 #include "content/common/indexed_db/indexed_db_messages.h" | 32 #include "content/common/indexed_db/indexed_db_messages.h" |
| 30 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 33 #include "content/public/common/result_codes.h" | 36 #include "content/public/common/result_codes.h" |
| 34 #include "storage/browser/blob/blob_data_builder.h" | 37 #include "storage/browser/blob/blob_data_builder.h" |
| 35 #include "storage/browser/blob/blob_storage_context.h" | 38 #include "storage/browser/blob/blob_storage_context.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 184 |
| 182 int32_t IndexedDBDispatcherHost::Add(IndexedDBConnection* connection, | 185 int32_t IndexedDBDispatcherHost::Add(IndexedDBConnection* connection, |
| 183 int32_t ipc_thread_id, | 186 int32_t ipc_thread_id, |
| 184 const url::Origin& origin) { | 187 const url::Origin& origin) { |
| 185 if (!database_dispatcher_host_) { | 188 if (!database_dispatcher_host_) { |
| 186 connection->Close(); | 189 connection->Close(); |
| 187 delete connection; | 190 delete connection; |
| 188 return -1; | 191 return -1; |
| 189 } | 192 } |
| 190 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); | 193 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); |
| 194 connection->set_id(ipc_database_id); |
| 191 context()->ConnectionOpened(origin, connection); | 195 context()->ConnectionOpened(origin, connection); |
| 192 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; | 196 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; |
| 193 return ipc_database_id; | 197 return ipc_database_id; |
| 194 } | 198 } |
| 195 | 199 |
| 196 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | 200 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, |
| 197 const url::Origin& origin) { | 201 const url::Origin& origin) { |
| 198 if (!database_dispatcher_host_) | 202 if (!database_dispatcher_host_) |
| 199 return; | 203 return; |
| 200 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; | 204 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 idb_index_metadata.key_path = web_index_metadata.key_path; | 314 idb_index_metadata.key_path = web_index_metadata.key_path; |
| 311 idb_index_metadata.unique = web_index_metadata.unique; | 315 idb_index_metadata.unique = web_index_metadata.unique; |
| 312 idb_index_metadata.multi_entry = web_index_metadata.multi_entry; | 316 idb_index_metadata.multi_entry = web_index_metadata.multi_entry; |
| 313 idb_store_metadata.indexes.push_back(idb_index_metadata); | 317 idb_store_metadata.indexes.push_back(idb_index_metadata); |
| 314 } | 318 } |
| 315 metadata.object_stores.push_back(idb_store_metadata); | 319 metadata.object_stores.push_back(idb_store_metadata); |
| 316 } | 320 } |
| 317 return metadata; | 321 return metadata; |
| 318 } | 322 } |
| 319 | 323 |
| 324 IndexedDBMsg_ObserverChanges IndexedDBDispatcherHost::ConvertObserverChanges( |
| 325 std::unique_ptr<IndexedDBObserverChanges> changes) { |
| 326 IndexedDBMsg_ObserverChanges idb_changes; |
| 327 idb_changes.observation_index = changes->release_observation_indices_map(); |
| 328 for (auto& observation : changes->release_observations()) |
| 329 idb_changes.observations.push_back(ConvertObservation(observation.get())); |
| 330 return idb_changes; |
| 331 } |
| 332 |
| 333 IndexedDBMsg_Observation IndexedDBDispatcherHost::ConvertObservation( |
| 334 const IndexedDBObservation* observation) { |
| 335 // TODO(palakj): Modify function for indexed_db_value. Issue crbug.com/609934. |
| 336 IndexedDBMsg_Observation idb_observation; |
| 337 idb_observation.object_store_id = observation->object_store_id(); |
| 338 idb_observation.type = observation->type(); |
| 339 idb_observation.key_range = observation->key_range(); |
| 340 return idb_observation; |
| 341 } |
| 342 |
| 320 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( | 343 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( |
| 321 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { | 344 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { |
| 322 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 345 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 323 | 346 |
| 324 if (!IsValidOrigin(params.origin)) { | 347 if (!IsValidOrigin(params.origin)) { |
| 325 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); | 348 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_INVALID_ORIGIN); |
| 326 return; | 349 return; |
| 327 } | 350 } |
| 328 | 351 |
| 329 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 352 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, | 536 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, |
| 514 OnCreateObjectStore) | 537 OnCreateObjectStore) |
| 515 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, | 538 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, |
| 516 OnDeleteObjectStore) | 539 OnDeleteObjectStore) |
| 517 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, | 540 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, |
| 518 OnCreateTransaction) | 541 OnCreateTransaction) |
| 519 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) | 542 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) |
| 520 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, | 543 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseVersionChangeIgnored, |
| 521 OnVersionChangeIgnored) | 544 OnVersionChangeIgnored) |
| 522 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) | 545 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) |
| 546 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseObserve, OnObserve) |
| 547 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseUnobserve, OnUnobserve) |
| 523 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) | 548 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) |
| 524 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) | 549 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGetAll, OnGetAll) |
| 525 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) | 550 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPutWrapper) |
| 526 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) | 551 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys) |
| 527 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, | 552 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, |
| 528 OnSetIndexesReady) | 553 OnSetIndexesReady) |
| 529 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) | 554 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) |
| 530 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) | 555 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) |
| 531 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) | 556 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) |
| 532 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) | 557 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 if (!connection) | 647 if (!connection) |
| 623 return; | 648 return; |
| 624 if (connection->IsConnected()) | 649 if (connection->IsConnected()) |
| 625 connection->Close(); | 650 connection->Close(); |
| 626 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], | 651 parent_->context()->ConnectionClosed(database_origin_map_[ipc_object_id], |
| 627 connection); | 652 connection); |
| 628 database_origin_map_.erase(ipc_object_id); | 653 database_origin_map_.erase(ipc_object_id); |
| 629 parent_->DestroyObject(&map_, ipc_object_id); | 654 parent_->DestroyObject(&map_, ipc_object_id); |
| 630 } | 655 } |
| 631 | 656 |
| 657 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( |
| 658 const IndexedDBHostMsg_DatabaseObserve_Params& params) { |
| 659 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 660 IndexedDBConnection* connection = |
| 661 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 662 if (!connection || !connection->IsConnected()) |
| 663 return; |
| 664 IndexedDBObserver::Options options(params.include_transaction, |
| 665 params.no_records, params.values, |
| 666 params.operation_types); |
| 667 connection->database()->AddPendingObserver( |
| 668 parent_->HostTransactionId(params.transaction_id), params.observer_id, |
| 669 options); |
| 670 } |
| 671 |
| 672 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve( |
| 673 int32_t ipc_database_id, |
| 674 const std::vector<int32_t>& observer_ids_to_remove) { |
| 675 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 676 DCHECK(!observer_ids_to_remove.empty()); |
| 677 IndexedDBConnection* connection = |
| 678 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 679 if (!connection || !connection->IsConnected()) |
| 680 return; |
| 681 connection->RemoveObservers(observer_ids_to_remove); |
| 682 } |
| 683 |
| 632 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | 684 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( |
| 633 const IndexedDBHostMsg_DatabaseGet_Params& params) { | 685 const IndexedDBHostMsg_DatabaseGet_Params& params) { |
| 634 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 686 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 635 IndexedDBConnection* connection = | 687 IndexedDBConnection* connection = |
| 636 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 688 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 637 if (!connection || !connection->IsConnected()) | 689 if (!connection || !connection->IsConnected()) |
| 638 return; | 690 return; |
| 639 | 691 |
| 640 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 692 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 641 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 693 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"; | 1094 DLOG(ERROR) << "Unable to reset prefetch"; |
| 1043 } | 1095 } |
| 1044 | 1096 |
| 1045 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1097 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 1046 int32_t ipc_object_id) { | 1098 int32_t ipc_object_id) { |
| 1047 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 1099 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 1048 parent_->DestroyObject(&map_, ipc_object_id); | 1100 parent_->DestroyObject(&map_, ipc_object_id); |
| 1049 } | 1101 } |
| 1050 | 1102 |
| 1051 } // namespace content | 1103 } // namespace content |
| OLD | NEW |