Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 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/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/process/process.h" | 14 #include "base/process/process.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/indexed_db/indexed_db_callbacks.h" | 19 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 20 #include "content/browser/indexed_db/indexed_db_connection.h" | 20 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 21 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 21 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 22 #include "content/browser/indexed_db/indexed_db_cursor.h" | 22 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 23 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 23 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 24 #include "content/browser/indexed_db/indexed_db_observation.h" | 24 #include "content/browser/indexed_db/indexed_db_observation.h" |
| 25 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 25 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
| 26 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 26 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 27 #include "content/browser/indexed_db/indexed_db_transaction.h" | |
| 27 #include "content/browser/indexed_db/indexed_db_value.h" | 28 #include "content/browser/indexed_db/indexed_db_value.h" |
| 28 #include "content/browser/renderer_host/render_message_filter.h" | 29 #include "content/browser/renderer_host/render_message_filter.h" |
| 29 #include "content/common/indexed_db/indexed_db_messages.h" | 30 #include "content/common/indexed_db/indexed_db_messages.h" |
| 30 #include "content/common/indexed_db/indexed_db_metadata.h" | 31 #include "content/common/indexed_db/indexed_db_metadata.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 33 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/result_codes.h" | 35 #include "content/public/common/result_codes.h" |
| 35 #include "storage/browser/blob/blob_data_builder.h" | 36 #include "storage/browser/blob/blob_data_builder.h" |
| 36 #include "storage/browser/blob/blob_storage_context.h" | 37 #include "storage/browser/blob/blob_storage_context.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 if (!handled) { | 138 if (!handled) { |
| 138 handled = true; | 139 handled = true; |
| 139 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcherHost, message) | 140 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcherHost, message) |
| 140 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) | 141 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_AckReceivedBlobs, OnAckReceivedBlobs) |
| 141 IPC_MESSAGE_UNHANDLED(handled = false) | 142 IPC_MESSAGE_UNHANDLED(handled = false) |
| 142 IPC_END_MESSAGE_MAP() | 143 IPC_END_MESSAGE_MAP() |
| 143 } | 144 } |
| 144 return handled; | 145 return handled; |
| 145 } | 146 } |
| 146 | 147 |
| 147 int32_t IndexedDBDispatcherHost::Add(IndexedDBCursor* cursor) { | 148 int32_t IndexedDBDispatcherHost::Add(std::unique_ptr<IndexedDBCursor> cursor) { |
| 148 if (!cursor_dispatcher_host_) { | 149 if (!cursor_dispatcher_host_) { |
| 149 return 0; | 150 return 0; |
| 150 } | 151 } |
| 151 return cursor_dispatcher_host_->map_.Add(cursor); | 152 return cursor_dispatcher_host_->map_.Add(std::move(cursor)); |
| 152 } | 153 } |
| 153 | 154 |
| 154 int32_t IndexedDBDispatcherHost::Add(IndexedDBConnection* connection, | 155 int32_t IndexedDBDispatcherHost::Add( |
| 155 const url::Origin& origin) { | 156 std::unique_ptr<IndexedDBConnection> connection, |
| 157 const url::Origin& origin) { | |
| 156 if (!database_dispatcher_host_) { | 158 if (!database_dispatcher_host_) { |
| 157 connection->Close(); | 159 connection->Close(); |
| 158 delete connection; | |
| 159 return -1; | 160 return -1; |
| 160 } | 161 } |
| 161 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); | 162 IndexedDBConnection* connection_ptr = connection.get(); |
| 162 context()->ConnectionOpened(origin, connection); | 163 int32_t ipc_database_id = |
| 164 database_dispatcher_host_->map_.Add(std::move(connection)); | |
| 165 context()->ConnectionOpened(origin, connection_ptr); | |
| 163 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; | 166 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; |
| 164 return ipc_database_id; | 167 return ipc_database_id; |
| 165 } | 168 } |
| 166 | 169 |
| 167 void IndexedDBDispatcherHost::RegisterTransactionId(int64_t host_transaction_id, | |
| 168 const url::Origin& origin) { | |
| 169 if (!database_dispatcher_host_) | |
| 170 return; | |
| 171 database_dispatcher_host_->transaction_size_map_[host_transaction_id] = 0; | |
| 172 database_dispatcher_host_->transaction_origin_map_[host_transaction_id] = | |
| 173 origin; | |
| 174 } | |
| 175 | |
| 176 int64_t IndexedDBDispatcherHost::HostTransactionId(int64_t transaction_id) { | |
| 177 // Inject the renderer process id into the transaction id, to | |
| 178 // uniquely identify this transaction, and effectively bind it to | |
| 179 // the renderer that initiated it. The lower 32 bits of | |
| 180 // transaction_id are guaranteed to be unique within that renderer. | |
| 181 base::ProcessId pid = peer_pid(); | |
| 182 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; | |
| 183 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t), | |
| 184 "Process ID must fit in 32 bits"); | |
| 185 | |
| 186 return transaction_id | (static_cast<uint64_t>(pid) << 32); | |
| 187 } | |
| 188 | |
| 189 int64_t IndexedDBDispatcherHost::RendererTransactionId( | |
| 190 int64_t host_transaction_id) { | |
| 191 DCHECK(host_transaction_id >> 32 == peer_pid()) | |
| 192 << "Invalid renderer target for transaction id"; | |
| 193 return host_transaction_id & 0xffffffff; | |
| 194 } | |
| 195 | |
| 196 // static | |
| 197 uint32_t IndexedDBDispatcherHost::TransactionIdToRendererTransactionId( | |
| 198 int64_t host_transaction_id) { | |
| 199 return host_transaction_id & 0xffffffff; | |
| 200 } | |
| 201 | |
| 202 // static | |
| 203 uint32_t IndexedDBDispatcherHost::TransactionIdToProcessId( | |
| 204 int64_t host_transaction_id) { | |
| 205 return (host_transaction_id >> 32) & 0xffffffff; | |
| 206 } | |
| 207 | |
| 208 std::string IndexedDBDispatcherHost::HoldBlobData( | 170 std::string IndexedDBDispatcherHost::HoldBlobData( |
| 209 const IndexedDBBlobInfo& blob_info) { | 171 const IndexedDBBlobInfo& blob_info) { |
| 210 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 172 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 211 std::string uuid = blob_info.uuid(); | 173 std::string uuid = blob_info.uuid(); |
| 212 storage::BlobStorageContext* context = blob_storage_context_->context(); | 174 storage::BlobStorageContext* context = blob_storage_context_->context(); |
| 213 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; | 175 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; |
| 214 if (uuid.empty()) { | 176 if (uuid.empty()) { |
| 215 uuid = base::GenerateGUID(); | 177 uuid = base::GenerateGUID(); |
| 216 storage::BlobDataBuilder blob_data_builder(uuid); | 178 storage::BlobDataBuilder blob_data_builder(uuid); |
| 217 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); | 179 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, | 318 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, |
| 357 const url::Origin& origin, | 319 const url::Origin& origin, |
| 358 const base::string16& name, | 320 const base::string16& name, |
| 359 int64_t version, | 321 int64_t version, |
| 360 int64_t transaction_id) { | 322 int64_t transaction_id) { |
| 361 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 323 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 362 | 324 |
| 363 base::TimeTicks begin_time = base::TimeTicks::Now(); | 325 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 364 base::FilePath indexed_db_path = indexed_db_context_->data_path(); | 326 base::FilePath indexed_db_path = indexed_db_context_->data_path(); |
| 365 | 327 |
| 366 int64_t host_transaction_id = HostTransactionId(transaction_id); | |
| 367 | |
| 368 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 328 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 369 // created) if this origin is already over quota. | 329 // created) if this origin is already over quota. |
| 370 callbacks->SetConnectionOpenStartTime(begin_time); | 330 callbacks->SetConnectionOpenStartTime(begin_time); |
| 371 callbacks->set_host_transaction_id(host_transaction_id); | 331 callbacks->set_host_transaction_id(transaction_id); |
| 372 std::unique_ptr<IndexedDBPendingConnection> connection = | 332 std::unique_ptr<IndexedDBPendingConnection> connection = |
| 373 base::MakeUnique<IndexedDBPendingConnection>( | 333 base::MakeUnique<IndexedDBPendingConnection>( |
| 374 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, | 334 callbacks, database_callbacks, ipc_process_id_, origin, |
| 375 version); | 335 transaction_id, version); |
| 376 DCHECK(request_context_getter_); | 336 DCHECK(request_context_getter_); |
| 377 context()->GetIDBFactory()->Open(name, std::move(connection), | 337 context()->GetIDBFactory()->Open(name, std::move(connection), |
| 378 request_context_getter_, origin, | 338 request_context_getter_, origin, |
| 379 indexed_db_path); | 339 indexed_db_path); |
| 380 } | 340 } |
| 381 | 341 |
| 382 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( | 342 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( |
| 383 scoped_refptr<IndexedDBCallbacks> callbacks, | 343 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 384 const url::Origin& origin, | 344 const url::Origin& origin, |
| 385 const base::string16& name) { | 345 const base::string16& name) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 399 database_dispatcher_host_->OnPut(params, std::move(handles)); | 359 database_dispatcher_host_->OnPut(params, std::move(handles)); |
| 400 } | 360 } |
| 401 | 361 |
| 402 void IndexedDBDispatcherHost::OnAckReceivedBlobs( | 362 void IndexedDBDispatcherHost::OnAckReceivedBlobs( |
| 403 const std::vector<std::string>& uuids) { | 363 const std::vector<std::string>& uuids) { |
| 404 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 364 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 405 for (const auto& uuid : uuids) | 365 for (const auto& uuid : uuids) |
| 406 DropBlobData(uuid); | 366 DropBlobData(uuid); |
| 407 } | 367 } |
| 408 | 368 |
| 409 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, | 369 void IndexedDBDispatcherHost::FinishTransaction( |
|
jsbell
2016/11/08 00:42:52
The only purpose of this method now is to poke the
dmurph
2016/11/09 00:27:32
Done.
| |
| 410 bool committed) { | 370 const url::Origin& transaction_origin, |
| 371 bool committed) { | |
| 411 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 372 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 412 if (!database_dispatcher_host_) | 373 if (!database_dispatcher_host_) |
| 413 return; | 374 return; |
| 414 TransactionIDToOriginMap& transaction_origin_map = | |
| 415 database_dispatcher_host_->transaction_origin_map_; | |
| 416 TransactionIDToSizeMap& transaction_size_map = | |
| 417 database_dispatcher_host_->transaction_size_map_; | |
| 418 TransactionIDToDatabaseIDMap& transaction_database_map = | |
| 419 database_dispatcher_host_->transaction_database_map_; | |
| 420 if (committed) | 375 if (committed) |
| 421 context()->TransactionComplete(transaction_origin_map[host_transaction_id]); | 376 context()->TransactionComplete(transaction_origin); |
| 422 transaction_origin_map.erase(host_transaction_id); | |
| 423 transaction_size_map.erase(host_transaction_id); | |
| 424 transaction_database_map.erase(host_transaction_id); | |
| 425 } | 377 } |
| 426 | 378 |
| 427 ////////////////////////////////////////////////////////////////////// | 379 ////////////////////////////////////////////////////////////////////// |
| 428 // Helper templates. | 380 // Helper templates. |
| 429 // | 381 // |
| 430 | 382 |
| 431 template <typename ObjectType> | 383 template <typename ObjectType> |
| 432 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | 384 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( |
| 433 IDMap<ObjectType, IDMapOwnPointer>* map, | 385 IDMap<ObjectType, IDMapOwnPointer>* map, |
| 434 int32_t ipc_return_object_id) { | 386 int32_t ipc_return_object_id) { |
| 435 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | 387 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); |
| 436 ObjectType* return_object = map->Lookup(ipc_return_object_id); | 388 ObjectType* return_object = map->Lookup(ipc_return_object_id); |
| 437 if (!return_object) { | 389 if (!return_object) { |
| 438 NOTREACHED() << "Uh oh, couldn't find object with id " | 390 NOTREACHED() << "Uh oh, couldn't find object with id " |
| 439 << ipc_return_object_id; | 391 << ipc_return_object_id; |
| 440 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); | 392 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); |
| 441 } | 393 } |
| 442 return return_object; | 394 return return_object; |
| 443 } | 395 } |
| 444 | 396 |
| 445 template <typename ObjectType> | |
| 446 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( | |
| 447 RefIDMap<ObjectType>* map, | |
| 448 int32_t ipc_return_object_id) { | |
| 449 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); | |
| 450 ObjectType* return_object = map->Lookup(ipc_return_object_id); | |
| 451 if (!return_object) { | |
| 452 NOTREACHED() << "Uh oh, couldn't find object with id " | |
| 453 << ipc_return_object_id; | |
| 454 bad_message::ReceivedBadMessage(this, bad_message::IDBDH_GET_OR_TERMINATE); | |
| 455 } | |
| 456 return return_object; | |
| 457 } | |
| 458 | |
| 459 template <typename MapType> | 397 template <typename MapType> |
| 460 void IndexedDBDispatcherHost::DestroyObject(MapType* map, | 398 void IndexedDBDispatcherHost::DestroyObject(MapType* map, |
| 461 int32_t ipc_object_id) { | 399 int32_t ipc_object_id) { |
| 462 GetOrTerminateProcess(map, ipc_object_id); | 400 GetOrTerminateProcess(map, ipc_object_id); |
| 463 map->Remove(ipc_object_id); | 401 map->Remove(ipc_object_id); |
| 464 } | 402 } |
| 465 | 403 |
| 466 ////////////////////////////////////////////////////////////////////// | 404 ////////////////////////////////////////////////////////////////////// |
| 467 // IndexedDBDispatcherHost::DatabaseDispatcherHost | 405 // IndexedDBDispatcherHost::DatabaseDispatcherHost |
| 468 // | 406 // |
| 469 | 407 |
| 470 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( | 408 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( |
| 471 IndexedDBDispatcherHost* parent) | 409 IndexedDBDispatcherHost* parent) |
| 472 : parent_(parent), weak_factory_(this) { | 410 : parent_(parent), weak_factory_(this) { |
| 473 map_.set_check_on_null_data(true); | 411 map_.set_check_on_null_data(true); |
| 474 } | 412 } |
| 475 | 413 |
| 476 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { | 414 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { |
| 477 // TODO(alecflett): uncomment these when we find the source of these leaks. | 415 // TODO(alecflett): uncomment these when we find the source of these leaks. |
| 478 // DCHECK(transaction_size_map_.empty()); | 416 // DCHECK(transaction_size_map_.empty()); |
| 479 // DCHECK(transaction_origin_map_.empty()); | 417 // DCHECK(transaction_origin_map_.empty()); |
| 480 } | 418 } |
| 481 | 419 |
| 482 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { | 420 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { |
| 483 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 421 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 484 // Abort outstanding transactions started by connections in the associated | 422 // Abort outstanding transactions started by connections in the associated |
| 485 // front-end to unblock later transactions. This should only occur on unclean | 423 // front-end to unblock later transactions. This should only occur on unclean |
| 486 // (crash) or abrupt (process-kill) shutdowns. | 424 // (crash) or abrupt (process-kill) shutdowns. |
| 487 for (TransactionIDToDatabaseIDMap::iterator iter = | 425 IDMap<IndexedDBConnection, IDMapOwnPointer>::iterator iterator(&map_); |
| 488 transaction_database_map_.begin(); | 426 while (!iterator.IsAtEnd()) { |
| 489 iter != transaction_database_map_.end();) { | 427 IndexedDBConnection* connection = iterator.GetCurrentValue(); |
| 490 int64_t transaction_id = iter->first; | |
| 491 int32_t ipc_database_id = iter->second; | |
| 492 ++iter; | |
| 493 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); | |
| 494 if (connection && connection->IsConnected()) { | 428 if (connection && connection->IsConnected()) { |
| 495 connection->database()->Abort( | 429 // TODO(dmurph): Perhaps mark these transactions as DOOMED instead, so we |
| 496 transaction_id, | 430 // can prevent side effects in the rest of the system. |
| 431 connection->AbortAllTransactions( | |
| 497 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError)); | 432 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError)); |
| 498 } | 433 } |
| 434 iterator.Advance(); | |
| 499 } | 435 } |
| 500 DCHECK(transaction_database_map_.empty()); | |
| 501 | 436 |
| 502 for (const auto& iter : database_origin_map_) { | 437 for (const auto& iter : database_origin_map_) { |
| 503 IndexedDBConnection* connection = map_.Lookup(iter.first); | 438 IndexedDBConnection* connection = map_.Lookup(iter.first); |
| 504 if (connection && connection->IsConnected()) { | 439 if (connection && connection->IsConnected()) { |
| 505 connection->Close(); | 440 connection->Close(); |
| 506 parent_->context()->ConnectionClosed(iter.second, connection); | 441 parent_->context()->ConnectionClosed(iter.second, connection); |
| 507 } | 442 } |
| 508 } | 443 } |
| 509 } | 444 } |
| 510 | 445 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 return handled; | 487 return handled; |
| 553 } | 488 } |
| 554 | 489 |
| 555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( | 490 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( |
| 556 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { | 491 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { |
| 557 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 492 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 558 IndexedDBConnection* connection = | 493 IndexedDBConnection* connection = |
| 559 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 494 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 560 if (!connection || !connection->IsConnected()) | 495 if (!connection || !connection->IsConnected()) |
| 561 return; | 496 return; |
| 497 IndexedDBTransaction* transaction = | |
| 498 connection->GetTransaction(params.transaction_id); | |
| 499 if (!transaction) | |
| 500 return; | |
| 562 | 501 |
| 563 int64_t host_transaction_id = | 502 connection->database()->CreateObjectStore(transaction, params.object_store_id, |
| 564 parent_->HostTransactionId(params.transaction_id); | 503 params.name, params.key_path, |
| 565 connection->database()->CreateObjectStore(host_transaction_id, | |
| 566 params.object_store_id, | |
| 567 params.name, | |
| 568 params.key_path, | |
| 569 params.auto_increment); | 504 params.auto_increment); |
| 570 } | 505 } |
| 571 | 506 |
| 572 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( | 507 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( |
| 573 int32_t ipc_database_id, | 508 int32_t ipc_database_id, |
| 574 int64_t transaction_id, | 509 int64_t transaction_id, |
| 575 int64_t object_store_id) { | 510 int64_t object_store_id) { |
| 576 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 511 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 577 IndexedDBConnection* connection = | 512 IndexedDBConnection* connection = |
| 578 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 513 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 579 if (!connection || !connection->IsConnected()) | 514 if (!connection || !connection->IsConnected()) |
| 580 return; | 515 return; |
| 516 IndexedDBTransaction* transaction = | |
| 517 connection->GetTransaction(transaction_id); | |
| 518 if (!transaction) | |
| 519 return; | |
| 581 | 520 |
| 582 connection->database()->DeleteObjectStore( | 521 connection->database()->DeleteObjectStore(transaction, object_store_id); |
| 583 parent_->HostTransactionId(transaction_id), object_store_id); | |
| 584 } | 522 } |
| 585 | 523 |
| 586 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameObjectStore( | 524 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameObjectStore( |
| 587 int32_t ipc_database_id, | 525 int32_t ipc_database_id, |
| 588 int64_t transaction_id, | 526 int64_t transaction_id, |
| 589 int64_t object_store_id, | 527 int64_t object_store_id, |
| 590 const base::string16& new_name) { | 528 const base::string16& new_name) { |
| 591 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 529 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 592 IndexedDBConnection* connection = | 530 IndexedDBConnection* connection = |
| 593 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 531 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 594 if (!connection || !connection->IsConnected()) | 532 if (!connection || !connection->IsConnected()) |
| 595 return; | 533 return; |
| 534 IndexedDBTransaction* transaction = | |
| 535 connection->GetTransaction(transaction_id); | |
| 536 if (!transaction) | |
| 537 return; | |
| 596 | 538 |
| 597 connection->database()->RenameObjectStore( | 539 connection->database()->RenameObjectStore(transaction, object_store_id, |
| 598 parent_->HostTransactionId(transaction_id), object_store_id, new_name); | 540 new_name); |
| 599 } | 541 } |
| 600 | 542 |
| 601 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( | 543 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( |
| 602 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { | 544 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { |
| 603 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 545 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 604 IndexedDBConnection* connection = | 546 IndexedDBConnection* connection = |
| 605 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 547 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 606 if (!connection || !connection->IsConnected()) | 548 if (!connection || !connection->IsConnected()) |
| 607 return; | 549 return; |
| 608 | 550 |
| 609 int64_t host_transaction_id = | 551 if (connection->GetTransaction(params.transaction_id)) { |
| 610 parent_->HostTransactionId(params.transaction_id); | |
| 611 | |
| 612 if (base::ContainsKey(transaction_database_map_, host_transaction_id)) { | |
| 613 DLOG(ERROR) << "Duplicate host_transaction_id."; | 552 DLOG(ERROR) << "Duplicate host_transaction_id."; |
| 614 return; | 553 return; |
| 615 } | 554 } |
| 616 | 555 |
| 617 connection->database()->CreateTransaction( | 556 connection->database()->CreateTransaction( |
| 618 host_transaction_id, connection, params.object_store_ids, params.mode); | 557 params.transaction_id, connection, params.object_store_ids, params.mode); |
| 619 transaction_database_map_[host_transaction_id] = params.ipc_database_id; | |
| 620 parent_->RegisterTransactionId(host_transaction_id, | |
| 621 database_origin_map_[params.ipc_database_id]); | |
| 622 } | 558 } |
| 623 | 559 |
| 624 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( | 560 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( |
| 625 int32_t ipc_database_id) { | 561 int32_t ipc_database_id) { |
| 626 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 562 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 627 IndexedDBConnection* connection = | 563 IndexedDBConnection* connection = |
| 628 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 564 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 629 if (!connection || !connection->IsConnected()) | 565 if (!connection || !connection->IsConnected()) |
| 630 return; | 566 return; |
| 631 connection->Close(); | 567 connection->Close(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 656 parent_->DestroyObject(&map_, ipc_object_id); | 592 parent_->DestroyObject(&map_, ipc_object_id); |
| 657 } | 593 } |
| 658 | 594 |
| 659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( | 595 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( |
| 660 const IndexedDBHostMsg_DatabaseObserve_Params& params) { | 596 const IndexedDBHostMsg_DatabaseObserve_Params& params) { |
| 661 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 597 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 662 IndexedDBConnection* connection = | 598 IndexedDBConnection* connection = |
| 663 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 599 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 664 if (!connection || !connection->IsConnected()) | 600 if (!connection || !connection->IsConnected()) |
| 665 return; | 601 return; |
| 602 IndexedDBTransaction* transaction = | |
| 603 connection->GetTransaction(params.transaction_id); | |
| 604 if (!transaction) | |
| 605 return; | |
| 666 IndexedDBObserver::Options options(params.include_transaction, | 606 IndexedDBObserver::Options options(params.include_transaction, |
| 667 params.no_records, params.values, | 607 params.no_records, params.values, |
| 668 params.operation_types); | 608 params.operation_types); |
| 669 connection->database()->AddPendingObserver( | 609 connection->database()->AddPendingObserver(transaction, params.observer_id, |
| 670 parent_->HostTransactionId(params.transaction_id), params.observer_id, | 610 options); |
| 671 options); | |
| 672 } | 611 } |
| 673 | 612 |
| 674 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve( | 613 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve( |
| 675 int32_t ipc_database_id, | 614 int32_t ipc_database_id, |
| 676 const std::vector<int32_t>& observer_ids_to_remove) { | 615 const std::vector<int32_t>& observer_ids_to_remove) { |
| 677 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 616 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 678 DCHECK(!observer_ids_to_remove.empty()); | 617 DCHECK(!observer_ids_to_remove.empty()); |
| 679 IndexedDBConnection* connection = | 618 IndexedDBConnection* connection = |
| 680 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 619 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 681 if (!connection || !connection->IsConnected()) | 620 if (!connection || !connection->IsConnected()) |
| 682 return; | 621 return; |
| 683 connection->RemoveObservers(observer_ids_to_remove); | 622 connection->RemoveObservers(observer_ids_to_remove); |
| 684 } | 623 } |
| 685 | 624 |
| 686 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( | 625 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( |
| 687 const IndexedDBHostMsg_DatabaseGet_Params& params) { | 626 const IndexedDBHostMsg_DatabaseGet_Params& params) { |
| 688 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 627 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 689 IndexedDBConnection* connection = | 628 IndexedDBConnection* connection = |
| 690 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 629 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 691 if (!connection || !connection->IsConnected()) | 630 if (!connection || !connection->IsConnected()) |
| 692 return; | 631 return; |
| 632 IndexedDBTransaction* transaction = | |
| 633 connection->GetTransaction(params.transaction_id); | |
| 634 if (!transaction) | |
| 635 return; | |
| 693 | 636 |
| 694 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 637 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 695 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 638 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 696 connection->database()->Get( | 639 connection->database()->Get( |
| 697 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | 640 transaction, params.object_store_id, params.index_id, |
| 698 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | 641 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.key_only, |
| 699 params.key_only, callbacks); | 642 callbacks); |
| 700 } | 643 } |
| 701 | 644 |
| 702 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGetAll( | 645 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGetAll( |
| 703 const IndexedDBHostMsg_DatabaseGetAll_Params& params) { | 646 const IndexedDBHostMsg_DatabaseGetAll_Params& params) { |
| 704 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 647 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 705 IndexedDBConnection* connection = | 648 IndexedDBConnection* connection = |
| 706 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 649 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 707 if (!connection || !connection->IsConnected()) | 650 if (!connection || !connection->IsConnected()) |
| 708 return; | 651 return; |
| 652 IndexedDBTransaction* transaction = | |
| 653 connection->GetTransaction(params.transaction_id); | |
| 654 if (!transaction) | |
| 655 return; | |
| 709 | 656 |
| 710 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 657 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 711 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 658 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 712 connection->database()->GetAll( | 659 connection->database()->GetAll( |
| 713 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | 660 transaction, params.object_store_id, params.index_id, |
| 714 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | 661 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.key_only, |
| 715 params.key_only, params.max_count, callbacks); | 662 params.max_count, callbacks); |
| 716 } | 663 } |
| 717 | 664 |
| 718 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( | 665 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( |
| 719 const IndexedDBHostMsg_DatabasePut_Params& params) { | 666 const IndexedDBHostMsg_DatabasePut_Params& params) { |
| 720 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | 667 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; |
| 721 for (const auto& info : params.value.blob_or_file_info) { | 668 for (const auto& info : params.value.blob_or_file_info) { |
| 722 handles.push_back( | 669 handles.push_back( |
| 723 parent_->blob_storage_context_->context()->GetBlobDataFromUUID( | 670 parent_->blob_storage_context_->context()->GetBlobDataFromUUID( |
| 724 info.uuid)); | 671 info.uuid)); |
| 725 } | 672 } |
| 726 parent_->context()->TaskRunner()->PostTask( | 673 parent_->context()->TaskRunner()->PostTask( |
| 727 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, | 674 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, |
| 728 params, base::Passed(&handles))); | 675 params, base::Passed(&handles))); |
| 729 } | 676 } |
| 730 | 677 |
| 731 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( | 678 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( |
| 732 const IndexedDBHostMsg_DatabasePut_Params& params, | 679 const IndexedDBHostMsg_DatabasePut_Params& params, |
| 733 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) { | 680 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) { |
| 734 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 681 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 735 | 682 |
| 736 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles; | 683 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles; |
| 737 scoped_handles.swap(handles); | 684 scoped_handles.swap(handles); |
| 738 | 685 |
| 739 IndexedDBConnection* connection = | 686 IndexedDBConnection* connection = |
| 740 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 687 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 741 if (!connection || !connection->IsConnected()) | 688 if (!connection || !connection->IsConnected()) |
| 742 return; | 689 return; |
| 690 IndexedDBTransaction* transaction = | |
| 691 connection->GetTransaction(params.transaction_id); | |
| 692 if (!transaction) | |
| 693 return; | |
| 743 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 694 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 744 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 695 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 745 | 696 |
| 746 int64_t host_transaction_id = | |
| 747 parent_->HostTransactionId(params.transaction_id); | |
| 748 | |
| 749 std::vector<IndexedDBBlobInfo> blob_info( | 697 std::vector<IndexedDBBlobInfo> blob_info( |
| 750 params.value.blob_or_file_info.size()); | 698 params.value.blob_or_file_info.size()); |
| 751 | 699 |
| 752 ChildProcessSecurityPolicyImpl* policy = | 700 ChildProcessSecurityPolicyImpl* policy = |
| 753 ChildProcessSecurityPolicyImpl::GetInstance(); | 701 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 754 | 702 |
| 755 size_t i = 0; | 703 size_t i = 0; |
| 756 for (const auto& info : params.value.blob_or_file_info) { | 704 for (const auto& info : params.value.blob_or_file_info) { |
| 757 if (info.is_file) { | 705 if (info.is_file) { |
| 758 base::FilePath path; | 706 base::FilePath path; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 774 } else { | 722 } else { |
| 775 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); | 723 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); |
| 776 } | 724 } |
| 777 ++i; | 725 ++i; |
| 778 } | 726 } |
| 779 | 727 |
| 780 // TODO(alecflett): Avoid a copy here. | 728 // TODO(alecflett): Avoid a copy here. |
| 781 IndexedDBValue value; | 729 IndexedDBValue value; |
| 782 value.bits = params.value.bits; | 730 value.bits = params.value.bits; |
| 783 value.blob_info.swap(blob_info); | 731 value.blob_info.swap(blob_info); |
| 784 connection->database()->Put(host_transaction_id, params.object_store_id, | 732 connection->database()->Put(transaction, params.object_store_id, &value, |
| 785 &value, &scoped_handles, | 733 &scoped_handles, |
| 786 base::MakeUnique<IndexedDBKey>(params.key), | 734 base::MakeUnique<IndexedDBKey>(params.key), |
| 787 params.put_mode, callbacks, params.index_keys); | 735 params.put_mode, callbacks, params.index_keys); |
| 788 // Size can't be big enough to overflow because it represents the | 736 // Size can't be big enough to overflow because it represents the |
| 789 // actual bytes passed through IPC. | 737 // actual bytes passed through IPC. |
| 790 transaction_size_map_[host_transaction_id] += params.value.bits.size(); | 738 transaction->set_size(transaction->size() + params.value.bits.size()); |
| 791 } | 739 } |
| 792 | 740 |
| 793 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( | 741 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( |
| 794 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { | 742 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { |
| 795 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 743 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 796 IndexedDBConnection* connection = | 744 IndexedDBConnection* connection = |
| 797 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 745 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 798 if (!connection || !connection->IsConnected()) | 746 if (!connection || !connection->IsConnected()) |
| 799 return; | 747 return; |
| 748 IndexedDBTransaction* transaction = | |
| 749 connection->GetTransaction(params.transaction_id); | |
| 750 if (!transaction) | |
| 751 return; | |
| 800 | 752 |
| 801 int64_t host_transaction_id = | |
| 802 parent_->HostTransactionId(params.transaction_id); | |
| 803 connection->database()->SetIndexKeys( | 753 connection->database()->SetIndexKeys( |
| 804 host_transaction_id, params.object_store_id, | 754 transaction, params.object_store_id, |
| 805 base::MakeUnique<IndexedDBKey>(params.primary_key), params.index_keys); | 755 base::MakeUnique<IndexedDBKey>(params.primary_key), params.index_keys); |
| 806 } | 756 } |
| 807 | 757 |
| 808 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( | 758 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( |
| 809 int32_t ipc_database_id, | 759 int32_t ipc_database_id, |
| 810 int64_t transaction_id, | 760 int64_t transaction_id, |
| 811 int64_t object_store_id, | 761 int64_t object_store_id, |
| 812 const std::vector<int64_t>& index_ids) { | 762 const std::vector<int64_t>& index_ids) { |
| 813 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 763 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 814 IndexedDBConnection* connection = | 764 IndexedDBConnection* connection = |
| 815 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 765 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 816 if (!connection || !connection->IsConnected()) | 766 if (!connection || !connection->IsConnected()) |
| 817 return; | 767 return; |
| 768 IndexedDBTransaction* transaction = | |
| 769 connection->GetTransaction(transaction_id); | |
| 770 if (!transaction) | |
| 771 return; | |
| 818 | 772 |
| 819 connection->database()->SetIndexesReady( | 773 connection->database()->SetIndexesReady(transaction, object_store_id, |
| 820 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); | 774 index_ids); |
| 821 } | 775 } |
| 822 | 776 |
| 823 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( | 777 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( |
| 824 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { | 778 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { |
| 825 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 779 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 826 IndexedDBConnection* connection = | 780 IndexedDBConnection* connection = |
| 827 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 781 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 828 if (!connection || !connection->IsConnected()) | 782 if (!connection || !connection->IsConnected()) |
| 829 return; | 783 return; |
| 784 IndexedDBTransaction* transaction = | |
| 785 connection->GetTransaction(params.transaction_id); | |
| 786 if (!transaction) | |
| 787 return; | |
| 830 | 788 |
| 831 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 789 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 832 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); | 790 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); |
| 833 connection->database()->OpenCursor( | 791 connection->database()->OpenCursor( |
| 834 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | 792 transaction, params.object_store_id, params.index_id, |
| 835 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | 793 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.direction, |
| 836 params.direction, params.key_only, params.task_type, callbacks); | 794 params.key_only, params.task_type, callbacks); |
| 837 } | 795 } |
| 838 | 796 |
| 839 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( | 797 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( |
| 840 const IndexedDBHostMsg_DatabaseCount_Params& params) { | 798 const IndexedDBHostMsg_DatabaseCount_Params& params) { |
| 841 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 799 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 842 IndexedDBConnection* connection = | 800 IndexedDBConnection* connection = |
| 843 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 801 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 844 if (!connection || !connection->IsConnected()) | 802 if (!connection || !connection->IsConnected()) |
| 845 return; | 803 return; |
| 804 IndexedDBTransaction* transaction = | |
| 805 connection->GetTransaction(params.transaction_id); | |
| 806 if (!transaction) | |
| 807 return; | |
| 846 | 808 |
| 847 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 809 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 848 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 810 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 849 connection->database()->Count( | 811 connection->database()->Count( |
| 850 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | 812 transaction, params.object_store_id, params.index_id, |
| 851 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), | 813 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks); |
| 852 callbacks); | |
| 853 } | 814 } |
| 854 | 815 |
| 855 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( | 816 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( |
| 856 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { | 817 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { |
| 857 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 818 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 858 IndexedDBConnection* connection = | 819 IndexedDBConnection* connection = |
| 859 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 820 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 860 if (!connection || !connection->IsConnected()) | 821 if (!connection || !connection->IsConnected()) |
| 861 return; | 822 return; |
| 823 IndexedDBTransaction* transaction = | |
| 824 connection->GetTransaction(params.transaction_id); | |
| 825 if (!transaction) | |
| 826 return; | |
| 862 | 827 |
| 863 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 828 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 864 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); | 829 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); |
| 865 connection->database()->DeleteRange( | 830 connection->database()->DeleteRange( |
| 866 parent_->HostTransactionId(params.transaction_id), params.object_store_id, | 831 transaction, params.object_store_id, |
| 867 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks); | 832 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks); |
| 868 } | 833 } |
| 869 | 834 |
| 870 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( | 835 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( |
| 871 int32_t ipc_thread_id, | 836 int32_t ipc_thread_id, |
| 872 int32_t ipc_callbacks_id, | 837 int32_t ipc_callbacks_id, |
| 873 int32_t ipc_database_id, | 838 int32_t ipc_database_id, |
| 874 int64_t transaction_id, | 839 int64_t transaction_id, |
| 875 int64_t object_store_id) { | 840 int64_t object_store_id) { |
| 876 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 841 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 877 IndexedDBConnection* connection = | 842 IndexedDBConnection* connection = |
| 878 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 843 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 879 if (!connection || !connection->IsConnected()) | 844 if (!connection || !connection->IsConnected()) |
| 880 return; | 845 return; |
| 846 IndexedDBTransaction* transaction = | |
| 847 connection->GetTransaction(transaction_id); | |
| 848 if (!transaction) | |
| 849 return; | |
| 881 | 850 |
| 882 scoped_refptr<IndexedDBCallbacks> callbacks( | 851 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 883 new IndexedDBCallbacks(parent_, ipc_thread_id, ipc_callbacks_id)); | 852 new IndexedDBCallbacks(parent_, ipc_thread_id, ipc_callbacks_id)); |
| 884 | 853 |
| 885 connection->database()->Clear( | 854 connection->database()->Clear(transaction, object_store_id, callbacks); |
| 886 parent_->HostTransactionId(transaction_id), object_store_id, callbacks); | |
| 887 } | 855 } |
| 888 | 856 |
| 889 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( | 857 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( |
| 890 int32_t ipc_database_id, | 858 int32_t ipc_database_id, |
| 891 int64_t transaction_id) { | 859 int64_t transaction_id) { |
| 892 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 860 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 893 IndexedDBConnection* connection = | 861 IndexedDBConnection* connection = |
| 894 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 862 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 895 if (!connection || !connection->IsConnected()) | 863 if (!connection || !connection->IsConnected()) |
| 896 return; | 864 return; |
| 865 IndexedDBTransaction* transaction = | |
| 866 connection->GetTransaction(transaction_id); | |
| 867 if (!transaction) | |
| 868 return; | |
| 897 | 869 |
| 898 connection->database()->Abort(parent_->HostTransactionId(transaction_id)); | 870 connection->AbortTransaction(transaction); |
| 899 } | 871 } |
| 900 | 872 |
| 901 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( | 873 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( |
| 902 int32_t ipc_database_id, | 874 int32_t ipc_database_id, |
| 903 int64_t transaction_id) { | 875 int64_t transaction_id) { |
| 904 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 876 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 905 IndexedDBConnection* connection = | 877 IndexedDBConnection* connection = |
| 906 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 878 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 907 if (!connection || !connection->IsConnected()) | 879 if (!connection || !connection->IsConnected()) |
| 908 return; | 880 return; |
| 881 IndexedDBTransaction* transaction = | |
| 882 connection->GetTransaction(transaction_id); | |
| 883 if (!transaction) | |
| 884 return; | |
| 909 | 885 |
| 910 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); | 886 int64_t transaction_size = transaction->size(); |
| 911 // May have been aborted by back end before front-end could request commit. | |
| 912 if (!base::ContainsKey(transaction_size_map_, host_transaction_id)) | |
| 913 return; | |
| 914 int64_t transaction_size = transaction_size_map_[host_transaction_id]; | |
| 915 | 887 |
| 916 // Always allow empty or delete-only transactions. | 888 // Always allow empty or delete-only transactions. |
| 917 if (!transaction_size) { | 889 if (!transaction_size) { |
| 918 connection->database()->Commit(host_transaction_id); | 890 connection->database()->Commit(transaction); |
| 919 return; | 891 return; |
| 920 } | 892 } |
| 921 | 893 |
| 922 parent_->context()->quota_manager_proxy()->GetUsageAndQuota( | 894 parent_->context()->quota_manager_proxy()->GetUsageAndQuota( |
| 923 parent_->context()->TaskRunner(), | 895 parent_->context()->TaskRunner(), GURL(connection->origin().Serialize()), |
|
jsbell
2016/11/08 00:42:52
This can be replaced by connection->origin().GetUR
| |
| 924 GURL(transaction_origin_map_[host_transaction_id].Serialize()), | |
| 925 storage::kStorageTypeTemporary, | 896 storage::kStorageTypeTemporary, |
| 926 base::Bind(&IndexedDBDispatcherHost::DatabaseDispatcherHost:: | 897 base::Bind(&IndexedDBDispatcherHost::DatabaseDispatcherHost:: |
| 927 OnGotUsageAndQuotaForCommit, | 898 OnGotUsageAndQuotaForCommit, |
| 928 weak_factory_.GetWeakPtr(), ipc_database_id, transaction_id)); | 899 weak_factory_.GetWeakPtr(), ipc_database_id, transaction_id)); |
| 929 } | 900 } |
| 930 | 901 |
| 931 void IndexedDBDispatcherHost::DatabaseDispatcherHost:: | 902 void IndexedDBDispatcherHost::DatabaseDispatcherHost:: |
| 932 OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, | 903 OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, |
| 933 int64_t transaction_id, | 904 int64_t transaction_id, |
| 934 storage::QuotaStatusCode status, | 905 storage::QuotaStatusCode status, |
| 935 int64_t usage, | 906 int64_t usage, |
| 936 int64_t quota) { | 907 int64_t quota) { |
| 937 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 908 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 938 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); | 909 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); |
| 939 // May have disconnected while quota check was pending. | 910 // May have disconnected while quota check was pending. |
| 940 if (!connection || !connection->IsConnected()) | 911 if (!connection || !connection->IsConnected()) |
| 941 return; | 912 return; |
| 942 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); | 913 IndexedDBTransaction* transaction = |
| 943 // May have aborted while quota check was pending. | 914 connection->GetTransaction(transaction_id); |
| 944 if (!base::ContainsKey(transaction_size_map_, host_transaction_id)) | 915 if (!transaction) |
| 945 return; | 916 return; |
| 946 int64_t transaction_size = transaction_size_map_[host_transaction_id]; | 917 |
| 918 int64_t transaction_size = transaction->size(); | |
| 947 | 919 |
| 948 if (status == storage::kQuotaStatusOk && | 920 if (status == storage::kQuotaStatusOk && |
| 949 usage + transaction_size <= quota) { | 921 usage + transaction_size <= quota) { |
| 950 connection->database()->Commit(host_transaction_id); | 922 connection->database()->Commit(transaction); |
| 951 } else { | 923 } else { |
| 952 connection->database()->Abort( | 924 connection->AbortTransaction( |
| 953 host_transaction_id, | 925 transaction, |
| 954 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); | 926 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); |
| 955 } | 927 } |
| 956 } | 928 } |
| 957 | 929 |
| 958 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( | 930 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( |
| 959 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { | 931 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { |
| 960 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 932 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 961 IndexedDBConnection* connection = | 933 IndexedDBConnection* connection = |
| 962 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); | 934 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); |
| 963 if (!connection || !connection->IsConnected()) | 935 if (!connection || !connection->IsConnected()) |
| 964 return; | 936 return; |
| 937 IndexedDBTransaction* transaction = | |
| 938 connection->GetTransaction(params.transaction_id); | |
| 939 if (!transaction) | |
| 940 return; | |
| 965 | 941 |
| 966 int64_t host_transaction_id = | 942 connection->database()->CreateIndex( |
| 967 parent_->HostTransactionId(params.transaction_id); | 943 transaction, params.object_store_id, params.index_id, params.name, |
| 968 connection->database()->CreateIndex(host_transaction_id, | 944 params.key_path, params.unique, params.multi_entry); |
| 969 params.object_store_id, | |
| 970 params.index_id, | |
| 971 params.name, | |
| 972 params.key_path, | |
| 973 params.unique, | |
| 974 params.multi_entry); | |
| 975 } | 945 } |
| 976 | 946 |
| 977 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( | 947 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( |
| 978 int32_t ipc_database_id, | 948 int32_t ipc_database_id, |
| 979 int64_t transaction_id, | 949 int64_t transaction_id, |
| 980 int64_t object_store_id, | 950 int64_t object_store_id, |
| 981 int64_t index_id) { | 951 int64_t index_id) { |
| 982 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 952 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 983 IndexedDBConnection* connection = | 953 IndexedDBConnection* connection = |
| 984 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 954 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 985 if (!connection || !connection->IsConnected()) | 955 if (!connection || !connection->IsConnected()) |
| 986 return; | 956 return; |
| 957 IndexedDBTransaction* transaction = | |
| 958 connection->GetTransaction(transaction_id); | |
| 959 if (!transaction) | |
| 960 return; | |
| 987 | 961 |
| 988 connection->database()->DeleteIndex( | 962 connection->database()->DeleteIndex(transaction, object_store_id, index_id); |
| 989 parent_->HostTransactionId(transaction_id), object_store_id, index_id); | |
| 990 } | 963 } |
| 991 | 964 |
| 992 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameIndex( | 965 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameIndex( |
| 993 int32_t ipc_database_id, | 966 int32_t ipc_database_id, |
| 994 int64_t transaction_id, | 967 int64_t transaction_id, |
| 995 int64_t object_store_id, | 968 int64_t object_store_id, |
| 996 int64_t index_id, | 969 int64_t index_id, |
| 997 const base::string16& new_name) { | 970 const base::string16& new_name) { |
| 998 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 971 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 999 IndexedDBConnection* connection = | 972 IndexedDBConnection* connection = |
| 1000 parent_->GetOrTerminateProcess(&map_, ipc_database_id); | 973 parent_->GetOrTerminateProcess(&map_, ipc_database_id); |
| 1001 if (!connection || !connection->IsConnected()) | 974 if (!connection || !connection->IsConnected()) |
| 1002 return; | 975 return; |
| 976 IndexedDBTransaction* transaction = | |
| 977 connection->GetTransaction(transaction_id); | |
| 978 if (!transaction) | |
| 979 return; | |
| 1003 | 980 |
| 1004 connection->database()->RenameIndex( | 981 connection->database()->RenameIndex(transaction, object_store_id, index_id, |
| 1005 parent_->HostTransactionId(transaction_id), object_store_id, index_id, | 982 new_name); |
| 1006 new_name); | |
| 1007 } | 983 } |
| 1008 | 984 |
| 1009 ////////////////////////////////////////////////////////////////////// | 985 ////////////////////////////////////////////////////////////////////// |
| 1010 // IndexedDBDispatcherHost::CursorDispatcherHost | 986 // IndexedDBDispatcherHost::CursorDispatcherHost |
| 1011 // | 987 // |
| 1012 | 988 |
| 1013 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( | 989 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( |
| 1014 IndexedDBDispatcherHost* parent) | 990 IndexedDBDispatcherHost* parent) |
| 1015 : parent_(parent) { | 991 : parent_(parent) { |
| 1016 map_.set_check_on_null_data(true); | 992 map_.set_check_on_null_data(true); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 return; | 1079 return; |
| 1104 | 1080 |
| 1105 leveldb::Status s = | 1081 leveldb::Status s = |
| 1106 idb_cursor->PrefetchReset(used_prefetches, unused_prefetches); | 1082 idb_cursor->PrefetchReset(used_prefetches, unused_prefetches); |
| 1107 // TODO(cmumford): Handle this error (crbug.com/363397) | 1083 // TODO(cmumford): Handle this error (crbug.com/363397) |
| 1108 if (!s.ok()) | 1084 if (!s.ok()) |
| 1109 DLOG(ERROR) << "Unable to reset prefetch"; | 1085 DLOG(ERROR) << "Unable to reset prefetch"; |
| 1110 } | 1086 } |
| 1111 | 1087 |
| 1112 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( | 1088 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( |
| 1113 int32_t ipc_object_id) { | 1089 int32_t ipc_cursor_id) { |
| 1114 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); | 1090 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); |
| 1115 parent_->DestroyObject(&map_, ipc_object_id); | 1091 IndexedDBCursor* idb_cursor = |
| 1092 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id); | |
| 1093 idb_cursor->RemoveCursorFromTransaction(); | |
| 1094 parent_->DestroyObject(&map_, ipc_cursor_id); | |
| 1116 } | 1095 } |
| 1117 | 1096 |
| 1118 } // namespace content | 1097 } // namespace content |
| OLD | NEW |