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

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

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: updated unittests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/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
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(IndexedDBConnection* connection,
155 const url::Origin& origin) { 156 const url::Origin& origin) {
156 if (!database_dispatcher_host_) { 157 if (!database_dispatcher_host_) {
157 connection->Close(); 158 connection->Close();
158 delete connection; 159 delete connection;
159 return -1; 160 return -1;
160 } 161 }
161 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection); 162 int32_t ipc_database_id = database_dispatcher_host_->map_.Add(connection);
162 context()->ConnectionOpened(origin, connection); 163 context()->ConnectionOpened(origin, connection);
163 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin; 164 database_dispatcher_host_->database_origin_map_[ipc_database_id] = origin;
164 return ipc_database_id; 165 return ipc_database_id;
165 } 166 }
166 167
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( 168 std::string IndexedDBDispatcherHost::HoldBlobData(
209 const IndexedDBBlobInfo& blob_info) { 169 const IndexedDBBlobInfo& blob_info) {
210 DCHECK_CURRENTLY_ON(BrowserThread::IO); 170 DCHECK_CURRENTLY_ON(BrowserThread::IO);
211 std::string uuid = blob_info.uuid(); 171 std::string uuid = blob_info.uuid();
212 storage::BlobStorageContext* context = blob_storage_context_->context(); 172 storage::BlobStorageContext* context = blob_storage_context_->context();
213 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; 173 std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
214 if (uuid.empty()) { 174 if (uuid.empty()) {
215 uuid = base::GenerateGUID(); 175 uuid = base::GenerateGUID();
216 storage::BlobDataBuilder blob_data_builder(uuid); 176 storage::BlobDataBuilder blob_data_builder(uuid);
217 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); 177 blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type()));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks, 316 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
357 const url::Origin& origin, 317 const url::Origin& origin,
358 const base::string16& name, 318 const base::string16& name,
359 int64_t version, 319 int64_t version,
360 int64_t transaction_id) { 320 int64_t transaction_id) {
361 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 321 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
362 322
363 base::TimeTicks begin_time = base::TimeTicks::Now(); 323 base::TimeTicks begin_time = base::TimeTicks::Now();
364 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 324 base::FilePath indexed_db_path = indexed_db_context_->data_path();
365 325
366 int64_t host_transaction_id = HostTransactionId(transaction_id);
367
368 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore 326 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
369 // created) if this origin is already over quota. 327 // created) if this origin is already over quota.
370 callbacks->SetConnectionOpenStartTime(begin_time); 328 callbacks->SetConnectionOpenStartTime(begin_time);
371 callbacks->set_host_transaction_id(host_transaction_id); 329 callbacks->set_host_transaction_id(transaction_id);
372 std::unique_ptr<IndexedDBPendingConnection> connection = 330 std::unique_ptr<IndexedDBPendingConnection> connection =
373 base::MakeUnique<IndexedDBPendingConnection>( 331 base::MakeUnique<IndexedDBPendingConnection>(
374 callbacks, database_callbacks, ipc_process_id_, host_transaction_id, 332 callbacks, database_callbacks, ipc_process_id_, transaction_id,
375 version); 333 version);
376 DCHECK(request_context_getter_); 334 DCHECK(request_context_getter_);
377 context()->GetIDBFactory()->Open(name, std::move(connection), 335 context()->GetIDBFactory()->Open(name, std::move(connection),
378 request_context_getter_, origin, 336 request_context_getter_, origin,
379 indexed_db_path); 337 indexed_db_path);
380 } 338 }
381 339
382 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread( 340 void IndexedDBDispatcherHost::DeleteDatabaseOnIDBThread(
383 scoped_refptr<IndexedDBCallbacks> callbacks, 341 scoped_refptr<IndexedDBCallbacks> callbacks,
384 const url::Origin& origin, 342 const url::Origin& origin,
(...skipping 14 matching lines...) Expand all
399 database_dispatcher_host_->OnPut(params, std::move(handles)); 357 database_dispatcher_host_->OnPut(params, std::move(handles));
400 } 358 }
401 359
402 void IndexedDBDispatcherHost::OnAckReceivedBlobs( 360 void IndexedDBDispatcherHost::OnAckReceivedBlobs(
403 const std::vector<std::string>& uuids) { 361 const std::vector<std::string>& uuids) {
404 DCHECK_CURRENTLY_ON(BrowserThread::IO); 362 DCHECK_CURRENTLY_ON(BrowserThread::IO);
405 for (const auto& uuid : uuids) 363 for (const auto& uuid : uuids)
406 DropBlobData(uuid); 364 DropBlobData(uuid);
407 } 365 }
408 366
409 void IndexedDBDispatcherHost::FinishTransaction(int64_t host_transaction_id, 367 void IndexedDBDispatcherHost::FinishTransaction(url::Origin transaction_origin,
410 bool committed) { 368 bool committed) {
411 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 369 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
412 if (!database_dispatcher_host_) 370 if (!database_dispatcher_host_)
413 return; 371 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) 372 if (committed)
421 context()->TransactionComplete(transaction_origin_map[host_transaction_id]); 373 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 } 374 }
426 375
427 ////////////////////////////////////////////////////////////////////// 376 //////////////////////////////////////////////////////////////////////
428 // Helper templates. 377 // Helper templates.
429 // 378 //
430 379
431 template <typename ObjectType> 380 template <typename ObjectType>
432 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( 381 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess(
433 IDMap<ObjectType, IDMapOwnPointer>* map, 382 IDMap<ObjectType, IDMapOwnPointer>* map,
434 int32_t ipc_return_object_id) { 383 int32_t ipc_return_object_id) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // TODO(alecflett): uncomment these when we find the source of these leaks. 426 // TODO(alecflett): uncomment these when we find the source of these leaks.
478 // DCHECK(transaction_size_map_.empty()); 427 // DCHECK(transaction_size_map_.empty());
479 // DCHECK(transaction_origin_map_.empty()); 428 // DCHECK(transaction_origin_map_.empty());
480 } 429 }
481 430
482 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { 431 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() {
483 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 432 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
484 // Abort outstanding transactions started by connections in the associated 433 // Abort outstanding transactions started by connections in the associated
485 // front-end to unblock later transactions. This should only occur on unclean 434 // front-end to unblock later transactions. This should only occur on unclean
486 // (crash) or abrupt (process-kill) shutdowns. 435 // (crash) or abrupt (process-kill) shutdowns.
487 for (TransactionIDToDatabaseIDMap::iterator iter = 436 IDMap<IndexedDBConnection, IDMapOwnPointer>::iterator iterator(&map_);
488 transaction_database_map_.begin(); 437 while (!iterator.IsAtEnd()) {
jsbell 2016/11/04 17:48:19 We can't use range-based for here? :(
dmurph 2016/11/04 22:52:24 We got rid of the extra map, and this map doesn't
489 iter != transaction_database_map_.end();) { 438 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()) { 439 if (connection && connection->IsConnected()) {
495 connection->database()->Abort( 440 for (const auto& transaction_pair : connection->transactions()) {
496 transaction_id, 441 connection->database()->Abort(
jsbell 2016/11/04 17:48:19 As an aside (maybe a TODO?) - maybe we want to cop
dmurph 2016/11/04 22:52:24 Acknowledged.
497 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError)); 442 transaction_pair.second.get(),
443 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError));
444 }
498 } 445 }
446 iterator.Advance();
499 } 447 }
500 DCHECK(transaction_database_map_.empty());
501 448
502 for (const auto& iter : database_origin_map_) { 449 for (const auto& iter : database_origin_map_) {
503 IndexedDBConnection* connection = map_.Lookup(iter.first); 450 IndexedDBConnection* connection = map_.Lookup(iter.first);
504 if (connection && connection->IsConnected()) { 451 if (connection && connection->IsConnected()) {
505 connection->Close(); 452 connection->Close();
506 parent_->context()->ConnectionClosed(iter.second, connection); 453 parent_->context()->ConnectionClosed(iter.second, connection);
507 } 454 }
508 } 455 }
509 } 456 }
510 457
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 return handled; 499 return handled;
553 } 500 }
554 501
555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( 502 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
556 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { 503 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) {
557 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 504 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
558 IndexedDBConnection* connection = 505 IndexedDBConnection* connection =
559 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 506 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
560 if (!connection || !connection->IsConnected()) 507 if (!connection || !connection->IsConnected())
561 return; 508 return;
509 IndexedDBTransaction* transaction =
510 connection->GetTransaction(params.transaction_id);
511 if (!transaction)
512 return;
562 513
563 int64_t host_transaction_id = 514 connection->database()->CreateObjectStore(transaction, params.object_store_id,
564 parent_->HostTransactionId(params.transaction_id); 515 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); 516 params.auto_increment);
570 } 517 }
571 518
572 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( 519 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
573 int32_t ipc_database_id, 520 int32_t ipc_database_id,
574 int64_t transaction_id, 521 int64_t transaction_id,
575 int64_t object_store_id) { 522 int64_t object_store_id) {
576 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 523 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
577 IndexedDBConnection* connection = 524 IndexedDBConnection* connection =
578 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 525 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
579 if (!connection || !connection->IsConnected()) 526 if (!connection || !connection->IsConnected())
580 return; 527 return;
528 IndexedDBTransaction* transaction =
529 connection->GetTransaction(transaction_id);
530 if (!transaction)
531 return;
581 532
582 connection->database()->DeleteObjectStore( 533 connection->database()->DeleteObjectStore(transaction, object_store_id);
583 parent_->HostTransactionId(transaction_id), object_store_id);
584 } 534 }
585 535
586 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameObjectStore( 536 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameObjectStore(
587 int32_t ipc_database_id, 537 int32_t ipc_database_id,
588 int64_t transaction_id, 538 int64_t transaction_id,
589 int64_t object_store_id, 539 int64_t object_store_id,
590 const base::string16& new_name) { 540 const base::string16& new_name) {
591 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 541 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
592 IndexedDBConnection* connection = 542 IndexedDBConnection* connection =
593 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 543 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
594 if (!connection || !connection->IsConnected()) 544 if (!connection || !connection->IsConnected())
595 return; 545 return;
546 IndexedDBTransaction* transaction =
547 connection->GetTransaction(transaction_id);
548 if (!transaction)
549 return;
596 550
597 connection->database()->RenameObjectStore( 551 connection->database()->RenameObjectStore(transaction, object_store_id,
598 parent_->HostTransactionId(transaction_id), object_store_id, new_name); 552 new_name);
599 } 553 }
600 554
601 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( 555 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction(
602 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { 556 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) {
603 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 557 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
604 IndexedDBConnection* connection = 558 IndexedDBConnection* connection =
605 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 559 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
606 if (!connection || !connection->IsConnected()) 560 if (!connection || !connection->IsConnected())
607 return; 561 return;
608 562
609 int64_t host_transaction_id = 563 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."; 564 DLOG(ERROR) << "Duplicate host_transaction_id.";
614 return; 565 return;
615 } 566 }
616 567
617 connection->database()->CreateTransaction( 568 IndexedDBTransaction* transaction = connection->database()->CreateTransaction(
618 host_transaction_id, connection, params.object_store_ids, params.mode); 569 params.transaction_id, connection, params.object_store_ids, params.mode);
619 transaction_database_map_[host_transaction_id] = params.ipc_database_id; 570 transaction->set_origin(database_origin_map_[params.ipc_database_id]);
cmumford 2016/11/04 23:33:12 Why aren't we passing in the origin to CreateTrans
dmurph 2016/11/07 20:05:23 No longer needed now that we store it on the conne
620 parent_->RegisterTransactionId(host_transaction_id,
621 database_origin_map_[params.ipc_database_id]);
622 } 571 }
623 572
624 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( 573 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose(
625 int32_t ipc_database_id) { 574 int32_t ipc_database_id) {
626 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 575 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
627 IndexedDBConnection* connection = 576 IndexedDBConnection* connection =
628 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 577 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
629 if (!connection || !connection->IsConnected()) 578 if (!connection || !connection->IsConnected())
630 return; 579 return;
631 connection->Close(); 580 connection->Close();
(...skipping 24 matching lines...) Expand all
656 parent_->DestroyObject(&map_, ipc_object_id); 605 parent_->DestroyObject(&map_, ipc_object_id);
657 } 606 }
658 607
659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve( 608 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObserve(
660 const IndexedDBHostMsg_DatabaseObserve_Params& params) { 609 const IndexedDBHostMsg_DatabaseObserve_Params& params) {
661 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 610 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
662 IndexedDBConnection* connection = 611 IndexedDBConnection* connection =
663 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 612 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
664 if (!connection || !connection->IsConnected()) 613 if (!connection || !connection->IsConnected())
665 return; 614 return;
615 IndexedDBTransaction* transaction =
616 connection->GetTransaction(params.transaction_id);
617 if (!transaction)
618 return;
666 IndexedDBObserver::Options options(params.include_transaction, 619 IndexedDBObserver::Options options(params.include_transaction,
667 params.no_records, params.values, 620 params.no_records, params.values,
668 params.operation_types); 621 params.operation_types);
669 connection->database()->AddPendingObserver( 622 connection->database()->AddPendingObserver(transaction, params.observer_id,
670 parent_->HostTransactionId(params.transaction_id), params.observer_id, 623 options);
671 options);
672 } 624 }
673 625
674 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve( 626 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnUnobserve(
675 int32_t ipc_database_id, 627 int32_t ipc_database_id,
676 const std::vector<int32_t>& observer_ids_to_remove) { 628 const std::vector<int32_t>& observer_ids_to_remove) {
677 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 629 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
678 DCHECK(!observer_ids_to_remove.empty()); 630 DCHECK(!observer_ids_to_remove.empty());
679 IndexedDBConnection* connection = 631 IndexedDBConnection* connection =
680 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 632 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
681 if (!connection || !connection->IsConnected()) 633 if (!connection || !connection->IsConnected())
682 return; 634 return;
683 connection->RemoveObservers(observer_ids_to_remove); 635 connection->RemoveObservers(observer_ids_to_remove);
684 } 636 }
685 637
686 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 638 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
687 const IndexedDBHostMsg_DatabaseGet_Params& params) { 639 const IndexedDBHostMsg_DatabaseGet_Params& params) {
688 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 640 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
689 IndexedDBConnection* connection = 641 IndexedDBConnection* connection =
690 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 642 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
691 if (!connection || !connection->IsConnected()) 643 if (!connection || !connection->IsConnected())
692 return; 644 return;
645 IndexedDBTransaction* transaction =
646 connection->GetTransaction(params.transaction_id);
647 if (!transaction)
648 return;
693 649
694 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 650 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
695 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 651 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
696 connection->database()->Get( 652 connection->database()->Get(
697 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 653 transaction, params.object_store_id, params.index_id,
698 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 654 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.key_only,
699 params.key_only, callbacks); 655 callbacks);
700 } 656 }
701 657
702 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGetAll( 658 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGetAll(
703 const IndexedDBHostMsg_DatabaseGetAll_Params& params) { 659 const IndexedDBHostMsg_DatabaseGetAll_Params& params) {
704 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 660 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
705 IndexedDBConnection* connection = 661 IndexedDBConnection* connection =
706 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 662 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
707 if (!connection || !connection->IsConnected()) 663 if (!connection || !connection->IsConnected())
708 return; 664 return;
665 IndexedDBTransaction* transaction =
666 connection->GetTransaction(params.transaction_id);
667 if (!transaction)
668 return;
709 669
710 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 670 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
711 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 671 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
712 connection->database()->GetAll( 672 connection->database()->GetAll(
713 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 673 transaction, params.object_store_id, params.index_id,
714 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 674 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.key_only,
715 params.key_only, params.max_count, callbacks); 675 params.max_count, callbacks);
716 } 676 }
717 677
718 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper( 678 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPutWrapper(
719 const IndexedDBHostMsg_DatabasePut_Params& params) { 679 const IndexedDBHostMsg_DatabasePut_Params& params) {
720 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; 680 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
721 for (const auto& info : params.value.blob_or_file_info) { 681 for (const auto& info : params.value.blob_or_file_info) {
722 handles.push_back( 682 handles.push_back(
723 parent_->blob_storage_context_->context()->GetBlobDataFromUUID( 683 parent_->blob_storage_context_->context()->GetBlobDataFromUUID(
724 info.uuid)); 684 info.uuid));
725 } 685 }
726 parent_->context()->TaskRunner()->PostTask( 686 parent_->context()->TaskRunner()->PostTask(
727 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_, 687 FROM_HERE, base::Bind(&IndexedDBDispatcherHost::OnPutHelper, parent_,
728 params, base::Passed(&handles))); 688 params, base::Passed(&handles)));
729 } 689 }
730 690
731 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 691 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
732 const IndexedDBHostMsg_DatabasePut_Params& params, 692 const IndexedDBHostMsg_DatabasePut_Params& params,
733 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) { 693 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles) {
734 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 694 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
735 695
736 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles; 696 std::vector<std::unique_ptr<storage::BlobDataHandle>> scoped_handles;
737 scoped_handles.swap(handles); 697 scoped_handles.swap(handles);
738 698
739 IndexedDBConnection* connection = 699 IndexedDBConnection* connection =
740 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 700 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
741 if (!connection || !connection->IsConnected()) 701 if (!connection || !connection->IsConnected())
742 return; 702 return;
703 IndexedDBTransaction* transaction =
704 connection->GetTransaction(params.transaction_id);
705 if (!transaction)
706 return;
743 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 707 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
744 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 708 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
745 709
746 int64_t host_transaction_id =
747 parent_->HostTransactionId(params.transaction_id);
748
749 std::vector<IndexedDBBlobInfo> blob_info( 710 std::vector<IndexedDBBlobInfo> blob_info(
750 params.value.blob_or_file_info.size()); 711 params.value.blob_or_file_info.size());
751 712
752 ChildProcessSecurityPolicyImpl* policy = 713 ChildProcessSecurityPolicyImpl* policy =
753 ChildProcessSecurityPolicyImpl::GetInstance(); 714 ChildProcessSecurityPolicyImpl::GetInstance();
754 715
755 size_t i = 0; 716 size_t i = 0;
756 for (const auto& info : params.value.blob_or_file_info) { 717 for (const auto& info : params.value.blob_or_file_info) {
757 if (info.is_file) { 718 if (info.is_file) {
758 base::FilePath path; 719 base::FilePath path;
(...skipping 15 matching lines...) Expand all
774 } else { 735 } else {
775 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size); 736 blob_info[i] = IndexedDBBlobInfo(info.uuid, info.mime_type, info.size);
776 } 737 }
777 ++i; 738 ++i;
778 } 739 }
779 740
780 // TODO(alecflett): Avoid a copy here. 741 // TODO(alecflett): Avoid a copy here.
781 IndexedDBValue value; 742 IndexedDBValue value;
782 value.bits = params.value.bits; 743 value.bits = params.value.bits;
783 value.blob_info.swap(blob_info); 744 value.blob_info.swap(blob_info);
784 connection->database()->Put(host_transaction_id, params.object_store_id, 745 connection->database()->Put(transaction, params.object_store_id, &value,
785 &value, &scoped_handles, 746 &scoped_handles,
786 base::MakeUnique<IndexedDBKey>(params.key), 747 base::MakeUnique<IndexedDBKey>(params.key),
787 params.put_mode, callbacks, params.index_keys); 748 params.put_mode, callbacks, params.index_keys);
788 // Size can't be big enough to overflow because it represents the 749 // Size can't be big enough to overflow because it represents the
789 // actual bytes passed through IPC. 750 // actual bytes passed through IPC.
790 transaction_size_map_[host_transaction_id] += params.value.bits.size(); 751 transaction->set_size(transaction->size() + params.value.bits.size());
791 } 752 }
792 753
793 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( 754 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
794 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { 755 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
795 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 756 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
796 IndexedDBConnection* connection = 757 IndexedDBConnection* connection =
797 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 758 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
798 if (!connection || !connection->IsConnected()) 759 if (!connection || !connection->IsConnected())
799 return; 760 return;
761 IndexedDBTransaction* transaction =
762 connection->GetTransaction(params.transaction_id);
763 if (!transaction)
764 return;
800 765
801 int64_t host_transaction_id =
802 parent_->HostTransactionId(params.transaction_id);
803 connection->database()->SetIndexKeys( 766 connection->database()->SetIndexKeys(
804 host_transaction_id, params.object_store_id, 767 transaction, params.object_store_id,
805 base::MakeUnique<IndexedDBKey>(params.primary_key), params.index_keys); 768 base::MakeUnique<IndexedDBKey>(params.primary_key), params.index_keys);
806 } 769 }
807 770
808 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( 771 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
809 int32_t ipc_database_id, 772 int32_t ipc_database_id,
810 int64_t transaction_id, 773 int64_t transaction_id,
811 int64_t object_store_id, 774 int64_t object_store_id,
812 const std::vector<int64_t>& index_ids) { 775 const std::vector<int64_t>& index_ids) {
813 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 776 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
814 IndexedDBConnection* connection = 777 IndexedDBConnection* connection =
815 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 778 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
816 if (!connection || !connection->IsConnected()) 779 if (!connection || !connection->IsConnected())
817 return; 780 return;
781 IndexedDBTransaction* transaction =
782 connection->GetTransaction(transaction_id);
783 if (!transaction)
784 return;
818 785
819 connection->database()->SetIndexesReady( 786 connection->database()->SetIndexesReady(transaction, object_store_id,
820 parent_->HostTransactionId(transaction_id), object_store_id, index_ids); 787 index_ids);
821 } 788 }
822 789
823 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( 790 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
824 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { 791 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
825 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 792 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
826 IndexedDBConnection* connection = 793 IndexedDBConnection* connection =
827 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 794 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
828 if (!connection || !connection->IsConnected()) 795 if (!connection || !connection->IsConnected())
829 return; 796 return;
797 IndexedDBTransaction* transaction =
798 connection->GetTransaction(params.transaction_id);
799 if (!transaction)
800 return;
830 801
831 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 802 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
832 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1)); 803 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1));
833 connection->database()->OpenCursor( 804 connection->database()->OpenCursor(
834 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 805 transaction, params.object_store_id, params.index_id,
835 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 806 base::MakeUnique<IndexedDBKeyRange>(params.key_range), params.direction,
836 params.direction, params.key_only, params.task_type, callbacks); 807 params.key_only, params.task_type, callbacks);
837 } 808 }
838 809
839 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( 810 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
840 const IndexedDBHostMsg_DatabaseCount_Params& params) { 811 const IndexedDBHostMsg_DatabaseCount_Params& params) {
841 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 812 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
842 IndexedDBConnection* connection = 813 IndexedDBConnection* connection =
843 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 814 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
844 if (!connection || !connection->IsConnected()) 815 if (!connection || !connection->IsConnected())
845 return; 816 return;
817 IndexedDBTransaction* transaction =
818 connection->GetTransaction(params.transaction_id);
819 if (!transaction)
820 return;
846 821
847 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 822 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
848 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 823 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
849 connection->database()->Count( 824 connection->database()->Count(
850 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 825 transaction, params.object_store_id, params.index_id,
851 params.index_id, base::MakeUnique<IndexedDBKeyRange>(params.key_range), 826 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks);
852 callbacks);
853 } 827 }
854 828
855 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( 829 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
856 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { 830 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
857 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 831 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
858 IndexedDBConnection* connection = 832 IndexedDBConnection* connection =
859 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 833 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
860 if (!connection || !connection->IsConnected()) 834 if (!connection || !connection->IsConnected())
861 return; 835 return;
836 IndexedDBTransaction* transaction =
837 connection->GetTransaction(params.transaction_id);
838 if (!transaction)
839 return;
862 840
863 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 841 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
864 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 842 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
865 connection->database()->DeleteRange( 843 connection->database()->DeleteRange(
866 parent_->HostTransactionId(params.transaction_id), params.object_store_id, 844 transaction, params.object_store_id,
867 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks); 845 base::MakeUnique<IndexedDBKeyRange>(params.key_range), callbacks);
868 } 846 }
869 847
870 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( 848 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
871 int32_t ipc_thread_id, 849 int32_t ipc_thread_id,
872 int32_t ipc_callbacks_id, 850 int32_t ipc_callbacks_id,
873 int32_t ipc_database_id, 851 int32_t ipc_database_id,
874 int64_t transaction_id, 852 int64_t transaction_id,
875 int64_t object_store_id) { 853 int64_t object_store_id) {
876 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 854 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
877 IndexedDBConnection* connection = 855 IndexedDBConnection* connection =
878 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 856 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
879 if (!connection || !connection->IsConnected()) 857 if (!connection || !connection->IsConnected())
880 return; 858 return;
859 IndexedDBTransaction* transaction =
860 connection->GetTransaction(transaction_id);
861 if (!transaction)
862 return;
881 863
882 scoped_refptr<IndexedDBCallbacks> callbacks( 864 scoped_refptr<IndexedDBCallbacks> callbacks(
883 new IndexedDBCallbacks(parent_, ipc_thread_id, ipc_callbacks_id)); 865 new IndexedDBCallbacks(parent_, ipc_thread_id, ipc_callbacks_id));
884 866
885 connection->database()->Clear( 867 connection->database()->Clear(transaction, object_store_id, callbacks);
886 parent_->HostTransactionId(transaction_id), object_store_id, callbacks);
887 } 868 }
888 869
889 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( 870 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort(
890 int32_t ipc_database_id, 871 int32_t ipc_database_id,
891 int64_t transaction_id) { 872 int64_t transaction_id) {
892 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 873 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
893 IndexedDBConnection* connection = 874 IndexedDBConnection* connection =
894 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 875 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
895 if (!connection || !connection->IsConnected()) 876 if (!connection || !connection->IsConnected())
896 return; 877 return;
878 IndexedDBTransaction* transaction =
879 connection->GetTransaction(transaction_id);
880 if (!transaction)
881 return;
897 882
898 connection->database()->Abort(parent_->HostTransactionId(transaction_id)); 883 connection->database()->Abort(transaction);
899 } 884 }
900 885
901 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( 886 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit(
902 int32_t ipc_database_id, 887 int32_t ipc_database_id,
903 int64_t transaction_id) { 888 int64_t transaction_id) {
904 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 889 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
905 IndexedDBConnection* connection = 890 IndexedDBConnection* connection =
906 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 891 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
907 if (!connection || !connection->IsConnected()) 892 if (!connection || !connection->IsConnected())
908 return; 893 return;
894 IndexedDBTransaction* transaction =
895 connection->GetTransaction(transaction_id);
896 if (!transaction)
897 return;
909 898
910 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); 899 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 900
916 // Always allow empty or delete-only transactions. 901 // Always allow empty or delete-only transactions.
917 if (!transaction_size) { 902 if (!transaction_size) {
918 connection->database()->Commit(host_transaction_id); 903 connection->database()->Commit(transaction);
919 return; 904 return;
920 } 905 }
921 906
922 parent_->context()->quota_manager_proxy()->GetUsageAndQuota( 907 parent_->context()->quota_manager_proxy()->GetUsageAndQuota(
923 parent_->context()->TaskRunner(), 908 parent_->context()->TaskRunner(), GURL(transaction->origin().Serialize()),
924 GURL(transaction_origin_map_[host_transaction_id].Serialize()),
925 storage::kStorageTypeTemporary, 909 storage::kStorageTypeTemporary,
926 base::Bind(&IndexedDBDispatcherHost::DatabaseDispatcherHost:: 910 base::Bind(&IndexedDBDispatcherHost::DatabaseDispatcherHost::
927 OnGotUsageAndQuotaForCommit, 911 OnGotUsageAndQuotaForCommit,
928 weak_factory_.GetWeakPtr(), ipc_database_id, transaction_id)); 912 weak_factory_.GetWeakPtr(), ipc_database_id, transaction_id));
929 } 913 }
930 914
931 void IndexedDBDispatcherHost::DatabaseDispatcherHost:: 915 void IndexedDBDispatcherHost::DatabaseDispatcherHost::
932 OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, 916 OnGotUsageAndQuotaForCommit(int32_t ipc_database_id,
933 int64_t transaction_id, 917 int64_t transaction_id,
934 storage::QuotaStatusCode status, 918 storage::QuotaStatusCode status,
935 int64_t usage, 919 int64_t usage,
936 int64_t quota) { 920 int64_t quota) {
937 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 921 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
938 IndexedDBConnection* connection = map_.Lookup(ipc_database_id); 922 IndexedDBConnection* connection = map_.Lookup(ipc_database_id);
939 // May have disconnected while quota check was pending. 923 // May have disconnected while quota check was pending.
940 if (!connection || !connection->IsConnected()) 924 if (!connection || !connection->IsConnected())
941 return; 925 return;
942 int64_t host_transaction_id = parent_->HostTransactionId(transaction_id); 926 IndexedDBTransaction* transaction =
943 // May have aborted while quota check was pending. 927 connection->GetTransaction(transaction_id);
944 if (!base::ContainsKey(transaction_size_map_, host_transaction_id)) 928 if (!transaction)
945 return; 929 return;
946 int64_t transaction_size = transaction_size_map_[host_transaction_id]; 930
931 int64_t transaction_size = transaction->size();
947 932
948 if (status == storage::kQuotaStatusOk && 933 if (status == storage::kQuotaStatusOk &&
949 usage + transaction_size <= quota) { 934 usage + transaction_size <= quota) {
950 connection->database()->Commit(host_transaction_id); 935 connection->database()->Commit(transaction);
951 } else { 936 } else {
952 connection->database()->Abort( 937 connection->database()->Abort(
953 host_transaction_id, 938 transaction,
954 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); 939 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError));
955 } 940 }
956 } 941 }
957 942
958 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( 943 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex(
959 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { 944 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) {
960 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 945 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
961 IndexedDBConnection* connection = 946 IndexedDBConnection* connection =
962 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 947 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
963 if (!connection || !connection->IsConnected()) 948 if (!connection || !connection->IsConnected())
964 return; 949 return;
950 IndexedDBTransaction* transaction =
951 connection->GetTransaction(params.transaction_id);
952 if (!transaction)
953 return;
965 954
966 int64_t host_transaction_id = 955 connection->database()->CreateIndex(
967 parent_->HostTransactionId(params.transaction_id); 956 transaction, params.object_store_id, params.index_id, params.name,
968 connection->database()->CreateIndex(host_transaction_id, 957 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 } 958 }
976 959
977 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( 960 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex(
978 int32_t ipc_database_id, 961 int32_t ipc_database_id,
979 int64_t transaction_id, 962 int64_t transaction_id,
980 int64_t object_store_id, 963 int64_t object_store_id,
981 int64_t index_id) { 964 int64_t index_id) {
982 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 965 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
983 IndexedDBConnection* connection = 966 IndexedDBConnection* connection =
984 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 967 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
985 if (!connection || !connection->IsConnected()) 968 if (!connection || !connection->IsConnected())
986 return; 969 return;
970 IndexedDBTransaction* transaction =
971 connection->GetTransaction(transaction_id);
972 if (!transaction)
973 return;
987 974
988 connection->database()->DeleteIndex( 975 connection->database()->DeleteIndex(transaction, object_store_id, index_id);
989 parent_->HostTransactionId(transaction_id), object_store_id, index_id);
990 } 976 }
991 977
992 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameIndex( 978 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRenameIndex(
993 int32_t ipc_database_id, 979 int32_t ipc_database_id,
994 int64_t transaction_id, 980 int64_t transaction_id,
995 int64_t object_store_id, 981 int64_t object_store_id,
996 int64_t index_id, 982 int64_t index_id,
997 const base::string16& new_name) { 983 const base::string16& new_name) {
998 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 984 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
999 IndexedDBConnection* connection = 985 IndexedDBConnection* connection =
1000 parent_->GetOrTerminateProcess(&map_, ipc_database_id); 986 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
1001 if (!connection || !connection->IsConnected()) 987 if (!connection || !connection->IsConnected())
1002 return; 988 return;
989 IndexedDBTransaction* transaction =
990 connection->GetTransaction(transaction_id);
991 if (!transaction)
992 return;
1003 993
1004 connection->database()->RenameIndex( 994 connection->database()->RenameIndex(transaction, object_store_id, index_id,
1005 parent_->HostTransactionId(transaction_id), object_store_id, index_id, 995 new_name);
1006 new_name);
1007 } 996 }
1008 997
1009 ////////////////////////////////////////////////////////////////////// 998 //////////////////////////////////////////////////////////////////////
1010 // IndexedDBDispatcherHost::CursorDispatcherHost 999 // IndexedDBDispatcherHost::CursorDispatcherHost
1011 // 1000 //
1012 1001
1013 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( 1002 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
1014 IndexedDBDispatcherHost* parent) 1003 IndexedDBDispatcherHost* parent)
1015 : parent_(parent) { 1004 : parent_(parent) {
1016 map_.set_check_on_null_data(true); 1005 map_.set_check_on_null_data(true);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 return; 1092 return;
1104 1093
1105 leveldb::Status s = 1094 leveldb::Status s =
1106 idb_cursor->PrefetchReset(used_prefetches, unused_prefetches); 1095 idb_cursor->PrefetchReset(used_prefetches, unused_prefetches);
1107 // TODO(cmumford): Handle this error (crbug.com/363397) 1096 // TODO(cmumford): Handle this error (crbug.com/363397)
1108 if (!s.ok()) 1097 if (!s.ok())
1109 DLOG(ERROR) << "Unable to reset prefetch"; 1098 DLOG(ERROR) << "Unable to reset prefetch";
1110 } 1099 }
1111 1100
1112 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 1101 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1113 int32_t ipc_object_id) { 1102 int32_t ipc_cursor_id) {
1114 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread()); 1103 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
1115 parent_->DestroyObject(&map_, ipc_object_id); 1104 IndexedDBCursor* idb_cursor =
1105 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
1106 idb_cursor->RemoveCursorFromTransaction();
1107 parent_->DestroyObject(&map_, ipc_cursor_id);
1116 } 1108 }
1117 1109
1118 } // namespace content 1110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698