| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 12 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 13 #include "content/browser/indexed_db/indexed_db_connection.h" | 13 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 14 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 14 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 15 #include "content/browser/indexed_db/indexed_db_cursor.h" | 15 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 17 #include "content/browser/indexed_db/indexed_db_metadata.h" | 17 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 18 #include "content/browser/renderer_host/render_message_filter.h" | 18 #include "content/browser/renderer_host/render_message_filter.h" |
| 19 #include "content/common/indexed_db/indexed_db_messages.h" | 19 #include "content/common/indexed_db/indexed_db_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
| 24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 #include "webkit/browser/database/database_util.h" | 26 #include "webkit/browser/database/database_util.h" |
| 27 #include "webkit/common/database/database_identifier.h" | 27 #include "webkit/common/database/database_identifier.h" |
| 28 | 28 |
| 29 using webkit_database::DatabaseUtil; | 29 using webkit_database::DatabaseUtil; |
| 30 using WebKit::WebIDBKey; | 30 using blink::WebIDBKey; |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 34 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 35 int ipc_process_id, | 35 int ipc_process_id, |
| 36 IndexedDBContextImpl* indexed_db_context) | 36 IndexedDBContextImpl* indexed_db_context) |
| 37 : indexed_db_context_(indexed_db_context), | 37 : indexed_db_context_(indexed_db_context), |
| 38 database_dispatcher_host_(new DatabaseDispatcherHost(this)), | 38 database_dispatcher_host_(new DatabaseDispatcherHost(this)), |
| 39 cursor_dispatcher_host_(new CursorDispatcherHost(this)), | 39 cursor_dispatcher_host_(new CursorDispatcherHost(this)), |
| 40 ipc_process_id_(ipc_process_id) { | 40 ipc_process_id_(ipc_process_id) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 for (TransactionIDToDatabaseIDMap::iterator iter = | 359 for (TransactionIDToDatabaseIDMap::iterator iter = |
| 360 transaction_database_map_.begin(); | 360 transaction_database_map_.begin(); |
| 361 iter != transaction_database_map_.end();) { | 361 iter != transaction_database_map_.end();) { |
| 362 int64 transaction_id = iter->first; | 362 int64 transaction_id = iter->first; |
| 363 int32 ipc_database_id = iter->second; | 363 int32 ipc_database_id = iter->second; |
| 364 ++iter; | 364 ++iter; |
| 365 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); | 365 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); |
| 366 if (connection && connection->IsConnected()) { | 366 if (connection && connection->IsConnected()) { |
| 367 connection->database()->Abort( | 367 connection->database()->Abort( |
| 368 transaction_id, | 368 transaction_id, |
| 369 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError)); | 369 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError)); |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 DCHECK(transaction_database_map_.empty()); | 372 DCHECK(transaction_database_map_.empty()); |
| 373 | 373 |
| 374 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); | 374 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); |
| 375 iter != database_url_map_.end(); | 375 iter != database_url_map_.end(); |
| 376 iter++) { | 376 iter++) { |
| 377 IndexedDBConnection* connection = map_.Lookup(iter->first); | 377 IndexedDBConnection* connection = map_.Lookup(iter->first); |
| 378 if (connection && connection->IsConnected()) { | 378 if (connection && connection->IsConnected()) { |
| 379 connection->Close(); | 379 connection->Close(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 433 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 434 connection->database()->CreateObjectStore(host_transaction_id, | 434 connection->database()->CreateObjectStore(host_transaction_id, |
| 435 params.object_store_id, | 435 params.object_store_id, |
| 436 params.name, | 436 params.name, |
| 437 params.key_path, | 437 params.key_path, |
| 438 params.auto_increment); | 438 params.auto_increment); |
| 439 if (parent_->Context()->IsOverQuota( | 439 if (parent_->Context()->IsOverQuota( |
| 440 database_url_map_[params.ipc_database_id])) { | 440 database_url_map_[params.ipc_database_id])) { |
| 441 connection->database()->Abort( | 441 connection->database()->Abort( |
| 442 host_transaction_id, | 442 host_transaction_id, |
| 443 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 443 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | 447 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( |
| 448 int32 ipc_database_id, | 448 int32 ipc_database_id, |
| 449 int64 transaction_id, | 449 int64 transaction_id, |
| 450 int64 object_store_id) { | 450 int64 object_store_id) { |
| 451 DCHECK( | 451 DCHECK( |
| 452 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 452 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 453 IndexedDBConnection* connection = | 453 IndexedDBConnection* connection = |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 IndexedDBConnection* connection = | 563 IndexedDBConnection* connection = |
| 564 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 564 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 565 if (!connection || !connection->IsConnected()) | 565 if (!connection || !connection->IsConnected()) |
| 566 return; | 566 return; |
| 567 | 567 |
| 568 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 568 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 569 if (params.index_ids.size() != params.index_keys.size()) { | 569 if (params.index_ids.size() != params.index_keys.size()) { |
| 570 connection->database()->Abort( | 570 connection->database()->Abort( |
| 571 host_transaction_id, | 571 host_transaction_id, |
| 572 IndexedDBDatabaseError( | 572 IndexedDBDatabaseError( |
| 573 WebKit::WebIDBDatabaseExceptionUnknownError, | 573 blink::WebIDBDatabaseExceptionUnknownError, |
| 574 "Malformed IPC message: index_ids.size() != index_keys.size()")); | 574 "Malformed IPC message: index_ids.size() != index_keys.size()")); |
| 575 return; | 575 return; |
| 576 } | 576 } |
| 577 | 577 |
| 578 connection->database()->SetIndexKeys( | 578 connection->database()->SetIndexKeys( |
| 579 host_transaction_id, | 579 host_transaction_id, |
| 580 params.object_store_id, | 580 params.object_store_id, |
| 581 make_scoped_ptr(new IndexedDBKey(params.primary_key)), | 581 make_scoped_ptr(new IndexedDBKey(params.primary_key)), |
| 582 params.index_ids, | 582 params.index_ids, |
| 583 params.index_keys); | 583 params.index_keys); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 if (!connection || !connection->IsConnected()) | 701 if (!connection || !connection->IsConnected()) |
| 702 return; | 702 return; |
| 703 | 703 |
| 704 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); | 704 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); |
| 705 int64 transaction_size = transaction_size_map_[host_transaction_id]; | 705 int64 transaction_size = transaction_size_map_[host_transaction_id]; |
| 706 if (transaction_size && | 706 if (transaction_size && |
| 707 parent_->Context()->WouldBeOverQuota( | 707 parent_->Context()->WouldBeOverQuota( |
| 708 transaction_url_map_[host_transaction_id], transaction_size)) { | 708 transaction_url_map_[host_transaction_id], transaction_size)) { |
| 709 connection->database()->Abort( | 709 connection->database()->Abort( |
| 710 host_transaction_id, | 710 host_transaction_id, |
| 711 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 711 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); |
| 712 return; | 712 return; |
| 713 } | 713 } |
| 714 | 714 |
| 715 connection->database()->Commit(host_transaction_id); | 715 connection->database()->Commit(host_transaction_id); |
| 716 } | 716 } |
| 717 | 717 |
| 718 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( | 718 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( |
| 719 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { | 719 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { |
| 720 DCHECK( | 720 DCHECK( |
| 721 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 721 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 722 IndexedDBConnection* connection = | 722 IndexedDBConnection* connection = |
| 723 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 723 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 724 if (!connection || !connection->IsConnected()) | 724 if (!connection || !connection->IsConnected()) |
| 725 return; | 725 return; |
| 726 | 726 |
| 727 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 727 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 728 connection->database()->CreateIndex(host_transaction_id, | 728 connection->database()->CreateIndex(host_transaction_id, |
| 729 params.object_store_id, | 729 params.object_store_id, |
| 730 params.index_id, | 730 params.index_id, |
| 731 params.name, | 731 params.name, |
| 732 params.key_path, | 732 params.key_path, |
| 733 params.unique, | 733 params.unique, |
| 734 params.multi_entry); | 734 params.multi_entry); |
| 735 if (parent_->Context()->IsOverQuota( | 735 if (parent_->Context()->IsOverQuota( |
| 736 database_url_map_[params.ipc_database_id])) { | 736 database_url_map_[params.ipc_database_id])) { |
| 737 connection->database()->Abort( | 737 connection->database()->Abort( |
| 738 host_transaction_id, | 738 host_transaction_id, |
| 739 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 739 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); |
| 740 } | 740 } |
| 741 } | 741 } |
| 742 | 742 |
| 743 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( | 743 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( |
| 744 int32 ipc_database_id, | 744 int32 ipc_database_id, |
| 745 int64 transaction_id, | 745 int64 transaction_id, |
| 746 int64 object_store_id, | 746 int64 object_store_id, |
| 747 int64 index_id) { | 747 int64 index_id) { |
| 748 DCHECK( | 748 DCHECK( |
| 749 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 749 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 } | 861 } |
| 862 | 862 |
| 863 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 863 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 864 int32 ipc_object_id) { | 864 int32 ipc_object_id) { |
| 865 DCHECK( | 865 DCHECK( |
| 866 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 866 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 867 parent_->DestroyObject(&map_, ipc_object_id); | 867 parent_->DestroyObject(&map_, ipc_object_id); |
| 868 } | 868 } |
| 869 | 869 |
| 870 } // namespace content | 870 } // namespace content |
| OLD | NEW |