| 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_connection.h" |
| 16 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 17 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 17 #include "content/browser/indexed_db/indexed_db_cursor.h" | 18 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 19 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 19 #include "content/browser/indexed_db/indexed_db_metadata.h" | 20 #include "content/browser/indexed_db/indexed_db_metadata.h" |
| 20 #include "content/browser/indexed_db/webidbdatabase_impl.h" | |
| 21 #include "content/browser/renderer_host/render_message_filter.h" | 21 #include "content/browser/renderer_host/render_message_filter.h" |
| 22 #include "content/common/indexed_db/indexed_db_messages.h" | 22 #include "content/common/indexed_db/indexed_db_messages.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 28 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" | |
| 29 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 28 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
| 30 #include "webkit/browser/database/database_util.h" | 29 #include "webkit/browser/database/database_util.h" |
| 31 #include "webkit/common/database/database_identifier.h" | 30 #include "webkit/common/database/database_identifier.h" |
| 32 | 31 |
| 33 using webkit_database::DatabaseUtil; | 32 using webkit_database::DatabaseUtil; |
| 34 using WebKit::WebIDBKey; | 33 using WebKit::WebIDBKey; |
| 35 | 34 |
| 36 namespace content { | 35 namespace content { |
| 37 | 36 |
| 38 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 37 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 OnIDBFactoryGetDatabaseNames) | 106 OnIDBFactoryGetDatabaseNames) |
| 108 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) | 107 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) |
| 109 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, | 108 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, |
| 110 OnIDBFactoryDeleteDatabase) | 109 OnIDBFactoryDeleteDatabase) |
| 111 IPC_MESSAGE_UNHANDLED(handled = false) | 110 IPC_MESSAGE_UNHANDLED(handled = false) |
| 112 IPC_END_MESSAGE_MAP() | 111 IPC_END_MESSAGE_MAP() |
| 113 } | 112 } |
| 114 return handled; | 113 return handled; |
| 115 } | 114 } |
| 116 | 115 |
| 117 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* idb_cursor) { | 116 int32 IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { |
| 118 if (!cursor_dispatcher_host_) { | 117 if (!cursor_dispatcher_host_) { |
| 119 return 0; | 118 return 0; |
| 120 } | 119 } |
| 121 return cursor_dispatcher_host_->map_.Add(idb_cursor); | 120 return cursor_dispatcher_host_->map_.Add(cursor); |
| 122 } | 121 } |
| 123 | 122 |
| 124 int32 IndexedDBDispatcherHost::Add(WebIDBDatabaseImpl* idb_database, | 123 int32 IndexedDBDispatcherHost::Add(IndexedDBConnection* connection, |
| 125 int32 ipc_thread_id, | 124 int32 ipc_thread_id, |
| 126 const GURL& origin_url) { | 125 const GURL& origin_url) { |
| 127 if (!database_dispatcher_host_) { | 126 if (!database_dispatcher_host_) { |
| 128 delete idb_database; | 127 delete connection; |
| 129 return 0; | 128 return 0; |
| 130 } | 129 } |
| 131 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database); | 130 int32 ipc_database_id = database_dispatcher_host_->map_.Add(connection); |
| 132 Context()->ConnectionOpened(origin_url, idb_database); | 131 Context()->ConnectionOpened(origin_url, connection); |
| 133 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url; | 132 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url; |
| 134 return ipc_database_id; | 133 return ipc_database_id; |
| 135 } | 134 } |
| 136 | 135 |
| 137 void IndexedDBDispatcherHost::RegisterTransactionId(int64 host_transaction_id, | 136 void IndexedDBDispatcherHost::RegisterTransactionId(int64 host_transaction_id, |
| 138 const GURL& url) { | 137 const GURL& url) { |
| 139 if (!database_dispatcher_host_) | 138 if (!database_dispatcher_host_) |
| 140 return; | 139 return; |
| 141 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url; | 140 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url; |
| 142 } | 141 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 scoped_refptr<IndexedDBCallbacks> callbacks = | 234 scoped_refptr<IndexedDBCallbacks> callbacks = |
| 236 IndexedDBCallbacks::Create(this, | 235 IndexedDBCallbacks::Create(this, |
| 237 params.ipc_thread_id, | 236 params.ipc_thread_id, |
| 238 params.ipc_callbacks_id, | 237 params.ipc_callbacks_id, |
| 239 params.ipc_database_callbacks_id, | 238 params.ipc_database_callbacks_id, |
| 240 host_transaction_id, | 239 host_transaction_id, |
| 241 origin_url); | 240 origin_url); |
| 242 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = | 241 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = |
| 243 IndexedDBDatabaseCallbacks::Create( | 242 IndexedDBDatabaseCallbacks::Create( |
| 244 this, params.ipc_thread_id, params.ipc_database_callbacks_id); | 243 this, params.ipc_thread_id, params.ipc_database_callbacks_id); |
| 245 callbacks->SetDatabaseCallbacks(database_callbacks); | |
| 246 Context()->GetIDBFactory()-> | 244 Context()->GetIDBFactory()-> |
| 247 Open(params.name, | 245 Open(params.name, |
| 248 params.version, | 246 params.version, |
| 249 host_transaction_id, | 247 host_transaction_id, |
| 250 callbacks, | 248 callbacks, |
| 251 database_callbacks, | 249 database_callbacks, |
| 252 base::UTF8ToUTF16(params.database_identifier), | 250 base::UTF8ToUTF16(params.database_identifier), |
| 253 indexed_db_path); | 251 indexed_db_path); |
| 254 } | 252 } |
| 255 | 253 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 349 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 352 // Abort outstanding transactions started by connections in the associated | 350 // Abort outstanding transactions started by connections in the associated |
| 353 // front-end to unblock later transactions. This should only occur on unclean | 351 // front-end to unblock later transactions. This should only occur on unclean |
| 354 // (crash) or abrupt (process-kill) shutdowns. | 352 // (crash) or abrupt (process-kill) shutdowns. |
| 355 for (TransactionIDToDatabaseIDMap::iterator iter = | 353 for (TransactionIDToDatabaseIDMap::iterator iter = |
| 356 transaction_database_map_.begin(); | 354 transaction_database_map_.begin(); |
| 357 iter != transaction_database_map_.end();) { | 355 iter != transaction_database_map_.end();) { |
| 358 int64 transaction_id = iter->first; | 356 int64 transaction_id = iter->first; |
| 359 int32 ipc_database_id = iter->second; | 357 int32 ipc_database_id = iter->second; |
| 360 ++iter; | 358 ++iter; |
| 361 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id); | 359 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); |
| 362 if (database) { | 360 if (connection) { |
| 363 database->abort( | 361 connection->database()->Abort( |
| 364 transaction_id, | 362 transaction_id, |
| 365 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError)); | 363 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError)); |
| 366 } | 364 } |
| 367 } | 365 } |
| 368 DCHECK(transaction_database_map_.empty()); | 366 DCHECK(transaction_database_map_.empty()); |
| 369 | 367 |
| 370 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); | 368 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); |
| 371 iter != database_url_map_.end(); | 369 iter != database_url_map_.end(); |
| 372 iter++) { | 370 iter++) { |
| 373 WebIDBDatabaseImpl* database = map_.Lookup(iter->first); | 371 IndexedDBConnection* connection = map_.Lookup(iter->first); |
| 374 if (database) { | 372 if (connection) { |
| 375 database->close(); | 373 connection->Close(); |
| 376 parent_->Context()->ConnectionClosed(iter->second, database); | 374 parent_->Context()->ConnectionClosed(iter->second, connection); |
| 377 } | 375 } |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 | 378 |
| 381 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( | 379 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( |
| 382 const IPC::Message& message, | 380 const IPC::Message& message, |
| 383 bool* msg_is_ok) { | 381 bool* msg_is_ok) { |
| 384 DCHECK( | 382 DCHECK( |
| 385 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 383 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 386 bool handled = true; | 384 bool handled = true; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 414 | 412 |
| 415 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( | 413 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( |
| 416 IPC::Message* message) { | 414 IPC::Message* message) { |
| 417 parent_->Send(message); | 415 parent_->Send(message); |
| 418 } | 416 } |
| 419 | 417 |
| 420 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( | 418 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( |
| 421 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { | 419 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { |
| 422 DCHECK( | 420 DCHECK( |
| 423 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 421 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 424 WebIDBDatabaseImpl* database = | 422 IndexedDBConnection* connection = |
| 425 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 423 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 426 if (!database) | 424 if (!connection) |
| 427 return; | 425 return; |
| 428 | 426 |
| 429 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 427 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 430 database->createObjectStore(host_transaction_id, | 428 connection->database()->CreateObjectStore(host_transaction_id, |
| 431 params.object_store_id, | 429 params.object_store_id, |
| 432 params.name, | 430 params.name, |
| 433 params.key_path, | 431 params.key_path, |
| 434 params.auto_increment); | 432 params.auto_increment); |
| 435 if (parent_->Context()->IsOverQuota( | 433 if (parent_->Context()->IsOverQuota( |
| 436 database_url_map_[params.ipc_database_id])) { | 434 database_url_map_[params.ipc_database_id])) { |
| 437 database->abort( | 435 connection->database()->Abort( |
| 438 host_transaction_id, | 436 host_transaction_id, |
| 439 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 437 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
| 440 } | 438 } |
| 441 } | 439 } |
| 442 | 440 |
| 443 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | 441 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( |
| 444 int32 ipc_database_id, | 442 int32 ipc_database_id, |
| 445 int64 transaction_id, | 443 int64 transaction_id, |
| 446 int64 object_store_id) { | 444 int64 object_store_id) { |
| 447 DCHECK( | 445 DCHECK( |
| 448 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 446 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 449 WebIDBDatabaseImpl* database = | 447 IndexedDBConnection* connection = |
| 450 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 448 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 451 if (!database) | 449 if (!connection) |
| 452 return; | 450 return; |
| 453 | 451 |
| 454 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), | 452 connection->database()->DeleteObjectStore( |
| 455 object_store_id); | 453 parent_->HostTransactionId(transaction_id), object_store_id); |
| 456 } | 454 } |
| 457 | 455 |
| 458 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( | 456 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( |
| 459 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { | 457 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { |
| 460 DCHECK( | 458 DCHECK( |
| 461 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 459 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 462 WebIDBDatabaseImpl* database = | 460 IndexedDBConnection* connection = |
| 463 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 461 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 464 if (!database) | 462 if (!connection) |
| 465 return; | 463 return; |
| 466 | 464 |
| 467 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 465 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 468 | 466 |
| 469 database->createTransaction( | 467 connection->database()->CreateTransaction(host_transaction_id, |
| 470 host_transaction_id, params.object_store_ids, params.mode); | 468 connection, |
| 469 params.object_store_ids, |
| 470 params.mode); |
| 471 transaction_database_map_[host_transaction_id] = params.ipc_database_id; | 471 transaction_database_map_[host_transaction_id] = params.ipc_database_id; |
| 472 parent_->RegisterTransactionId(host_transaction_id, | 472 parent_->RegisterTransactionId(host_transaction_id, |
| 473 database_url_map_[params.ipc_database_id]); | 473 database_url_map_[params.ipc_database_id]); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( | 476 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( |
| 477 int32 ipc_database_id) { | 477 int32 ipc_database_id) { |
| 478 DCHECK( | 478 DCHECK( |
| 479 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 479 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 480 WebIDBDatabaseImpl* database = | 480 IndexedDBConnection* connection = |
| 481 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 481 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 482 if (!database) | 482 if (!connection) |
| 483 return; | 483 return; |
| 484 database->close(); | 484 connection->Close(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( | 487 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( |
| 488 int32 ipc_object_id) { | 488 int32 ipc_object_id) { |
| 489 DCHECK( | 489 DCHECK( |
| 490 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 490 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 491 WebIDBDatabaseImpl* database = map_.Lookup(ipc_object_id); | 491 IndexedDBConnection* connection = map_.Lookup(ipc_object_id); |
| 492 parent_->Context() | 492 parent_->Context() |
| 493 ->ConnectionClosed(database_url_map_[ipc_object_id], database); | 493 ->ConnectionClosed(database_url_map_[ipc_object_id], connection); |
| 494 database_url_map_.erase(ipc_object_id); | 494 database_url_map_.erase(ipc_object_id); |
| 495 parent_->DestroyObject(&map_, ipc_object_id); | 495 parent_->DestroyObject(&map_, ipc_object_id); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | 498 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( |
| 499 const IndexedDBHostMsg_DatabaseGet_Params& params) { | 499 const IndexedDBHostMsg_DatabaseGet_Params& params) { |
| 500 DCHECK( | 500 DCHECK( |
| 501 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 501 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 502 WebIDBDatabaseImpl* database = | 502 IndexedDBConnection* connection = |
| 503 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 503 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 504 if (!database) | 504 if (!connection) |
| 505 return; | 505 return; |
| 506 | 506 |
| 507 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( | 507 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( |
| 508 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 508 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 509 database->get(parent_->HostTransactionId(params.transaction_id), | 509 connection->database()->Get( |
| 510 params.object_store_id, | 510 parent_->HostTransactionId(params.transaction_id), |
| 511 params.index_id, | 511 params.object_store_id, |
| 512 params.key_range, | 512 params.index_id, |
| 513 params.key_only, | 513 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 514 callbacks); | 514 params.key_only, |
| 515 callbacks); |
| 515 } | 516 } |
| 516 | 517 |
| 517 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 518 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( |
| 518 const IndexedDBHostMsg_DatabasePut_Params& params) { | 519 const IndexedDBHostMsg_DatabasePut_Params& params) { |
| 519 DCHECK( | 520 DCHECK( |
| 520 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 521 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 521 | 522 |
| 522 WebIDBDatabaseImpl* database = | 523 IndexedDBConnection* connection = |
| 523 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 524 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 524 if (!database) | 525 if (!connection) |
| 525 return; | 526 return; |
| 526 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( | 527 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( |
| 527 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 528 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 528 | 529 |
| 529 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 530 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 530 // TODO(alecflett): Avoid a copy here. | 531 // TODO(alecflett): Avoid a copy here. |
| 531 std::vector<char> value_copy = params.value; | 532 std::vector<char> value_copy = params.value; |
| 532 database->put(host_transaction_id, | 533 connection->database()->Put( |
| 533 params.object_store_id, | 534 host_transaction_id, |
| 534 &value_copy, | 535 params.object_store_id, |
| 535 params.key, | 536 &value_copy, |
| 536 params.put_mode, | 537 make_scoped_ptr(new IndexedDBKey(params.key)), |
| 537 callbacks, | 538 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), |
| 538 params.index_ids, | 539 callbacks, |
| 539 params.index_keys); | 540 params.index_ids, |
| 541 params.index_keys); |
| 540 TransactionIDToSizeMap* map = | 542 TransactionIDToSizeMap* map = |
| 541 &parent_->database_dispatcher_host_->transaction_size_map_; | 543 &parent_->database_dispatcher_host_->transaction_size_map_; |
| 542 // Size can't be big enough to overflow because it represents the | 544 // Size can't be big enough to overflow because it represents the |
| 543 // actual bytes passed through IPC. | 545 // actual bytes passed through IPC. |
| 544 (*map)[host_transaction_id] += params.value.size(); | 546 (*map)[host_transaction_id] += params.value.size(); |
| 545 } | 547 } |
| 546 | 548 |
| 547 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( | 549 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( |
| 548 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { | 550 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { |
| 549 DCHECK( | 551 DCHECK( |
| 550 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 552 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 551 WebIDBDatabaseImpl* database = | 553 IndexedDBConnection* connection = |
| 552 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 554 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 553 if (!database) | 555 if (!connection) |
| 554 return; | 556 return; |
| 555 | 557 |
| 556 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 558 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 557 if (params.index_ids.size() != params.index_keys.size()) { | 559 if (params.index_ids.size() != params.index_keys.size()) { |
| 558 database->abort( | 560 connection->database()->Abort( |
| 559 host_transaction_id, | 561 host_transaction_id, |
| 560 IndexedDBDatabaseError( | 562 IndexedDBDatabaseError( |
| 561 WebKit::WebIDBDatabaseExceptionUnknownError, | 563 WebKit::WebIDBDatabaseExceptionUnknownError, |
| 562 "Malformed IPC message: index_ids.size() != index_keys.size()")); | 564 "Malformed IPC message: index_ids.size() != index_keys.size()")); |
| 563 return; | 565 return; |
| 564 } | 566 } |
| 565 | 567 |
| 566 database->setIndexKeys(host_transaction_id, | 568 connection->database()->SetIndexKeys( |
| 567 params.object_store_id, | 569 host_transaction_id, |
| 568 params.primary_key, | 570 params.object_store_id, |
| 569 params.index_ids, | 571 make_scoped_ptr(new IndexedDBKey(params.primary_key)), |
| 570 params.index_keys); | 572 params.index_ids, |
| 573 params.index_keys); |
| 571 } | 574 } |
| 572 | 575 |
| 573 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( | 576 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( |
| 574 int32 ipc_database_id, | 577 int32 ipc_database_id, |
| 575 int64 transaction_id, | 578 int64 transaction_id, |
| 576 int64 object_store_id, | 579 int64 object_store_id, |
| 577 const std::vector<int64>& index_ids) { | 580 const std::vector<int64>& index_ids) { |
| 578 DCHECK( | 581 DCHECK( |
| 579 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 582 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 580 WebIDBDatabaseImpl* database = | 583 IndexedDBConnection* connection = |
| 581 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 584 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 582 if (!database) | 585 if (!connection) |
| 583 return; | 586 return; |
| 584 | 587 |
| 585 database->setIndexesReady( | 588 connection->database()->SetIndexesReady( |
| 586 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); | 589 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); |
| 587 } | 590 } |
| 588 | 591 |
| 589 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( | 592 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( |
| 590 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { | 593 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { |
| 591 DCHECK( | 594 DCHECK( |
| 592 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 595 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 593 WebIDBDatabaseImpl* database = | 596 IndexedDBConnection* connection = |
| 594 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 597 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 595 if (!database) | 598 if (!connection) |
| 596 return; | 599 return; |
| 597 | 600 |
| 598 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( | 601 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( |
| 599 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); | 602 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); |
| 600 database->openCursor(parent_->HostTransactionId(params.transaction_id), | 603 connection->database()->OpenCursor( |
| 601 params.object_store_id, | 604 parent_->HostTransactionId(params.transaction_id), |
| 602 params.index_id, | 605 params.object_store_id, |
| 603 params.key_range, | 606 params.index_id, |
| 604 params.direction, | 607 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 605 params.key_only, | 608 static_cast<indexed_db::CursorDirection>(params.direction), |
| 606 params.task_type, | 609 params.key_only, |
| 607 callbacks); | 610 static_cast<IndexedDBDatabase::TaskType>(params.task_type), |
| 611 callbacks); |
| 608 } | 612 } |
| 609 | 613 |
| 610 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( | 614 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( |
| 611 const IndexedDBHostMsg_DatabaseCount_Params& params) { | 615 const IndexedDBHostMsg_DatabaseCount_Params& params) { |
| 612 DCHECK( | 616 DCHECK( |
| 613 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 617 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 614 WebIDBDatabaseImpl* database = | 618 IndexedDBConnection* connection = |
| 615 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 619 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 616 if (!database) | 620 if (!connection) |
| 617 return; | 621 return; |
| 618 | 622 |
| 619 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( | 623 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( |
| 620 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 624 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 621 database->count(parent_->HostTransactionId(params.transaction_id), | 625 connection->database()->Count( |
| 622 params.object_store_id, | 626 parent_->HostTransactionId(params.transaction_id), |
| 623 params.index_id, | 627 params.object_store_id, |
| 624 params.key_range, | 628 params.index_id, |
| 625 callbacks); | 629 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 630 callbacks); |
| 626 } | 631 } |
| 627 | 632 |
| 628 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( | 633 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( |
| 629 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { | 634 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { |
| 630 DCHECK( | 635 DCHECK( |
| 631 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 636 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 632 WebIDBDatabaseImpl* database = | 637 IndexedDBConnection* connection = |
| 633 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 638 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 634 if (!database) | 639 if (!connection) |
| 635 return; | 640 return; |
| 636 | 641 |
| 637 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( | 642 scoped_refptr<IndexedDBCallbacks> callbacks(IndexedDBCallbacks::Create( |
| 638 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 643 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 639 database->deleteRange(parent_->HostTransactionId(params.transaction_id), | 644 connection->database()->DeleteRange( |
| 640 params.object_store_id, | 645 parent_->HostTransactionId(params.transaction_id), |
| 641 params.key_range, | 646 params.object_store_id, |
| 642 callbacks); | 647 make_scoped_ptr(new IndexedDBKeyRange(params.key_range)), |
| 648 callbacks); |
| 643 } | 649 } |
| 644 | 650 |
| 645 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( | 651 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( |
| 646 int32 ipc_thread_id, | 652 int32 ipc_thread_id, |
| 647 int32 ipc_callbacks_id, | 653 int32 ipc_callbacks_id, |
| 648 int32 ipc_database_id, | 654 int32 ipc_database_id, |
| 649 int64 transaction_id, | 655 int64 transaction_id, |
| 650 int64 object_store_id) { | 656 int64 object_store_id) { |
| 651 DCHECK( | 657 DCHECK( |
| 652 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 658 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 653 WebIDBDatabaseImpl* database = | 659 IndexedDBConnection* connection = |
| 654 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 660 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 655 if (!database) | 661 if (!connection) |
| 656 return; | 662 return; |
| 657 | 663 |
| 658 scoped_refptr<IndexedDBCallbacks> callbacks( | 664 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 659 IndexedDBCallbacks::Create(parent_, ipc_thread_id, ipc_callbacks_id)); | 665 IndexedDBCallbacks::Create(parent_, ipc_thread_id, ipc_callbacks_id)); |
| 660 | 666 |
| 661 database->clear( | 667 connection->database()->Clear( |
| 662 parent_->HostTransactionId(transaction_id), object_store_id, callbacks); | 668 parent_->HostTransactionId(transaction_id), object_store_id, callbacks); |
| 663 } | 669 } |
| 664 | 670 |
| 665 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( | 671 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( |
| 666 int32 ipc_database_id, | 672 int32 ipc_database_id, |
| 667 int64 transaction_id) { | 673 int64 transaction_id) { |
| 668 DCHECK( | 674 DCHECK( |
| 669 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 675 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 670 WebIDBDatabaseImpl* database = | 676 IndexedDBConnection* connection = |
| 671 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 677 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 672 if (!database) | 678 if (!connection) |
| 673 return; | 679 return; |
| 674 | 680 |
| 675 database->abort(parent_->HostTransactionId(transaction_id)); | 681 connection->database()->Abort(parent_->HostTransactionId(transaction_id)); |
| 676 } | 682 } |
| 677 | 683 |
| 678 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( | 684 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( |
| 679 int32 ipc_database_id, | 685 int32 ipc_database_id, |
| 680 int64 transaction_id) { | 686 int64 transaction_id) { |
| 681 DCHECK( | 687 DCHECK( |
| 682 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 688 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 683 WebIDBDatabaseImpl* database = | 689 IndexedDBConnection* connection = |
| 684 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 690 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 685 if (!database) | 691 if (!connection) |
| 686 return; | 692 return; |
| 687 | 693 |
| 688 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); | 694 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); |
| 689 int64 transaction_size = transaction_size_map_[host_transaction_id]; | 695 int64 transaction_size = transaction_size_map_[host_transaction_id]; |
| 690 if (transaction_size && | 696 if (transaction_size && |
| 691 parent_->Context()->WouldBeOverQuota( | 697 parent_->Context()->WouldBeOverQuota( |
| 692 transaction_url_map_[host_transaction_id], transaction_size)) { | 698 transaction_url_map_[host_transaction_id], transaction_size)) { |
| 693 database->abort( | 699 connection->database()->Abort( |
| 694 host_transaction_id, | 700 host_transaction_id, |
| 695 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 701 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
| 696 return; | 702 return; |
| 697 } | 703 } |
| 698 | 704 |
| 699 database->commit(host_transaction_id); | 705 connection->database()->Commit(host_transaction_id); |
| 700 } | 706 } |
| 701 | 707 |
| 702 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( | 708 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( |
| 703 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { | 709 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { |
| 704 DCHECK( | 710 DCHECK( |
| 705 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 711 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 706 WebIDBDatabaseImpl* database = | 712 IndexedDBConnection* connection = |
| 707 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 713 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 708 if (!database) | 714 if (!connection) |
| 709 return; | 715 return; |
| 710 | 716 |
| 711 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); | 717 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); |
| 712 database->createIndex(host_transaction_id, | 718 connection->database()->CreateIndex(host_transaction_id, |
| 713 params.object_store_id, | 719 params.object_store_id, |
| 714 params.index_id, | 720 params.index_id, |
| 715 params.name, | 721 params.name, |
| 716 params.key_path, | 722 params.key_path, |
| 717 params.unique, | 723 params.unique, |
| 718 params.multi_entry); | 724 params.multi_entry); |
| 719 if (parent_->Context()->IsOverQuota( | 725 if (parent_->Context()->IsOverQuota( |
| 720 database_url_map_[params.ipc_database_id])) { | 726 database_url_map_[params.ipc_database_id])) { |
| 721 database->abort( | 727 connection->database()->Abort( |
| 722 host_transaction_id, | 728 host_transaction_id, |
| 723 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); | 729 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); |
| 724 } | 730 } |
| 725 } | 731 } |
| 726 | 732 |
| 727 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( | 733 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( |
| 728 int32 ipc_database_id, | 734 int32 ipc_database_id, |
| 729 int64 transaction_id, | 735 int64 transaction_id, |
| 730 int64 object_store_id, | 736 int64 object_store_id, |
| 731 int64 index_id) { | 737 int64 index_id) { |
| 732 DCHECK( | 738 DCHECK( |
| 733 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 739 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 734 WebIDBDatabaseImpl* database = | 740 IndexedDBConnection* connection = |
| 735 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 741 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 736 if (!database) | 742 if (!connection) |
| 737 return; | 743 return; |
| 738 | 744 |
| 739 database->deleteIndex( | 745 connection->database()->DeleteIndex( |
| 740 parent_->HostTransactionId(transaction_id), object_store_id, index_id); | 746 parent_->HostTransactionId(transaction_id), object_store_id, index_id); |
| 741 } | 747 } |
| 742 | 748 |
| 743 ////////////////////////////////////////////////////////////////////// | 749 ////////////////////////////////////////////////////////////////////// |
| 744 // IndexedDBDispatcherHost::CursorDispatcherHost | 750 // IndexedDBDispatcherHost::CursorDispatcherHost |
| 745 // | 751 // |
| 746 | 752 |
| 747 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( | 753 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( |
| 748 IndexedDBDispatcherHost* parent) | 754 IndexedDBDispatcherHost* parent) |
| 749 : parent_(parent) { | 755 : parent_(parent) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 } | 851 } |
| 846 | 852 |
| 847 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 853 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 848 int32 ipc_object_id) { | 854 int32 ipc_object_id) { |
| 849 DCHECK( | 855 DCHECK( |
| 850 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 856 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 851 parent_->DestroyObject(&map_, ipc_object_id); | 857 parent_->DestroyObject(&map_, ipc_object_id); |
| 852 } | 858 } |
| 853 | 859 |
| 854 } // namespace content | 860 } // namespace content |
| OLD | NEW |