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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_dispatcher_host.cc

Issue 11567029: Proxy new objectstore/index methods through IPC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix nits, use faster copies Created 7 years, 11 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/in_process_webkit/indexed_db_dispatcher_host.h" 5 #include "content/browser/in_process_webkit/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"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) { 203 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
204 // Inject the renderer process id into the transaction id, to 204 // Inject the renderer process id into the transaction id, to
205 // uniquely identify this transaction, and effectively bind it to 205 // uniquely identify this transaction, and effectively bind it to
206 // the renderer that initiated it. The lower 32 bits of 206 // the renderer that initiated it. The lower 32 bits of
207 // transaction_id are guaranteed to be unique within that renderer. 207 // transaction_id are guaranteed to be unique within that renderer.
208 base::ProcessId pid = base::GetProcId(peer_handle()); 208 base::ProcessId pid = base::GetProcId(peer_handle());
209 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; 209 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
210 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32), 210 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32),
211 Process_ID_must_fit_in_32_bits); 211 Process_ID_must_fit_in_32_bits);
212 212
213 return transaction_id |= (static_cast<uint64>(pid) << 32); 213 return transaction_id | (static_cast<uint64>(pid) << 32);
214 } 214 }
215 215
216 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { 216 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
218 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); 218 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id);
219 } 219 }
220 220
221 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( 221 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
222 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { 222 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 message, *msg_is_ok) 354 message, *msg_is_ok)
355 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseMetadata, OnMetadata) 355 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseMetadata, OnMetadata)
356 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, 356 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
357 OnCreateObjectStore) 357 OnCreateObjectStore)
358 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, 358 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
359 OnDeleteObjectStore) 359 OnDeleteObjectStore)
360 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, 360 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
361 OnCreateTransaction) 361 OnCreateTransaction)
362 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) 362 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
363 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) 363 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
364 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet)
365 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut)
366 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys,
367 OnSetIndexKeys)
368 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady,
369 OnSetIndexesReady)
370 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor)
371 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount)
372 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange)
373 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear)
364 IPC_MESSAGE_UNHANDLED(handled = false) 374 IPC_MESSAGE_UNHANDLED(handled = false)
365 IPC_END_MESSAGE_MAP() 375 IPC_END_MESSAGE_MAP()
366 return handled; 376 return handled;
367 } 377 }
368 378
369 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( 379 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
370 IPC::Message* message) { 380 IPC::Message* message) {
371 parent_->Send(message); 381 parent_->Send(message);
372 } 382 }
373 383
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 494
485 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( 495 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
486 int32 ipc_object_id) { 496 int32 ipc_object_id) {
487 WebIDBDatabase* database = map_.Lookup(ipc_object_id); 497 WebIDBDatabase* database = map_.Lookup(ipc_object_id);
488 parent_->Context()->ConnectionClosed(database_url_map_[ipc_object_id], 498 parent_->Context()->ConnectionClosed(database_url_map_[ipc_object_id],
489 database); 499 database);
490 database_url_map_.erase(ipc_object_id); 500 database_url_map_.erase(ipc_object_id);
491 parent_->DestroyObject(&map_, ipc_object_id); 501 parent_->DestroyObject(&map_, ipc_object_id);
492 } 502 }
493 503
504 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
505 const IndexedDBHostMsg_DatabaseGet_Params& params) {
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
507 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
508 &map_, params.ipc_database_id);
509 if (!database)
510 return;
511
512 scoped_ptr<WebIDBCallbacks> callbacks(
513 new IndexedDBCallbacks<WebSerializedScriptValue>(
514 parent_, params.ipc_thread_id,
515 params.ipc_response_id));
516 database->get(parent_->HostTransactionId(params.transaction_id),
517 params.object_store_id,
518 params.index_id,
519 params.key_range, params.key_only, callbacks.release());
520 }
521
522 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
523 const IndexedDBHostMsg_DatabasePut_Params& params) {
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
525
526 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
527 &map_, params.ipc_database_id);
528 if (!database)
529 return;
530 scoped_ptr<WebIDBCallbacks> callbacks(
531 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id,
532 params.ipc_response_id));
533
534 WebVector<unsigned char> value(params.value);
535 database->put(parent_->HostTransactionId(params.transaction_id),
536 params.object_store_id,
537 &value, params.key,
538 params.put_mode, callbacks.release(),
539 params.index_ids,
540 params.index_keys);
541 WebIDBTransactionIDToSizeMap* map =
542 &parent_->database_dispatcher_host_->transaction_size_map_;
543 // Size can't be big enough to overflow because it represents the
544 // actual bytes passed through IPC.
545 int64 transaction_id = parent_->HostTransactionId(params.transaction_id);
546 (*map)[transaction_id] += params.value.size();
547 }
548
549 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
550 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
552 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
553 &map_, params.ipc_database_id);
554 if (!database)
555 return;
556
557 database->setIndexKeys(parent_->HostTransactionId(params.transaction_id),
558 params.object_store_id,
559 params.primary_key, params.index_ids,
560 params.index_keys);
561 }
562
563 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
564 int32 ipc_database_id,
565 int64 transaction_id,
566 int64 object_store_id,
567 const std::vector<int64>& index_ids) {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
569 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
570 &map_, ipc_database_id);
571 if (!database)
572 return;
573
574 database->setIndexesReady(parent_->HostTransactionId(transaction_id),
575 object_store_id,
576 WebVector<long long>(index_ids));
577 }
578
579 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
580 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
582 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
583 &map_, params.ipc_database_id);
584 if (!database)
585 return;
586
587 scoped_ptr<WebIDBCallbacks> callbacks(
588 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
589 params.ipc_response_id, -1));
590 database->openCursor(
591 parent_->HostTransactionId(params.transaction_id),
592 params.object_store_id, params.index_id,
593 params.key_range, params.direction, params.key_only, params.task_type,
594 callbacks.release());
595 }
596
597 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
598 const IndexedDBHostMsg_DatabaseCount_Params& params) {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
600 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
601 &map_, params.ipc_database_id);
602 if (!database)
603 return;
604
605 scoped_ptr<WebIDBCallbacks> callbacks(
606 new IndexedDBCallbacks<WebSerializedScriptValue>(
607 parent_, params.ipc_thread_id,
608 params.ipc_response_id));
609 database->count(
610 parent_->HostTransactionId(params.transaction_id),
611 params.object_store_id, params.index_id,
612 params.key_range, callbacks.release());
613 }
614
615 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
616 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
618 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
619 &map_, params.ipc_database_id);
620 if (!database)
621 return;
622
623 scoped_ptr<WebIDBCallbacks> callbacks(
624 new IndexedDBCallbacks<WebSerializedScriptValue>(
625 parent_, params.ipc_thread_id,
626 params.ipc_response_id));
627 database->deleteRange(parent_->HostTransactionId(params.transaction_id),
628 params.object_store_id,
629 params.key_range, callbacks.release());
630 }
631
632 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
633 int32 ipc_thread_id,
634 int32 ipc_response_id,
635 int32 ipc_database_id,
636 int64 transaction_id,
637 int64 object_store_id) {
638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
639 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
640 &map_, ipc_database_id);
641 if (!database)
642 return;
643
644 scoped_ptr<WebIDBCallbacks> callbacks(
645 new IndexedDBCallbacks<WebSerializedScriptValue>(
646 parent_, ipc_thread_id,
647 ipc_response_id));
648
649 database->clear(parent_->HostTransactionId(transaction_id),
650 object_store_id, callbacks.release());
651 }
494 652
495 ////////////////////////////////////////////////////////////////////// 653 //////////////////////////////////////////////////////////////////////
496 // IndexedDBDispatcherHost::IndexDispatcherHost 654 // IndexedDBDispatcherHost::IndexDispatcherHost
497 // 655 //
498 656
499 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost( 657 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost(
500 IndexedDBDispatcherHost* parent) 658 IndexedDBDispatcherHost* parent)
501 : parent_(parent) { 659 : parent_(parent) {
502 map_.set_check_on_null_data(true); 660 map_.set_check_on_null_data(true);
503 } 661 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 return; 870 return;
713 871
714 scoped_ptr<WebIDBCallbacks> callbacks( 872 scoped_ptr<WebIDBCallbacks> callbacks(
715 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id, 873 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id,
716 params.ipc_response_id)); 874 params.ipc_response_id));
717 idb_object_store->put(params.serialized_value, params.key, 875 idb_object_store->put(params.serialized_value, params.key,
718 params.put_mode, callbacks.release(), 876 params.put_mode, callbacks.release(),
719 *idb_transaction, params.index_ids, 877 *idb_transaction, params.index_ids,
720 params.index_keys); 878 params.index_keys);
721 int64 size = UTF16ToUTF8(params.serialized_value.data()).size(); 879 int64 size = UTF16ToUTF8(params.serialized_value.data()).size();
722 WebIDBTransactionIDToSizeMap* map = 880 WebIDBTransactionIPCIDToSizeMap* map =
723 &parent_->transaction_dispatcher_host_->transaction_size_map_; 881 &parent_->transaction_dispatcher_host_->transaction_ipc_size_map_;
724 (*map)[params.ipc_transaction_id] += size; 882 (*map)[params.ipc_transaction_id] += size;
725 } 883 }
726 884
727 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexKeys( 885 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexKeys(
728 int32 ipc_object_store_id, 886 int32 ipc_object_store_id,
729 const IndexedDBKey& primary_key, 887 const IndexedDBKey& primary_key,
730 const std::vector<int64>& index_names, 888 const std::vector<int64>& index_names,
731 const std::vector<std::vector<IndexedDBKey> >& index_keys, 889 const std::vector<std::vector<IndexedDBKey> >& index_keys,
732 int32 ipc_transaction_id) { 890 int32 ipc_transaction_id) {
733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 891 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 int32 ipc_transaction_id) { 1234 int32 ipc_transaction_id) {
1077 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( 1235 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1078 &map_, ipc_transaction_id); 1236 &map_, ipc_transaction_id);
1079 if (!idb_transaction) 1237 if (!idb_transaction)
1080 return; 1238 return;
1081 1239
1082 // TODO(dgrogan): Tell the page the transaction aborted because of quota. 1240 // TODO(dgrogan): Tell the page the transaction aborted because of quota.
1083 // http://crbug.com/113118 1241 // http://crbug.com/113118
1084 if (parent_->Context()->WouldBeOverQuota( 1242 if (parent_->Context()->WouldBeOverQuota(
1085 transaction_url_map_[ipc_transaction_id], 1243 transaction_url_map_[ipc_transaction_id],
1086 transaction_size_map_[ipc_transaction_id])) { 1244 transaction_ipc_size_map_[ipc_transaction_id])) {
1087 idb_transaction->abort(); 1245 idb_transaction->abort();
1088 return; 1246 return;
1089 } 1247 }
1090 1248
1091 idb_transaction->commit(); 1249 idb_transaction->commit();
1092 } 1250 }
1093 1251
1094 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnAbort( 1252 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnAbort(
1095 int32 ipc_transaction_id) { 1253 int32 ipc_transaction_id) {
1096 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( 1254 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
(...skipping 25 matching lines...) Expand all
1122 &map_, ipc_transaction_id); 1280 &map_, ipc_transaction_id);
1123 if (!idb_transaction) 1281 if (!idb_transaction)
1124 return; 1282 return;
1125 idb_transaction->didCompleteTaskEvents(); 1283 idb_transaction->didCompleteTaskEvents();
1126 } 1284 }
1127 1285
1128 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( 1286 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed(
1129 int32 ipc_object_id) { 1287 int32 ipc_object_id) {
1130 // TODO(dgrogan): This doesn't seem to be happening with some version change 1288 // TODO(dgrogan): This doesn't seem to be happening with some version change
1131 // transactions. Possibly introduced with integer version support. 1289 // transactions. Possibly introduced with integer version support.
1132 transaction_size_map_.erase(ipc_object_id); 1290 transaction_ipc_size_map_.erase(ipc_object_id);
1133 transaction_url_map_.erase(ipc_object_id); 1291 transaction_url_map_.erase(ipc_object_id);
1134 parent_->DestroyObject(&map_, ipc_object_id); 1292 parent_->DestroyObject(&map_, ipc_object_id);
1135 } 1293 }
1136 1294
1137 } // namespace content 1295 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_dispatcher_host.h ('k') | content/common/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698