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

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: delete -> deleteRange 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 // XXX can't swap here because params has a const
jsbell 2013/01/03 01:17:35 This comment still looks like a note-to-self?
535 WebVector<unsigned char> value(params.value);
536 database->put(parent_->HostTransactionId(params.transaction_id),
537 params.object_store_id,
538 &value, params.key,
539 params.put_mode, callbacks.release(),
540 params.index_ids,
541 params.index_keys);
542 WebIDBTransactionIDToSizeMap* map =
543 &parent_->database_dispatcher_host_->transaction_size_map_;
544 // Size can't be big enough to overflow because it represents the
545 // actual bytes passed through IPC.
546 int64 transaction_id = parent_->HostTransactionId(params.transaction_id);
547 (*map)[transaction_id] += params.value.size();
548 }
549
550 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
551 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
553 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
554 &map_, params.ipc_database_id);
555 if (!database)
556 return;
557
558 database->setIndexKeys(parent_->HostTransactionId(params.transaction_id),
559 params.object_store_id,
560 params.primary_key, params.index_ids,
561 params.index_keys);
562 }
563
564 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
565 int32 ipc_database_id,
566 int64 transaction_id,
567 int64 object_store_id,
568 const std::vector<int64>& index_ids) {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
570 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
571 &map_, ipc_database_id);
572 if (!database)
573 return;
574
575 database->setIndexesReady(parent_->HostTransactionId(transaction_id),
576 object_store_id,
577 WebVector<long long>(index_ids));
578 }
579
580 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
581 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
583 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
584 &map_, params.ipc_database_id);
585 if (!database)
586 return;
587
588 scoped_ptr<WebIDBCallbacks> callbacks(
589 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
590 params.ipc_response_id, -1));
591 database->openCursor(
592 parent_->HostTransactionId(params.transaction_id),
593 params.object_store_id, params.index_id,
594 params.key_range, params.direction, params.key_only, params.task_type,
595 callbacks.release());
596 }
597
598 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
599 const IndexedDBHostMsg_DatabaseCount_Params& params) {
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
601 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
602 &map_, params.ipc_database_id);
603 if (!database)
604 return;
605
606 scoped_ptr<WebIDBCallbacks> callbacks(
607 new IndexedDBCallbacks<WebSerializedScriptValue>(
608 parent_, params.ipc_thread_id,
609 params.ipc_response_id));
610 database->count(
611 parent_->HostTransactionId(params.transaction_id),
612 params.object_store_id, params.index_id,
613 params.key_range, callbacks.release());
614 }
615
616 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
617 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
619 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
620 &map_, params.ipc_database_id);
621 if (!database)
622 return;
623
624 scoped_ptr<WebIDBCallbacks> callbacks(
625 new IndexedDBCallbacks<WebSerializedScriptValue>(
626 parent_, params.ipc_thread_id,
627 params.ipc_response_id));
628 database->deleteRange(parent_->HostTransactionId(params.transaction_id),
629 params.object_store_id,
630 params.key_range, callbacks.release());
631 }
632
633 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
634 int32 ipc_thread_id,
635 int32 ipc_response_id,
636 int32 ipc_database_id,
637 int64 transaction_id,
638 int64 object_store_id) {
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
640 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
641 &map_, ipc_database_id);
642 if (!database)
643 return;
644
645 scoped_ptr<WebIDBCallbacks> callbacks(
646 new IndexedDBCallbacks<WebSerializedScriptValue>(
647 parent_, ipc_thread_id,
648 ipc_response_id));
649
650 database->clear(parent_->HostTransactionId(transaction_id),
651 object_store_id, callbacks.release());
652 }
494 653
495 ////////////////////////////////////////////////////////////////////// 654 //////////////////////////////////////////////////////////////////////
496 // IndexedDBDispatcherHost::IndexDispatcherHost 655 // IndexedDBDispatcherHost::IndexDispatcherHost
497 // 656 //
498 657
499 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost( 658 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost(
500 IndexedDBDispatcherHost* parent) 659 IndexedDBDispatcherHost* parent)
501 : parent_(parent) { 660 : parent_(parent) {
502 map_.set_check_on_null_data(true); 661 map_.set_check_on_null_data(true);
503 } 662 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 return; 871 return;
713 872
714 scoped_ptr<WebIDBCallbacks> callbacks( 873 scoped_ptr<WebIDBCallbacks> callbacks(
715 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id, 874 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id,
716 params.ipc_response_id)); 875 params.ipc_response_id));
717 idb_object_store->put(params.serialized_value, params.key, 876 idb_object_store->put(params.serialized_value, params.key,
718 params.put_mode, callbacks.release(), 877 params.put_mode, callbacks.release(),
719 *idb_transaction, params.index_ids, 878 *idb_transaction, params.index_ids,
720 params.index_keys); 879 params.index_keys);
721 int64 size = UTF16ToUTF8(params.serialized_value.data()).size(); 880 int64 size = UTF16ToUTF8(params.serialized_value.data()).size();
722 WebIDBTransactionIDToSizeMap* map = 881 WebIDBTransactionIPCIDToSizeMap* map =
723 &parent_->transaction_dispatcher_host_->transaction_size_map_; 882 &parent_->transaction_dispatcher_host_->transaction_ipc_size_map_;
724 (*map)[params.ipc_transaction_id] += size; 883 (*map)[params.ipc_transaction_id] += size;
725 } 884 }
726 885
727 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexKeys( 886 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexKeys(
728 int32 ipc_object_store_id, 887 int32 ipc_object_store_id,
729 const IndexedDBKey& primary_key, 888 const IndexedDBKey& primary_key,
730 const std::vector<int64>& index_names, 889 const std::vector<int64>& index_names,
731 const std::vector<std::vector<IndexedDBKey> >& index_keys, 890 const std::vector<std::vector<IndexedDBKey> >& index_keys,
732 int32 ipc_transaction_id) { 891 int32 ipc_transaction_id) {
733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 892 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 int32 ipc_transaction_id) { 1235 int32 ipc_transaction_id) {
1077 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( 1236 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1078 &map_, ipc_transaction_id); 1237 &map_, ipc_transaction_id);
1079 if (!idb_transaction) 1238 if (!idb_transaction)
1080 return; 1239 return;
1081 1240
1082 // TODO(dgrogan): Tell the page the transaction aborted because of quota. 1241 // TODO(dgrogan): Tell the page the transaction aborted because of quota.
1083 // http://crbug.com/113118 1242 // http://crbug.com/113118
1084 if (parent_->Context()->WouldBeOverQuota( 1243 if (parent_->Context()->WouldBeOverQuota(
1085 transaction_url_map_[ipc_transaction_id], 1244 transaction_url_map_[ipc_transaction_id],
1086 transaction_size_map_[ipc_transaction_id])) { 1245 transaction_ipc_size_map_[ipc_transaction_id])) {
1087 idb_transaction->abort(); 1246 idb_transaction->abort();
1088 return; 1247 return;
1089 } 1248 }
1090 1249
1091 idb_transaction->commit(); 1250 idb_transaction->commit();
1092 } 1251 }
1093 1252
1094 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnAbort( 1253 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnAbort(
1095 int32 ipc_transaction_id) { 1254 int32 ipc_transaction_id) {
1096 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess( 1255 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
(...skipping 25 matching lines...) Expand all
1122 &map_, ipc_transaction_id); 1281 &map_, ipc_transaction_id);
1123 if (!idb_transaction) 1282 if (!idb_transaction)
1124 return; 1283 return;
1125 idb_transaction->didCompleteTaskEvents(); 1284 idb_transaction->didCompleteTaskEvents();
1126 } 1285 }
1127 1286
1128 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( 1287 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed(
1129 int32 ipc_object_id) { 1288 int32 ipc_object_id) {
1130 // TODO(dgrogan): This doesn't seem to be happening with some version change 1289 // TODO(dgrogan): This doesn't seem to be happening with some version change
1131 // transactions. Possibly introduced with integer version support. 1290 // transactions. Possibly introduced with integer version support.
1132 transaction_size_map_.erase(ipc_object_id); 1291 transaction_ipc_size_map_.erase(ipc_object_id);
1133 transaction_url_map_.erase(ipc_object_id); 1292 transaction_url_map_.erase(ipc_object_id);
1134 parent_->DestroyObject(&map_, ipc_object_id); 1293 parent_->DestroyObject(&map_, ipc_object_id);
1135 } 1294 }
1136 1295
1137 } // namespace content 1296 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698