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

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

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: rebase Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/database_impl.h" 5 #include "content/browser/indexed_db/database_impl.h"
6 6
7 #include "content/browser/bad_message.h" 7 #include "content/browser/bad_message.h"
8 #include "content/browser/child_process_security_policy_impl.h" 8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/browser/indexed_db/indexed_db_connection.h" 9 #include "content/browser/indexed_db/indexed_db_connection.h"
10 #include "content/browser/indexed_db/indexed_db_context_impl.h" 10 #include "content/browser/indexed_db/indexed_db_context_impl.h"
11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
12 #include "content/browser/indexed_db/indexed_db_transaction.h"
12 #include "content/browser/indexed_db/indexed_db_value.h" 13 #include "content/browser/indexed_db/indexed_db_value.h"
13 #include "storage/browser/blob/blob_storage_context.h" 14 #include "storage/browser/blob/blob_storage_context.h"
14 #include "storage/browser/quota/quota_manager_proxy.h" 15 #include "storage/browser/quota/quota_manager_proxy.h"
15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
16 17
17 using std::swap; 18 using std::swap;
18 19
19 namespace content { 20 namespace content {
20 21
21 namespace { 22 namespace {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 447
447 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( 448 void DatabaseImpl::IDBThreadHelper::CreateObjectStore(
448 int64_t transaction_id, 449 int64_t transaction_id,
449 int64_t object_store_id, 450 int64_t object_store_id,
450 const base::string16& name, 451 const base::string16& name,
451 const IndexedDBKeyPath& key_path, 452 const IndexedDBKeyPath& key_path,
452 bool auto_increment) { 453 bool auto_increment) {
453 if (!connection_->IsConnected()) 454 if (!connection_->IsConnected())
454 return; 455 return;
455 456
456 connection_->database()->CreateObjectStore( 457 IndexedDBTransaction* transaction =
457 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 458 connection_->GetTransaction(transaction_id);
458 name, key_path, auto_increment); 459 if (!transaction)
460 return;
461
462 connection_->database()->CreateObjectStore(transaction, object_store_id, name,
463 key_path, auto_increment);
459 } 464 }
460 465
461 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id, 466 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id,
462 int64_t object_store_id) { 467 int64_t object_store_id) {
463 if (!connection_->IsConnected()) 468 if (!connection_->IsConnected())
464 return; 469 return;
465 470
466 connection_->database()->DeleteObjectStore( 471 IndexedDBTransaction* transaction =
467 dispatcher_host_->HostTransactionId(transaction_id), object_store_id); 472 connection_->GetTransaction(transaction_id);
473 if (!transaction)
474 return;
475
476 connection_->database()->DeleteObjectStore(transaction, object_store_id);
468 } 477 }
469 478
470 void DatabaseImpl::IDBThreadHelper::RenameObjectStore( 479 void DatabaseImpl::IDBThreadHelper::RenameObjectStore(
471 int64_t transaction_id, 480 int64_t transaction_id,
472 int64_t object_store_id, 481 int64_t object_store_id,
473 const base::string16& new_name) { 482 const base::string16& new_name) {
474 if (!connection_->IsConnected()) 483 if (!connection_->IsConnected())
475 return; 484 return;
476 485
477 connection_->database()->RenameObjectStore( 486 IndexedDBTransaction* transaction =
478 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 487 connection_->GetTransaction(transaction_id);
479 new_name); 488 if (!transaction)
489 return;
490
491 connection_->database()->RenameObjectStore(transaction, object_store_id,
492 new_name);
480 } 493 }
481 494
482 void DatabaseImpl::IDBThreadHelper::CreateTransaction( 495 void DatabaseImpl::IDBThreadHelper::CreateTransaction(
483 int64_t transaction_id, 496 int64_t transaction_id,
484 const std::vector<int64_t>& object_store_ids, 497 const std::vector<int64_t>& object_store_ids,
485 blink::WebIDBTransactionMode mode) { 498 blink::WebIDBTransactionMode mode) {
486 if (!connection_->IsConnected()) 499 if (!connection_->IsConnected())
487 return; 500 return;
488 501
489 int64_t host_transaction_id = 502 connection_->database()->CreateTransaction(transaction_id, connection_.get(),
490 dispatcher_host_->HostTransactionId(transaction_id); 503 object_store_ids, mode);
491 if (!dispatcher_host_->RegisterTransactionId(host_transaction_id, origin_)) {
492 DLOG(ERROR) << "Duplicate host_transaction_id.";
493 return;
494 }
495
496 connection_->database()->CreateTransaction(
497 host_transaction_id, connection_.get(), object_store_ids, mode);
498 } 504 }
499 505
500 void DatabaseImpl::IDBThreadHelper::Close() { 506 void DatabaseImpl::IDBThreadHelper::Close() {
501 if (!connection_->IsConnected()) 507 if (!connection_->IsConnected())
502 return; 508 return;
503 509
504 connection_->Close(); 510 connection_->Close();
505 } 511 }
506 512
507 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() { 513 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() {
508 if (!connection_->IsConnected()) 514 if (!connection_->IsConnected())
509 return; 515 return;
510 516
511 connection_->VersionChangeIgnored(); 517 connection_->VersionChangeIgnored();
512 } 518 }
513 519
514 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id, 520 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id,
515 int32_t observer_id, 521 int32_t observer_id,
516 bool include_transaction, 522 bool include_transaction,
517 bool no_records, 523 bool no_records,
518 bool values, 524 bool values,
519 uint16_t operation_types) { 525 uint16_t operation_types) {
520 if (!connection_->IsConnected()) 526 if (!connection_->IsConnected())
521 return; 527 return;
522 528
529 IndexedDBTransaction* transaction =
530 connection_->GetTransaction(transaction_id);
531 if (!transaction)
532 return;
533
523 IndexedDBObserver::Options options(include_transaction, no_records, values, 534 IndexedDBObserver::Options options(include_transaction, no_records, values,
524 operation_types); 535 operation_types);
525 connection_->database()->AddPendingObserver( 536 connection_->database()->AddPendingObserver(transaction, observer_id,
526 dispatcher_host_->HostTransactionId(transaction_id), observer_id, 537 options);
527 options);
528 } 538 }
529 539
530 void DatabaseImpl::IDBThreadHelper::RemoveObservers( 540 void DatabaseImpl::IDBThreadHelper::RemoveObservers(
531 const std::vector<int32_t>& observers) { 541 const std::vector<int32_t>& observers) {
532 if (!connection_->IsConnected()) 542 if (!connection_->IsConnected())
533 return; 543 return;
534 544
535 connection_->RemoveObservers(observers); 545 connection_->RemoveObservers(observers);
536 } 546 }
537 547
538 void DatabaseImpl::IDBThreadHelper::Get( 548 void DatabaseImpl::IDBThreadHelper::Get(
539 int64_t transaction_id, 549 int64_t transaction_id,
540 int64_t object_store_id, 550 int64_t object_store_id,
541 int64_t index_id, 551 int64_t index_id,
542 const IndexedDBKeyRange& key_range, 552 const IndexedDBKeyRange& key_range,
543 bool key_only, 553 bool key_only,
544 scoped_refptr<IndexedDBCallbacks> callbacks) { 554 scoped_refptr<IndexedDBCallbacks> callbacks) {
545 if (!connection_->IsConnected()) 555 if (!connection_->IsConnected())
546 return; 556 return;
547 557
548 connection_->database()->Get( 558 IndexedDBTransaction* transaction =
549 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 559 connection_->GetTransaction(transaction_id);
550 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, 560 if (!transaction)
551 callbacks); 561 return;
562
563 connection_->database()->Get(transaction, object_store_id, index_id,
564 base::MakeUnique<IndexedDBKeyRange>(key_range),
565 key_only, callbacks);
552 } 566 }
553 567
554 void DatabaseImpl::IDBThreadHelper::GetAll( 568 void DatabaseImpl::IDBThreadHelper::GetAll(
555 int64_t transaction_id, 569 int64_t transaction_id,
556 int64_t object_store_id, 570 int64_t object_store_id,
557 int64_t index_id, 571 int64_t index_id,
558 const IndexedDBKeyRange& key_range, 572 const IndexedDBKeyRange& key_range,
559 bool key_only, 573 bool key_only,
560 int64_t max_count, 574 int64_t max_count,
561 scoped_refptr<IndexedDBCallbacks> callbacks) { 575 scoped_refptr<IndexedDBCallbacks> callbacks) {
562 if (!connection_->IsConnected()) 576 if (!connection_->IsConnected())
563 return; 577 return;
564 578
579 IndexedDBTransaction* transaction =
580 connection_->GetTransaction(transaction_id);
581 if (!transaction)
582 return;
583
565 connection_->database()->GetAll( 584 connection_->database()->GetAll(
566 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 585 transaction, object_store_id, index_id,
567 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, 586 base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, max_count,
568 max_count, std::move(callbacks)); 587 std::move(callbacks));
569 } 588 }
570 589
571 void DatabaseImpl::IDBThreadHelper::Put( 590 void DatabaseImpl::IDBThreadHelper::Put(
572 int64_t transaction_id, 591 int64_t transaction_id,
573 int64_t object_store_id, 592 int64_t object_store_id,
574 ::indexed_db::mojom::ValuePtr mojo_value, 593 ::indexed_db::mojom::ValuePtr mojo_value,
575 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, 594 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles,
576 std::vector<IndexedDBBlobInfo> blob_info, 595 std::vector<IndexedDBBlobInfo> blob_info,
577 const IndexedDBKey& key, 596 const IndexedDBKey& key,
578 blink::WebIDBPutMode mode, 597 blink::WebIDBPutMode mode,
579 const std::vector<IndexedDBIndexKeys>& index_keys, 598 const std::vector<IndexedDBIndexKeys>& index_keys,
580 scoped_refptr<IndexedDBCallbacks> callbacks) { 599 scoped_refptr<IndexedDBCallbacks> callbacks) {
581 if (!connection_->IsConnected()) 600 if (!connection_->IsConnected())
582 return; 601 return;
583 602
584 int64_t host_transaction_id = 603 IndexedDBTransaction* transaction =
585 dispatcher_host_->HostTransactionId(transaction_id); 604 connection_->GetTransaction(transaction_id);
605 if (!transaction)
606 return;
607
586 uint64_t commit_size = mojo_value->bits.size(); 608 uint64_t commit_size = mojo_value->bits.size();
587 IndexedDBValue value; 609 IndexedDBValue value;
588 swap(value.bits, mojo_value->bits); 610 swap(value.bits, mojo_value->bits);
589 swap(value.blob_info, blob_info); 611 swap(value.blob_info, blob_info);
590 connection_->database()->Put(host_transaction_id, object_store_id, &value, 612 connection_->database()->Put(transaction, object_store_id, &value, &handles,
591 &handles, base::MakeUnique<IndexedDBKey>(key), 613 base::MakeUnique<IndexedDBKey>(key), mode,
592 mode, std::move(callbacks), index_keys); 614 std::move(callbacks), index_keys);
593 615
594 // Size can't be big enough to overflow because it represents the 616 // Size can't be big enough to overflow because it represents the
595 // actual bytes passed through IPC. 617 // actual bytes passed through IPC.
596 dispatcher_host_->AddToTransaction(host_transaction_id, commit_size); 618 transaction->set_size(transaction->size() + commit_size);
597 } 619 }
598 620
599 void DatabaseImpl::IDBThreadHelper::SetIndexKeys( 621 void DatabaseImpl::IDBThreadHelper::SetIndexKeys(
600 int64_t transaction_id, 622 int64_t transaction_id,
601 int64_t object_store_id, 623 int64_t object_store_id,
602 const IndexedDBKey& primary_key, 624 const IndexedDBKey& primary_key,
603 const std::vector<IndexedDBIndexKeys>& index_keys) { 625 const std::vector<IndexedDBIndexKeys>& index_keys) {
604 if (!connection_->IsConnected()) 626 if (!connection_->IsConnected())
605 return; 627 return;
606 628
629 IndexedDBTransaction* transaction =
630 connection_->GetTransaction(transaction_id);
631 if (!transaction)
632 return;
633
607 connection_->database()->SetIndexKeys( 634 connection_->database()->SetIndexKeys(
608 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 635 transaction, object_store_id, base::MakeUnique<IndexedDBKey>(primary_key),
609 base::MakeUnique<IndexedDBKey>(primary_key), index_keys); 636 index_keys);
610 } 637 }
611 638
612 void DatabaseImpl::IDBThreadHelper::SetIndexesReady( 639 void DatabaseImpl::IDBThreadHelper::SetIndexesReady(
613 int64_t transaction_id, 640 int64_t transaction_id,
614 int64_t object_store_id, 641 int64_t object_store_id,
615 const std::vector<int64_t>& index_ids) { 642 const std::vector<int64_t>& index_ids) {
616 if (!connection_->IsConnected()) 643 if (!connection_->IsConnected())
617 return; 644 return;
618 645
619 connection_->database()->SetIndexesReady( 646 IndexedDBTransaction* transaction =
620 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 647 connection_->GetTransaction(transaction_id);
621 index_ids); 648 if (!transaction)
649 return;
650
651 connection_->database()->SetIndexesReady(transaction, object_store_id,
652 index_ids);
622 } 653 }
623 654
624 void DatabaseImpl::IDBThreadHelper::OpenCursor( 655 void DatabaseImpl::IDBThreadHelper::OpenCursor(
625 int64_t transaction_id, 656 int64_t transaction_id,
626 int64_t object_store_id, 657 int64_t object_store_id,
627 int64_t index_id, 658 int64_t index_id,
628 const IndexedDBKeyRange& key_range, 659 const IndexedDBKeyRange& key_range,
629 blink::WebIDBCursorDirection direction, 660 blink::WebIDBCursorDirection direction,
630 bool key_only, 661 bool key_only,
631 blink::WebIDBTaskType task_type, 662 blink::WebIDBTaskType task_type,
632 scoped_refptr<IndexedDBCallbacks> callbacks) { 663 scoped_refptr<IndexedDBCallbacks> callbacks) {
633 if (!connection_->IsConnected()) 664 if (!connection_->IsConnected())
634 return; 665 return;
635 666
667 IndexedDBTransaction* transaction =
668 connection_->GetTransaction(transaction_id);
669 if (!transaction)
670 return;
671
636 connection_->database()->OpenCursor( 672 connection_->database()->OpenCursor(
637 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 673 transaction, object_store_id, index_id,
638 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), direction, 674 base::MakeUnique<IndexedDBKeyRange>(key_range), direction, key_only,
639 key_only, task_type, std::move(callbacks)); 675 task_type, std::move(callbacks));
640 } 676 }
641 677
642 void DatabaseImpl::IDBThreadHelper::Count( 678 void DatabaseImpl::IDBThreadHelper::Count(
643 int64_t transaction_id, 679 int64_t transaction_id,
644 int64_t object_store_id, 680 int64_t object_store_id,
645 int64_t index_id, 681 int64_t index_id,
646 const IndexedDBKeyRange& key_range, 682 const IndexedDBKeyRange& key_range,
647 scoped_refptr<IndexedDBCallbacks> callbacks) { 683 scoped_refptr<IndexedDBCallbacks> callbacks) {
648 if (!connection_->IsConnected()) 684 if (!connection_->IsConnected())
649 return; 685 return;
650 686
651 connection_->database()->Count( 687 IndexedDBTransaction* transaction =
652 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 688 connection_->GetTransaction(transaction_id);
653 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), 689 if (!transaction)
654 std::move(callbacks)); 690 return;
691
692 connection_->database()->Count(transaction, object_store_id, index_id,
693 base::MakeUnique<IndexedDBKeyRange>(key_range),
694 std::move(callbacks));
655 } 695 }
656 696
657 void DatabaseImpl::IDBThreadHelper::DeleteRange( 697 void DatabaseImpl::IDBThreadHelper::DeleteRange(
658 int64_t transaction_id, 698 int64_t transaction_id,
659 int64_t object_store_id, 699 int64_t object_store_id,
660 const IndexedDBKeyRange& key_range, 700 const IndexedDBKeyRange& key_range,
661 scoped_refptr<IndexedDBCallbacks> callbacks) { 701 scoped_refptr<IndexedDBCallbacks> callbacks) {
662 if (!connection_->IsConnected()) 702 if (!connection_->IsConnected())
663 return; 703 return;
664 704
705 IndexedDBTransaction* transaction =
706 connection_->GetTransaction(transaction_id);
707 if (!transaction)
708 return;
709
665 connection_->database()->DeleteRange( 710 connection_->database()->DeleteRange(
666 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 711 transaction, object_store_id,
667 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks)); 712 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks));
668 } 713 }
669 714
670 void DatabaseImpl::IDBThreadHelper::Clear( 715 void DatabaseImpl::IDBThreadHelper::Clear(
671 int64_t transaction_id, 716 int64_t transaction_id,
672 int64_t object_store_id, 717 int64_t object_store_id,
673 scoped_refptr<IndexedDBCallbacks> callbacks) { 718 scoped_refptr<IndexedDBCallbacks> callbacks) {
674 if (!connection_->IsConnected()) 719 if (!connection_->IsConnected())
675 return; 720 return;
676 721
677 connection_->database()->Clear( 722 IndexedDBTransaction* transaction =
678 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 723 connection_->GetTransaction(transaction_id);
679 callbacks); 724 if (!transaction)
725 return;
726
727 connection_->database()->Clear(transaction, object_store_id, callbacks);
680 } 728 }
681 729
682 void DatabaseImpl::IDBThreadHelper::CreateIndex( 730 void DatabaseImpl::IDBThreadHelper::CreateIndex(
683 int64_t transaction_id, 731 int64_t transaction_id,
684 int64_t object_store_id, 732 int64_t object_store_id,
685 int64_t index_id, 733 int64_t index_id,
686 const base::string16& name, 734 const base::string16& name,
687 const IndexedDBKeyPath& key_path, 735 const IndexedDBKeyPath& key_path,
688 bool unique, 736 bool unique,
689 bool multi_entry) { 737 bool multi_entry) {
690 if (!connection_->IsConnected()) 738 if (!connection_->IsConnected())
691 return; 739 return;
692 740
693 connection_->database()->CreateIndex( 741 IndexedDBTransaction* transaction =
694 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 742 connection_->GetTransaction(transaction_id);
695 index_id, name, key_path, unique, multi_entry); 743 if (!transaction)
744 return;
745
746 connection_->database()->CreateIndex(transaction, object_store_id, index_id,
747 name, key_path, unique, multi_entry);
696 } 748 }
697 749
698 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id, 750 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id,
699 int64_t object_store_id, 751 int64_t object_store_id,
700 int64_t index_id) { 752 int64_t index_id) {
701 if (!connection_->IsConnected()) 753 if (!connection_->IsConnected())
702 return; 754 return;
703 755
704 connection_->database()->DeleteIndex( 756 IndexedDBTransaction* transaction =
705 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 757 connection_->GetTransaction(transaction_id);
706 index_id); 758 if (!transaction)
759 return;
760
761 connection_->database()->DeleteIndex(transaction, object_store_id, index_id);
707 } 762 }
708 763
709 void DatabaseImpl::IDBThreadHelper::RenameIndex( 764 void DatabaseImpl::IDBThreadHelper::RenameIndex(
710 int64_t transaction_id, 765 int64_t transaction_id,
711 int64_t object_store_id, 766 int64_t object_store_id,
712 int64_t index_id, 767 int64_t index_id,
713 const base::string16& new_name) { 768 const base::string16& new_name) {
714 if (!connection_->IsConnected()) 769 if (!connection_->IsConnected())
715 return; 770 return;
716 771
717 connection_->database()->RenameIndex( 772 IndexedDBTransaction* transaction =
718 dispatcher_host_->HostTransactionId(transaction_id), object_store_id, 773 connection_->GetTransaction(transaction_id);
719 index_id, new_name); 774 if (!transaction)
775 return;
776
777 connection_->database()->RenameIndex(transaction, object_store_id, index_id,
778 new_name);
720 } 779 }
721 780
722 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) { 781 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) {
723 if (!connection_->IsConnected()) 782 if (!connection_->IsConnected())
724 return; 783 return;
725 784
726 connection_->database()->Abort( 785 IndexedDBTransaction* transaction =
727 dispatcher_host_->HostTransactionId(transaction_id)); 786 connection_->GetTransaction(transaction_id);
787 if (!transaction)
788 return;
789
790 connection_->AbortTransaction(transaction);
728 } 791 }
729 792
730 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) { 793 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) {
731 if (!connection_->IsConnected()) 794 if (!connection_->IsConnected())
732 return; 795 return;
733 796
734 int64_t host_transaction_id = 797 IndexedDBTransaction* transaction =
735 dispatcher_host_->HostTransactionId(transaction_id); 798 connection_->GetTransaction(transaction_id);
736 // May have been aborted by back end before front-end could request commit. 799 if (!transaction)
737 int64_t transaction_size;
738 if (!dispatcher_host_->GetTransactionSize(host_transaction_id,
739 &transaction_size))
740 return; 800 return;
741 801
742 // Always allow empty or delete-only transactions. 802 // Always allow empty or delete-only transactions.
743 if (transaction_size == 0) { 803 if (transaction->size() == 0) {
744 connection_->database()->Commit(host_transaction_id); 804 connection_->database()->Commit(transaction);
745 return; 805 return;
746 } 806 }
747 807
748 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota( 808 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota(
749 dispatcher_host_->context()->TaskRunner(), origin_.GetURL(), 809 dispatcher_host_->context()->TaskRunner(), origin_.GetURL(),
750 storage::kStorageTypeTemporary, 810 storage::kStorageTypeTemporary,
751 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, 811 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit,
752 weak_factory_.GetWeakPtr(), transaction_id)); 812 weak_factory_.GetWeakPtr(), transaction_id));
753 } 813 }
754 814
755 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( 815 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit(
756 int64_t transaction_id, 816 int64_t transaction_id,
757 storage::QuotaStatusCode status, 817 storage::QuotaStatusCode status,
758 int64_t usage, 818 int64_t usage,
759 int64_t quota) { 819 int64_t quota) {
760 // May have disconnected while quota check was pending. 820 // May have disconnected while quota check was pending.
761 if (!connection_->IsConnected()) 821 if (!connection_->IsConnected())
762 return; 822 return;
763 823
764 int64_t host_transaction_id = 824 IndexedDBTransaction* transaction =
765 dispatcher_host_->HostTransactionId(transaction_id); 825 connection_->GetTransaction(transaction_id);
766 // May have aborted while quota check was pending. 826 if (!transaction)
767 int64_t transaction_size;
768 if (!dispatcher_host_->GetTransactionSize(host_transaction_id,
769 &transaction_size))
770 return; 827 return;
771 828
772 if (status == storage::kQuotaStatusOk && usage + transaction_size <= quota) { 829 if (status == storage::kQuotaStatusOk &&
773 connection_->database()->Commit(host_transaction_id); 830 usage + transaction->size() <= quota) {
831 connection_->database()->Commit(transaction);
774 } else { 832 } else {
775 connection_->database()->Abort( 833 connection_->AbortTransaction(
776 host_transaction_id, 834 transaction,
777 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); 835 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError));
778 } 836 }
779 } 837 }
780 838
781 } // namespace content 839 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698