| 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 <vector> | 7 #include <vector> |
| 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/process.h" | 12 #include "base/process.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 15 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 18 #include "content/browser/indexed_db/indexed_db_metadata.h" | 19 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 19 #include "content/browser/indexed_db/webidbcursor_impl.h" | |
| 20 #include "content/browser/indexed_db/webidbcursor_impl.h" | |
| 21 #include "content/browser/indexed_db/webidbdatabase_impl.h" | 20 #include "content/browser/indexed_db/webidbdatabase_impl.h" |
| 22 #include "content/browser/renderer_host/render_message_filter.h" | 21 #include "content/browser/renderer_host/render_message_filter.h" |
| 23 #include "content/common/indexed_db/indexed_db_messages.h" | 22 #include "content/common/indexed_db/indexed_db_messages.h" |
| 24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 28 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 29 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | 28 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" |
| 30 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 29 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 OnIDBFactoryGetDatabaseNames) | 107 OnIDBFactoryGetDatabaseNames) |
| 109 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) | 108 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) |
| 110 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, | 109 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, |
| 111 OnIDBFactoryDeleteDatabase) | 110 OnIDBFactoryDeleteDatabase) |
| 112 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
| 113 IPC_END_MESSAGE_MAP() | 112 IPC_END_MESSAGE_MAP() |
| 114 } | 113 } |
| 115 return handled; | 114 return handled; |
| 116 } | 115 } |
| 117 | 116 |
| 118 int32 IndexedDBDispatcherHost::Add(WebIDBCursorImpl* idb_cursor) { | 117 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* idb_cursor) { |
| 119 if (!cursor_dispatcher_host_) { | 118 if (!cursor_dispatcher_host_) { |
| 120 delete idb_cursor; | |
| 121 return 0; | 119 return 0; |
| 122 } | 120 } |
| 123 return cursor_dispatcher_host_->map_.Add(idb_cursor); | 121 return cursor_dispatcher_host_->map_.Add(idb_cursor); |
| 124 } | 122 } |
| 125 | 123 |
| 126 int32 IndexedDBDispatcherHost::Add(WebIDBDatabaseImpl* idb_database, | 124 int32 IndexedDBDispatcherHost::Add(WebIDBDatabaseImpl* idb_database, |
| 127 int32 ipc_thread_id, | 125 int32 ipc_thread_id, |
| 128 const GURL& origin_url) { | 126 const GURL& origin_url) { |
| 129 if (!database_dispatcher_host_) { | 127 if (!database_dispatcher_host_) { |
| 130 delete idb_database; | 128 delete idb_database; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 156 return transaction_id | (static_cast<uint64>(pid) << 32); | 154 return transaction_id | (static_cast<uint64>(pid) << 32); |
| 157 } | 155 } |
| 158 | 156 |
| 159 int64 IndexedDBDispatcherHost::RendererTransactionId( | 157 int64 IndexedDBDispatcherHost::RendererTransactionId( |
| 160 int64 host_transaction_id) { | 158 int64 host_transaction_id) { |
| 161 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) | 159 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) |
| 162 << "Invalid renderer target for transaction id"; | 160 << "Invalid renderer target for transaction id"; |
| 163 return host_transaction_id & 0xffffffff; | 161 return host_transaction_id & 0xffffffff; |
| 164 } | 162 } |
| 165 | 163 |
| 166 WebIDBCursorImpl* IndexedDBDispatcherHost::GetCursorFromId( | 164 IndexedDBCursor* IndexedDBDispatcherHost::GetCursorFromId( |
| 167 int32 ipc_cursor_id) { | 165 int32 ipc_cursor_id) { |
| 168 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 166 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 169 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); | 167 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); |
| 170 } | 168 } |
| 171 | 169 |
| 172 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( | 170 ::IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( |
| 173 const content::IndexedDBDatabaseMetadata& web_metadata) { | 171 const content::IndexedDBDatabaseMetadata& web_metadata) { |
| 174 ::IndexedDBDatabaseMetadata metadata; | 172 ::IndexedDBDatabaseMetadata metadata; |
| 175 metadata.id = web_metadata.id; | 173 metadata.id = web_metadata.id; |
| 176 metadata.name = web_metadata.name; | 174 metadata.name = web_metadata.name; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (!return_object) { | 307 if (!return_object) { |
| 310 NOTREACHED() << "Uh oh, couldn't find object with id " | 308 NOTREACHED() << "Uh oh, couldn't find object with id " |
| 311 << ipc_return_object_id; | 309 << ipc_return_object_id; |
| 312 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); | 310 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); |
| 313 BadMessageReceived(); | 311 BadMessageReceived(); |
| 314 } | 312 } |
| 315 return return_object; | 313 return return_object; |
| 316 } | 314 } |
| 317 | 315 |
| 318 template <typename ObjectType> | 316 template <typename ObjectType> |
| 317 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( |
| 318 RefIDMap<ObjectType>* map, |
| 319 int32 ipc_return_object_id) { |
| 320 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 321 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
| 322 if (!return_object) { |
| 323 NOTREACHED() << "Uh oh, couldn't find object with id " |
| 324 << ipc_return_object_id; |
| 325 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); |
| 326 BadMessageReceived(); |
| 327 } |
| 328 return return_object; |
| 329 } |
| 330 |
| 331 template <typename MapType> |
| 319 void IndexedDBDispatcherHost::DestroyObject( | 332 void IndexedDBDispatcherHost::DestroyObject( |
| 320 IDMap<ObjectType, IDMapOwnPointer>* map, | 333 MapType* map, |
| 321 int32 ipc_object_id) { | 334 int32 ipc_object_id) { |
| 322 GetOrTerminateProcess(map, ipc_object_id); | 335 GetOrTerminateProcess(map, ipc_object_id); |
| 323 map->Remove(ipc_object_id); | 336 map->Remove(ipc_object_id); |
| 324 } | 337 } |
| 325 | 338 |
| 326 ////////////////////////////////////////////////////////////////////// | 339 ////////////////////////////////////////////////////////////////////// |
| 327 // IndexedDBDispatcherHost::DatabaseDispatcherHost | 340 // IndexedDBDispatcherHost::DatabaseDispatcherHost |
| 328 // | 341 // |
| 329 | 342 |
| 330 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( | 343 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( | 601 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( |
| 589 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { | 602 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { |
| 590 DCHECK( | 603 DCHECK( |
| 591 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 604 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 592 WebIDBDatabaseImpl* database = | 605 WebIDBDatabaseImpl* database = |
| 593 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 606 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 594 if (!database) | 607 if (!database) |
| 595 return; | 608 return; |
| 596 | 609 |
| 597 scoped_ptr<IndexedDBCallbacksBase> callbacks( | 610 scoped_ptr<IndexedDBCallbacksBase> callbacks( |
| 598 new IndexedDBCallbacks<WebIDBCursorImpl>( | 611 new IndexedDBCallbacks<IndexedDBCursor>( |
| 599 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); | 612 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); |
| 600 database->openCursor(parent_->HostTransactionId(params.transaction_id), | 613 database->openCursor(parent_->HostTransactionId(params.transaction_id), |
| 601 params.object_store_id, | 614 params.object_store_id, |
| 602 params.index_id, | 615 params.index_id, |
| 603 params.key_range, | 616 params.key_range, |
| 604 params.direction, | 617 params.direction, |
| 605 params.key_only, | 618 params.key_only, |
| 606 params.task_type, | 619 params.task_type, |
| 607 callbacks.release()); | 620 callbacks.release()); |
| 608 } | 621 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 parent_->Send(message); | 793 parent_->Send(message); |
| 781 } | 794 } |
| 782 | 795 |
| 783 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( | 796 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( |
| 784 int32 ipc_cursor_id, | 797 int32 ipc_cursor_id, |
| 785 int32 ipc_thread_id, | 798 int32 ipc_thread_id, |
| 786 int32 ipc_callbacks_id, | 799 int32 ipc_callbacks_id, |
| 787 unsigned long count) { | 800 unsigned long count) { |
| 788 DCHECK( | 801 DCHECK( |
| 789 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 802 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 790 WebIDBCursorImpl* idb_cursor = | 803 IndexedDBCursor* idb_cursor = |
| 791 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 804 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
| 792 if (!idb_cursor) | 805 if (!idb_cursor) |
| 793 return; | 806 return; |
| 794 | 807 |
| 795 idb_cursor->advance( | 808 idb_cursor->Advance( |
| 796 count, | 809 count, |
| 797 new IndexedDBCallbacks<WebIDBCursorImpl>( | 810 IndexedDBCallbacksWrapper::Create(new IndexedDBCallbacks<IndexedDBCursor>( |
| 798 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 811 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id))); |
| 799 } | 812 } |
| 800 | 813 |
| 801 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( | 814 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( |
| 802 int32 ipc_cursor_id, | 815 int32 ipc_cursor_id, |
| 803 int32 ipc_thread_id, | 816 int32 ipc_thread_id, |
| 804 int32 ipc_callbacks_id, | 817 int32 ipc_callbacks_id, |
| 805 const IndexedDBKey& key) { | 818 const IndexedDBKey& key) { |
| 806 DCHECK( | 819 DCHECK( |
| 807 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 820 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 808 WebIDBCursorImpl* idb_cursor = | 821 IndexedDBCursor* idb_cursor = |
| 809 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 822 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
| 810 if (!idb_cursor) | 823 if (!idb_cursor) |
| 811 return; | 824 return; |
| 812 | 825 |
| 813 idb_cursor->continueFunction( | 826 idb_cursor->ContinueFunction( |
| 814 key, | 827 make_scoped_ptr(new IndexedDBKey(key)), |
| 815 new IndexedDBCallbacks<WebIDBCursorImpl>( | 828 IndexedDBCallbacksWrapper::Create(new IndexedDBCallbacks<IndexedDBCursor>( |
| 816 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 829 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id))); |
| 817 } | 830 } |
| 818 | 831 |
| 819 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( | 832 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( |
| 820 int32 ipc_cursor_id, | 833 int32 ipc_cursor_id, |
| 821 int32 ipc_thread_id, | 834 int32 ipc_thread_id, |
| 822 int32 ipc_callbacks_id, | 835 int32 ipc_callbacks_id, |
| 823 int n) { | 836 int n) { |
| 824 DCHECK( | 837 DCHECK( |
| 825 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 838 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 826 WebIDBCursorImpl* idb_cursor = | 839 IndexedDBCursor* idb_cursor = |
| 827 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 840 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
| 828 if (!idb_cursor) | 841 if (!idb_cursor) |
| 829 return; | 842 return; |
| 830 | 843 |
| 831 idb_cursor->prefetchContinue( | 844 idb_cursor->PrefetchContinue( |
| 832 n, | 845 n, |
| 833 new IndexedDBCallbacks<WebIDBCursorImpl>( | 846 IndexedDBCallbacksWrapper::Create(new IndexedDBCallbacks<IndexedDBCursor>( |
| 834 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id)); | 847 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id))); |
| 835 } | 848 } |
| 836 | 849 |
| 837 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( | 850 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( |
| 838 int32 ipc_cursor_id, | 851 int32 ipc_cursor_id, |
| 839 int used_prefetches, | 852 int used_prefetches, |
| 840 int unused_prefetches) { | 853 int unused_prefetches) { |
| 841 DCHECK( | 854 DCHECK( |
| 842 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 855 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 843 WebIDBCursorImpl* idb_cursor = | 856 IndexedDBCursor* idb_cursor = |
| 844 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | 857 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); |
| 845 if (!idb_cursor) | 858 if (!idb_cursor) |
| 846 return; | 859 return; |
| 847 | 860 |
| 848 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); | 861 idb_cursor->PrefetchReset(used_prefetches, unused_prefetches); |
| 849 } | 862 } |
| 850 | 863 |
| 851 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 864 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 852 int32 ipc_object_id) { | 865 int32 ipc_object_id) { |
| 853 DCHECK( | 866 DCHECK( |
| 854 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 867 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 855 parent_->DestroyObject(&map_, ipc_object_id); | 868 parent_->DestroyObject(&map_, ipc_object_id); |
| 856 } | 869 } |
| 857 | 870 |
| 858 } // namespace content | 871 } // namespace content |
| OLD | NEW |