| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 pending_->child_process_id); | 235 pending_->child_process_id); |
| 236 DCHECK_EQ(db_->connections_.count(connection_.get()), 1UL); | 236 DCHECK_EQ(db_->connections_.count(connection_.get()), 1UL); |
| 237 | 237 |
| 238 std::vector<int64_t> object_store_ids; | 238 std::vector<int64_t> object_store_ids; |
| 239 IndexedDBTransaction* transaction = db_->CreateTransaction( | 239 IndexedDBTransaction* transaction = db_->CreateTransaction( |
| 240 pending_->transaction_id, connection_.get(), object_store_ids, | 240 pending_->transaction_id, connection_.get(), object_store_ids, |
| 241 blink::kWebIDBTransactionModeVersionChange); | 241 blink::kWebIDBTransactionModeVersionChange); |
| 242 | 242 |
| 243 DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction()); | 243 DCHECK(db_->transaction_coordinator_.IsRunningVersionChangeTransaction()); |
| 244 transaction->ScheduleTask( | 244 transaction->ScheduleTask( |
| 245 base::Bind(&IndexedDBDatabase::VersionChangeOperation, db_, | 245 base::BindOnce(&IndexedDBDatabase::VersionChangeOperation, db_, |
| 246 pending_->version, pending_->callbacks)); | 246 pending_->version, pending_->callbacks)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 // Called when the upgrade transaction has started executing. | 249 // Called when the upgrade transaction has started executing. |
| 250 void UpgradeTransactionStarted(int64_t old_version) override { | 250 void UpgradeTransactionStarted(int64_t old_version) override { |
| 251 DCHECK(connection_); | 251 DCHECK(connection_); |
| 252 pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_), | 252 pending_->callbacks->OnUpgradeNeeded(old_version, std::move(connection_), |
| 253 db_->metadata_, | 253 db_->metadata_, |
| 254 pending_->data_loss_info); | 254 pending_->data_loss_info); |
| 255 } | 255 } |
| 256 | 256 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 object_store_metadata.name, | 584 object_store_metadata.name, |
| 585 object_store_metadata.key_path, | 585 object_store_metadata.key_path, |
| 586 object_store_metadata.auto_increment); | 586 object_store_metadata.auto_increment); |
| 587 if (!s.ok()) { | 587 if (!s.ok()) { |
| 588 ReportErrorWithDetails(s, "Internal error creating object store."); | 588 ReportErrorWithDetails(s, "Internal error creating object store."); |
| 589 return; | 589 return; |
| 590 } | 590 } |
| 591 | 591 |
| 592 AddObjectStore(object_store_metadata, object_store_id); | 592 AddObjectStore(object_store_metadata, object_store_id); |
| 593 transaction->ScheduleAbortTask( | 593 transaction->ScheduleAbortTask( |
| 594 base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, | 594 base::BindOnce(&IndexedDBDatabase::CreateObjectStoreAbortOperation, this, |
| 595 this, | 595 object_store_id)); |
| 596 object_store_id)); | |
| 597 } | 596 } |
| 598 | 597 |
| 599 void IndexedDBDatabase::DeleteObjectStore(IndexedDBTransaction* transaction, | 598 void IndexedDBDatabase::DeleteObjectStore(IndexedDBTransaction* transaction, |
| 600 int64_t object_store_id) { | 599 int64_t object_store_id) { |
| 601 DCHECK(transaction); | 600 DCHECK(transaction); |
| 602 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", | 601 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStore", "txn.id", |
| 603 transaction->id()); | 602 transaction->id()); |
| 604 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); | 603 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); |
| 605 | 604 |
| 606 if (!ValidateObjectStoreId(object_store_id)) | 605 if (!ValidateObjectStoreId(object_store_id)) |
| 607 return; | 606 return; |
| 608 | 607 |
| 609 transaction->ScheduleTask( | 608 transaction->ScheduleTask(base::BindOnce( |
| 610 base::Bind(&IndexedDBDatabase::DeleteObjectStoreOperation, | 609 &IndexedDBDatabase::DeleteObjectStoreOperation, this, object_store_id)); |
| 611 this, | |
| 612 object_store_id)); | |
| 613 } | 610 } |
| 614 | 611 |
| 615 void IndexedDBDatabase::RenameObjectStore(IndexedDBTransaction* transaction, | 612 void IndexedDBDatabase::RenameObjectStore(IndexedDBTransaction* transaction, |
| 616 int64_t object_store_id, | 613 int64_t object_store_id, |
| 617 const base::string16& new_name) { | 614 const base::string16& new_name) { |
| 618 DCHECK(transaction); | 615 DCHECK(transaction); |
| 619 IDB_TRACE1("IndexedDBDatabase::RenameObjectStore", "txn.id", | 616 IDB_TRACE1("IndexedDBDatabase::RenameObjectStore", "txn.id", |
| 620 transaction->id()); | 617 transaction->id()); |
| 621 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); | 618 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); |
| 622 | 619 |
| 623 if (!ValidateObjectStoreId(object_store_id)) | 620 if (!ValidateObjectStoreId(object_store_id)) |
| 624 return; | 621 return; |
| 625 | 622 |
| 626 // Store renaming is done synchronously, as it may be followed by | 623 // Store renaming is done synchronously, as it may be followed by |
| 627 // index creation (also sync) since preemptive OpenCursor/SetIndexKeys | 624 // index creation (also sync) since preemptive OpenCursor/SetIndexKeys |
| 628 // may follow. | 625 // may follow. |
| 629 const IndexedDBObjectStoreMetadata object_store_metadata = | 626 const IndexedDBObjectStoreMetadata object_store_metadata = |
| 630 metadata_.object_stores[object_store_id]; | 627 metadata_.object_stores[object_store_id]; |
| 631 | 628 |
| 632 leveldb::Status s = | 629 leveldb::Status s = |
| 633 backing_store_->RenameObjectStore(transaction->BackingStoreTransaction(), | 630 backing_store_->RenameObjectStore(transaction->BackingStoreTransaction(), |
| 634 transaction->database()->id(), | 631 transaction->database()->id(), |
| 635 object_store_metadata.id, new_name); | 632 object_store_metadata.id, new_name); |
| 636 if (!s.ok()) { | 633 if (!s.ok()) { |
| 637 ReportErrorWithDetails(s, "Internal error renaming object store."); | 634 ReportErrorWithDetails(s, "Internal error renaming object store."); |
| 638 return; | 635 return; |
| 639 } | 636 } |
| 640 | 637 |
| 641 transaction->ScheduleAbortTask( | 638 transaction->ScheduleAbortTask( |
| 642 base::Bind(&IndexedDBDatabase::RenameObjectStoreAbortOperation, | 639 base::BindOnce(&IndexedDBDatabase::RenameObjectStoreAbortOperation, this, |
| 643 this, | 640 object_store_id, object_store_metadata.name)); |
| 644 object_store_id, | |
| 645 object_store_metadata.name)); | |
| 646 SetObjectStoreName(object_store_id, new_name); | 641 SetObjectStoreName(object_store_id, new_name); |
| 647 } | 642 } |
| 648 | 643 |
| 649 void IndexedDBDatabase::CreateIndex(IndexedDBTransaction* transaction, | 644 void IndexedDBDatabase::CreateIndex(IndexedDBTransaction* transaction, |
| 650 int64_t object_store_id, | 645 int64_t object_store_id, |
| 651 int64_t index_id, | 646 int64_t index_id, |
| 652 const base::string16& name, | 647 const base::string16& name, |
| 653 const IndexedDBKeyPath& key_path, | 648 const IndexedDBKeyPath& key_path, |
| 654 bool unique, | 649 bool unique, |
| 655 bool multi_entry) { | 650 bool multi_entry) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 682 base::string16 error_string = | 677 base::string16 error_string = |
| 683 ASCIIToUTF16("Internal error creating index '") + | 678 ASCIIToUTF16("Internal error creating index '") + |
| 684 index_metadata.name + ASCIIToUTF16("'."); | 679 index_metadata.name + ASCIIToUTF16("'."); |
| 685 transaction->Abort(IndexedDBDatabaseError( | 680 transaction->Abort(IndexedDBDatabaseError( |
| 686 blink::kWebIDBDatabaseExceptionUnknownError, error_string)); | 681 blink::kWebIDBDatabaseExceptionUnknownError, error_string)); |
| 687 return; | 682 return; |
| 688 } | 683 } |
| 689 | 684 |
| 690 AddIndex(object_store_id, index_metadata, index_id); | 685 AddIndex(object_store_id, index_metadata, index_id); |
| 691 transaction->ScheduleAbortTask( | 686 transaction->ScheduleAbortTask( |
| 692 base::Bind(&IndexedDBDatabase::CreateIndexAbortOperation, | 687 base::BindOnce(&IndexedDBDatabase::CreateIndexAbortOperation, this, |
| 693 this, | 688 object_store_id, index_id)); |
| 694 object_store_id, | |
| 695 index_id)); | |
| 696 } | 689 } |
| 697 | 690 |
| 698 void IndexedDBDatabase::CreateIndexAbortOperation(int64_t object_store_id, | 691 void IndexedDBDatabase::CreateIndexAbortOperation(int64_t object_store_id, |
| 699 int64_t index_id) { | 692 int64_t index_id) { |
| 700 IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); | 693 IDB_TRACE("IndexedDBDatabase::CreateIndexAbortOperation"); |
| 701 RemoveIndex(object_store_id, index_id); | 694 RemoveIndex(object_store_id, index_id); |
| 702 } | 695 } |
| 703 | 696 |
| 704 void IndexedDBDatabase::DeleteIndex(IndexedDBTransaction* transaction, | 697 void IndexedDBDatabase::DeleteIndex(IndexedDBTransaction* transaction, |
| 705 int64_t object_store_id, | 698 int64_t object_store_id, |
| 706 int64_t index_id) { | 699 int64_t index_id) { |
| 707 DCHECK(transaction); | 700 DCHECK(transaction); |
| 708 IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction->id()); | 701 IDB_TRACE1("IndexedDBDatabase::DeleteIndex", "txn.id", transaction->id()); |
| 709 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); | 702 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); |
| 710 | 703 |
| 711 if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) | 704 if (!ValidateObjectStoreIdAndIndexId(object_store_id, index_id)) |
| 712 return; | 705 return; |
| 713 | 706 |
| 714 transaction->ScheduleTask( | 707 transaction->ScheduleTask( |
| 715 base::Bind(&IndexedDBDatabase::DeleteIndexOperation, | 708 base::BindOnce(&IndexedDBDatabase::DeleteIndexOperation, this, |
| 716 this, | 709 object_store_id, index_id)); |
| 717 object_store_id, | |
| 718 index_id)); | |
| 719 } | 710 } |
| 720 | 711 |
| 721 leveldb::Status IndexedDBDatabase::DeleteIndexOperation( | 712 leveldb::Status IndexedDBDatabase::DeleteIndexOperation( |
| 722 int64_t object_store_id, | 713 int64_t object_store_id, |
| 723 int64_t index_id, | 714 int64_t index_id, |
| 724 IndexedDBTransaction* transaction) { | 715 IndexedDBTransaction* transaction) { |
| 725 IDB_TRACE1( | 716 IDB_TRACE1( |
| 726 "IndexedDBDatabase::DeleteIndexOperation", "txn.id", transaction->id()); | 717 "IndexedDBDatabase::DeleteIndexOperation", "txn.id", transaction->id()); |
| 727 | 718 |
| 728 const IndexedDBIndexMetadata index_metadata = | 719 const IndexedDBIndexMetadata index_metadata = |
| 729 metadata_.object_stores[object_store_id].indexes[index_id]; | 720 metadata_.object_stores[object_store_id].indexes[index_id]; |
| 730 | 721 |
| 731 leveldb::Status s = | 722 leveldb::Status s = |
| 732 backing_store_->DeleteIndex(transaction->BackingStoreTransaction(), | 723 backing_store_->DeleteIndex(transaction->BackingStoreTransaction(), |
| 733 transaction->database()->id(), | 724 transaction->database()->id(), |
| 734 object_store_id, | 725 object_store_id, |
| 735 index_id); | 726 index_id); |
| 736 if (!s.ok()) | 727 if (!s.ok()) |
| 737 return s; | 728 return s; |
| 738 | 729 |
| 739 RemoveIndex(object_store_id, index_id); | 730 RemoveIndex(object_store_id, index_id); |
| 740 transaction->ScheduleAbortTask( | 731 transaction->ScheduleAbortTask( |
| 741 base::Bind(&IndexedDBDatabase::DeleteIndexAbortOperation, | 732 base::BindOnce(&IndexedDBDatabase::DeleteIndexAbortOperation, this, |
| 742 this, | 733 object_store_id, index_metadata)); |
| 743 object_store_id, | |
| 744 index_metadata)); | |
| 745 return s; | 734 return s; |
| 746 } | 735 } |
| 747 | 736 |
| 748 void IndexedDBDatabase::DeleteIndexAbortOperation( | 737 void IndexedDBDatabase::DeleteIndexAbortOperation( |
| 749 int64_t object_store_id, | 738 int64_t object_store_id, |
| 750 const IndexedDBIndexMetadata& index_metadata) { | 739 const IndexedDBIndexMetadata& index_metadata) { |
| 751 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); | 740 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); |
| 752 AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); | 741 AddIndex(object_store_id, index_metadata, IndexedDBIndexMetadata::kInvalidId); |
| 753 } | 742 } |
| 754 | 743 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 774 transaction->database()->id(), | 763 transaction->database()->id(), |
| 775 object_store_id, | 764 object_store_id, |
| 776 index_id, | 765 index_id, |
| 777 new_name); | 766 new_name); |
| 778 if (!s.ok()) { | 767 if (!s.ok()) { |
| 779 ReportErrorWithDetails(s, "Internal error renaming index."); | 768 ReportErrorWithDetails(s, "Internal error renaming index."); |
| 780 return; | 769 return; |
| 781 } | 770 } |
| 782 | 771 |
| 783 transaction->ScheduleAbortTask( | 772 transaction->ScheduleAbortTask( |
| 784 base::Bind(&IndexedDBDatabase::RenameIndexAbortOperation, | 773 base::BindOnce(&IndexedDBDatabase::RenameIndexAbortOperation, this, |
| 785 this, | 774 object_store_id, index_id, index_metadata.name)); |
| 786 object_store_id, | |
| 787 index_id, | |
| 788 index_metadata.name)); | |
| 789 SetIndexName(object_store_id, index_id, new_name); | 775 SetIndexName(object_store_id, index_id, new_name); |
| 790 } | 776 } |
| 791 | 777 |
| 792 void IndexedDBDatabase::RenameIndexAbortOperation( | 778 void IndexedDBDatabase::RenameIndexAbortOperation( |
| 793 int64_t object_store_id, | 779 int64_t object_store_id, |
| 794 int64_t index_id, | 780 int64_t index_id, |
| 795 const base::string16& old_name) { | 781 const base::string16& old_name) { |
| 796 IDB_TRACE("IndexedDBDatabase::RenameIndexAbortOperation"); | 782 IDB_TRACE("IndexedDBDatabase::RenameIndexAbortOperation"); |
| 797 SetIndexName(object_store_id, index_id, old_name); | 783 SetIndexName(object_store_id, index_id, old_name); |
| 798 } | 784 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 std::unique_ptr<IndexedDBKeyRange> key_range, | 888 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 903 bool key_only, | 889 bool key_only, |
| 904 int64_t max_count, | 890 int64_t max_count, |
| 905 scoped_refptr<IndexedDBCallbacks> callbacks) { | 891 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 906 DCHECK(transaction); | 892 DCHECK(transaction); |
| 907 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction->id()); | 893 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction->id()); |
| 908 | 894 |
| 909 if (!ValidateObjectStoreId(object_store_id)) | 895 if (!ValidateObjectStoreId(object_store_id)) |
| 910 return; | 896 return; |
| 911 | 897 |
| 912 transaction->ScheduleTask(base::Bind( | 898 transaction->ScheduleTask(base::BindOnce( |
| 913 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, | 899 &IndexedDBDatabase::GetAllOperation, this, object_store_id, index_id, |
| 914 base::Passed(&key_range), | 900 base::Passed(&key_range), |
| 915 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 901 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, |
| 916 max_count, callbacks)); | 902 max_count, callbacks)); |
| 917 } | 903 } |
| 918 | 904 |
| 919 void IndexedDBDatabase::Get(IndexedDBTransaction* transaction, | 905 void IndexedDBDatabase::Get(IndexedDBTransaction* transaction, |
| 920 int64_t object_store_id, | 906 int64_t object_store_id, |
| 921 int64_t index_id, | 907 int64_t index_id, |
| 922 std::unique_ptr<IndexedDBKeyRange> key_range, | 908 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 923 bool key_only, | 909 bool key_only, |
| 924 scoped_refptr<IndexedDBCallbacks> callbacks) { | 910 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 925 DCHECK(transaction); | 911 DCHECK(transaction); |
| 926 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction->id()); | 912 IDB_TRACE1("IndexedDBDatabase::Get", "txn.id", transaction->id()); |
| 927 | 913 |
| 928 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 914 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) |
| 929 return; | 915 return; |
| 930 | 916 |
| 931 transaction->ScheduleTask(base::Bind( | 917 transaction->ScheduleTask(base::BindOnce( |
| 932 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, | 918 &IndexedDBDatabase::GetOperation, this, object_store_id, index_id, |
| 933 base::Passed(&key_range), | 919 base::Passed(&key_range), |
| 934 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, | 920 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE, |
| 935 callbacks)); | 921 callbacks)); |
| 936 } | 922 } |
| 937 | 923 |
| 938 leveldb::Status IndexedDBDatabase::GetOperation( | 924 leveldb::Status IndexedDBDatabase::GetOperation( |
| 939 int64_t object_store_id, | 925 int64_t object_store_id, |
| 940 int64_t index_id, | 926 int64_t index_id, |
| 941 std::unique_ptr<IndexedDBKeyRange> key_range, | 927 std::unique_ptr<IndexedDBKeyRange> key_range, |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 DCHECK(value); | 1252 DCHECK(value); |
| 1267 std::unique_ptr<PutOperationParams> params( | 1253 std::unique_ptr<PutOperationParams> params( |
| 1268 base::MakeUnique<PutOperationParams>()); | 1254 base::MakeUnique<PutOperationParams>()); |
| 1269 params->object_store_id = object_store_id; | 1255 params->object_store_id = object_store_id; |
| 1270 params->value.swap(*value); | 1256 params->value.swap(*value); |
| 1271 params->handles.swap(*handles); | 1257 params->handles.swap(*handles); |
| 1272 params->key = std::move(key); | 1258 params->key = std::move(key); |
| 1273 params->put_mode = put_mode; | 1259 params->put_mode = put_mode; |
| 1274 params->callbacks = callbacks; | 1260 params->callbacks = callbacks; |
| 1275 params->index_keys = index_keys; | 1261 params->index_keys = index_keys; |
| 1276 transaction->ScheduleTask(base::Bind( | 1262 transaction->ScheduleTask(base::BindOnce(&IndexedDBDatabase::PutOperation, |
| 1277 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); | 1263 this, base::Passed(¶ms))); |
| 1278 } | 1264 } |
| 1279 | 1265 |
| 1280 leveldb::Status IndexedDBDatabase::PutOperation( | 1266 leveldb::Status IndexedDBDatabase::PutOperation( |
| 1281 std::unique_ptr<PutOperationParams> params, | 1267 std::unique_ptr<PutOperationParams> params, |
| 1282 IndexedDBTransaction* transaction) { | 1268 IndexedDBTransaction* transaction) { |
| 1283 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id()); | 1269 IDB_TRACE1("IndexedDBDatabase::PutOperation", "txn.id", transaction->id()); |
| 1284 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); | 1270 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); |
| 1285 bool key_was_generated = false; | 1271 bool key_was_generated = false; |
| 1286 leveldb::Status s = leveldb::Status::OK(); | 1272 leveldb::Status s = leveldb::Status::OK(); |
| 1287 | 1273 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 } | 1450 } |
| 1465 | 1451 |
| 1466 void IndexedDBDatabase::SetIndexesReady(IndexedDBTransaction* transaction, | 1452 void IndexedDBDatabase::SetIndexesReady(IndexedDBTransaction* transaction, |
| 1467 int64_t, | 1453 int64_t, |
| 1468 const std::vector<int64_t>& index_ids) { | 1454 const std::vector<int64_t>& index_ids) { |
| 1469 DCHECK(transaction); | 1455 DCHECK(transaction); |
| 1470 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); | 1456 DCHECK_EQ(transaction->mode(), blink::kWebIDBTransactionModeVersionChange); |
| 1471 | 1457 |
| 1472 transaction->ScheduleTask( | 1458 transaction->ScheduleTask( |
| 1473 blink::kWebIDBTaskTypePreemptive, | 1459 blink::kWebIDBTaskTypePreemptive, |
| 1474 base::Bind(&IndexedDBDatabase::SetIndexesReadyOperation, this, | 1460 base::BindOnce(&IndexedDBDatabase::SetIndexesReadyOperation, this, |
| 1475 index_ids.size())); | 1461 index_ids.size())); |
| 1476 } | 1462 } |
| 1477 | 1463 |
| 1478 leveldb::Status IndexedDBDatabase::SetIndexesReadyOperation( | 1464 leveldb::Status IndexedDBDatabase::SetIndexesReadyOperation( |
| 1479 size_t index_count, | 1465 size_t index_count, |
| 1480 IndexedDBTransaction* transaction) { | 1466 IndexedDBTransaction* transaction) { |
| 1481 for (size_t i = 0; i < index_count; ++i) | 1467 for (size_t i = 0; i < index_count; ++i) |
| 1482 transaction->DidCompletePreemptiveEvent(); | 1468 transaction->DidCompletePreemptiveEvent(); |
| 1483 return leveldb::Status::OK(); | 1469 return leveldb::Status::OK(); |
| 1484 } | 1470 } |
| 1485 | 1471 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1515 std::unique_ptr<OpenCursorOperationParams> params( | 1501 std::unique_ptr<OpenCursorOperationParams> params( |
| 1516 base::MakeUnique<OpenCursorOperationParams>()); | 1502 base::MakeUnique<OpenCursorOperationParams>()); |
| 1517 params->object_store_id = object_store_id; | 1503 params->object_store_id = object_store_id; |
| 1518 params->index_id = index_id; | 1504 params->index_id = index_id; |
| 1519 params->key_range = std::move(key_range); | 1505 params->key_range = std::move(key_range); |
| 1520 params->direction = direction; | 1506 params->direction = direction; |
| 1521 params->cursor_type = | 1507 params->cursor_type = |
| 1522 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; | 1508 key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; |
| 1523 params->task_type = task_type; | 1509 params->task_type = task_type; |
| 1524 params->callbacks = callbacks; | 1510 params->callbacks = callbacks; |
| 1525 transaction->ScheduleTask(base::Bind( | 1511 transaction->ScheduleTask(base::BindOnce( |
| 1526 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(¶ms))); | 1512 &IndexedDBDatabase::OpenCursorOperation, this, base::Passed(¶ms))); |
| 1527 } | 1513 } |
| 1528 | 1514 |
| 1529 leveldb::Status IndexedDBDatabase::OpenCursorOperation( | 1515 leveldb::Status IndexedDBDatabase::OpenCursorOperation( |
| 1530 std::unique_ptr<OpenCursorOperationParams> params, | 1516 std::unique_ptr<OpenCursorOperationParams> params, |
| 1531 IndexedDBTransaction* transaction) { | 1517 IndexedDBTransaction* transaction) { |
| 1532 IDB_TRACE1( | 1518 IDB_TRACE1( |
| 1533 "IndexedDBDatabase::OpenCursorOperation", "txn.id", transaction->id()); | 1519 "IndexedDBDatabase::OpenCursorOperation", "txn.id", transaction->id()); |
| 1534 | 1520 |
| 1535 // The frontend has begun indexing, so this pauses the transaction | 1521 // The frontend has begun indexing, so this pauses the transaction |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 int64_t object_store_id, | 1594 int64_t object_store_id, |
| 1609 int64_t index_id, | 1595 int64_t index_id, |
| 1610 std::unique_ptr<IndexedDBKeyRange> key_range, | 1596 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 1611 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1597 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1612 DCHECK(transaction); | 1598 DCHECK(transaction); |
| 1613 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction->id()); | 1599 IDB_TRACE1("IndexedDBDatabase::Count", "txn.id", transaction->id()); |
| 1614 | 1600 |
| 1615 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) | 1601 if (!ValidateObjectStoreIdAndOptionalIndexId(object_store_id, index_id)) |
| 1616 return; | 1602 return; |
| 1617 | 1603 |
| 1618 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::CountOperation, | 1604 transaction->ScheduleTask( |
| 1619 this, | 1605 base::BindOnce(&IndexedDBDatabase::CountOperation, this, object_store_id, |
| 1620 object_store_id, | 1606 index_id, base::Passed(&key_range), callbacks)); |
| 1621 index_id, | |
| 1622 base::Passed(&key_range), | |
| 1623 callbacks)); | |
| 1624 } | 1607 } |
| 1625 | 1608 |
| 1626 leveldb::Status IndexedDBDatabase::CountOperation( | 1609 leveldb::Status IndexedDBDatabase::CountOperation( |
| 1627 int64_t object_store_id, | 1610 int64_t object_store_id, |
| 1628 int64_t index_id, | 1611 int64_t index_id, |
| 1629 std::unique_ptr<IndexedDBKeyRange> key_range, | 1612 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 1630 scoped_refptr<IndexedDBCallbacks> callbacks, | 1613 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1631 IndexedDBTransaction* transaction) { | 1614 IndexedDBTransaction* transaction) { |
| 1632 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id()); | 1615 IDB_TRACE1("IndexedDBDatabase::CountOperation", "txn.id", transaction->id()); |
| 1633 uint32_t count = 0; | 1616 uint32_t count = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 int64_t object_store_id, | 1650 int64_t object_store_id, |
| 1668 std::unique_ptr<IndexedDBKeyRange> key_range, | 1651 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 1669 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1652 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1670 DCHECK(transaction); | 1653 DCHECK(transaction); |
| 1671 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction->id()); | 1654 IDB_TRACE1("IndexedDBDatabase::DeleteRange", "txn.id", transaction->id()); |
| 1672 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); | 1655 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); |
| 1673 | 1656 |
| 1674 if (!ValidateObjectStoreId(object_store_id)) | 1657 if (!ValidateObjectStoreId(object_store_id)) |
| 1675 return; | 1658 return; |
| 1676 | 1659 |
| 1677 transaction->ScheduleTask(base::Bind(&IndexedDBDatabase::DeleteRangeOperation, | 1660 transaction->ScheduleTask( |
| 1678 this, | 1661 base::BindOnce(&IndexedDBDatabase::DeleteRangeOperation, this, |
| 1679 object_store_id, | 1662 object_store_id, base::Passed(&key_range), callbacks)); |
| 1680 base::Passed(&key_range), | |
| 1681 callbacks)); | |
| 1682 } | 1663 } |
| 1683 | 1664 |
| 1684 leveldb::Status IndexedDBDatabase::DeleteRangeOperation( | 1665 leveldb::Status IndexedDBDatabase::DeleteRangeOperation( |
| 1685 int64_t object_store_id, | 1666 int64_t object_store_id, |
| 1686 std::unique_ptr<IndexedDBKeyRange> key_range, | 1667 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 1687 scoped_refptr<IndexedDBCallbacks> callbacks, | 1668 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1688 IndexedDBTransaction* transaction) { | 1669 IndexedDBTransaction* transaction) { |
| 1689 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", | 1670 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", |
| 1690 transaction->id()); | 1671 transaction->id()); |
| 1691 leveldb::Status s = | 1672 leveldb::Status s = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1702 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, | 1683 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, |
| 1703 int64_t object_store_id, | 1684 int64_t object_store_id, |
| 1704 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1685 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1705 DCHECK(transaction); | 1686 DCHECK(transaction); |
| 1706 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); | 1687 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); |
| 1707 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); | 1688 DCHECK_NE(transaction->mode(), blink::kWebIDBTransactionModeReadOnly); |
| 1708 | 1689 |
| 1709 if (!ValidateObjectStoreId(object_store_id)) | 1690 if (!ValidateObjectStoreId(object_store_id)) |
| 1710 return; | 1691 return; |
| 1711 | 1692 |
| 1712 transaction->ScheduleTask(base::Bind( | 1693 transaction->ScheduleTask(base::BindOnce(&IndexedDBDatabase::ClearOperation, |
| 1713 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); | 1694 this, object_store_id, callbacks)); |
| 1714 } | 1695 } |
| 1715 | 1696 |
| 1716 leveldb::Status IndexedDBDatabase::ClearOperation( | 1697 leveldb::Status IndexedDBDatabase::ClearOperation( |
| 1717 int64_t object_store_id, | 1698 int64_t object_store_id, |
| 1718 scoped_refptr<IndexedDBCallbacks> callbacks, | 1699 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1719 IndexedDBTransaction* transaction) { | 1700 IndexedDBTransaction* transaction) { |
| 1720 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); | 1701 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); |
| 1721 leveldb::Status s = backing_store_->ClearObjectStore( | 1702 leveldb::Status s = backing_store_->ClearObjectStore( |
| 1722 transaction->BackingStoreTransaction(), id(), object_store_id); | 1703 transaction->BackingStoreTransaction(), id(), object_store_id); |
| 1723 if (!s.ok()) | 1704 if (!s.ok()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1740 metadata_.object_stores[object_store_id]; | 1721 metadata_.object_stores[object_store_id]; |
| 1741 leveldb::Status s = | 1722 leveldb::Status s = |
| 1742 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), | 1723 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), |
| 1743 transaction->database()->id(), | 1724 transaction->database()->id(), |
| 1744 object_store_id); | 1725 object_store_id); |
| 1745 if (!s.ok()) | 1726 if (!s.ok()) |
| 1746 return s; | 1727 return s; |
| 1747 | 1728 |
| 1748 RemoveObjectStore(object_store_id); | 1729 RemoveObjectStore(object_store_id); |
| 1749 transaction->ScheduleAbortTask( | 1730 transaction->ScheduleAbortTask( |
| 1750 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, | 1731 base::BindOnce(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, this, |
| 1751 this, | 1732 object_store_metadata)); |
| 1752 object_store_metadata)); | |
| 1753 return s; | 1733 return s; |
| 1754 } | 1734 } |
| 1755 | 1735 |
| 1756 leveldb::Status IndexedDBDatabase::VersionChangeOperation( | 1736 leveldb::Status IndexedDBDatabase::VersionChangeOperation( |
| 1757 int64_t version, | 1737 int64_t version, |
| 1758 scoped_refptr<IndexedDBCallbacks> callbacks, | 1738 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1759 IndexedDBTransaction* transaction) { | 1739 IndexedDBTransaction* transaction) { |
| 1760 IDB_TRACE1( | 1740 IDB_TRACE1( |
| 1761 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); | 1741 "IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); |
| 1762 int64_t old_version = metadata_.version; | 1742 int64_t old_version = metadata_.version; |
| 1763 DCHECK_GT(version, old_version); | 1743 DCHECK_GT(version, old_version); |
| 1764 | 1744 |
| 1765 backing_store_->UpdateIDBDatabaseIntVersion( | 1745 backing_store_->UpdateIDBDatabaseIntVersion( |
| 1766 transaction->BackingStoreTransaction(), id(), version); | 1746 transaction->BackingStoreTransaction(), id(), version); |
| 1767 | 1747 |
| 1768 transaction->ScheduleAbortTask( | 1748 transaction->ScheduleAbortTask( |
| 1769 base::Bind(&IndexedDBDatabase::VersionChangeAbortOperation, this, | 1749 base::BindOnce(&IndexedDBDatabase::VersionChangeAbortOperation, this, |
| 1770 metadata_.version)); | 1750 metadata_.version)); |
| 1771 metadata_.version = version; | 1751 metadata_.version = version; |
| 1772 | 1752 |
| 1773 active_request_->UpgradeTransactionStarted(old_version); | 1753 active_request_->UpgradeTransactionStarted(old_version); |
| 1774 return leveldb::Status::OK(); | 1754 return leveldb::Status::OK(); |
| 1775 } | 1755 } |
| 1776 | 1756 |
| 1777 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, | 1757 void IndexedDBDatabase::TransactionFinished(IndexedDBTransaction* transaction, |
| 1778 bool committed) { | 1758 bool committed) { |
| 1779 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", | 1759 IDB_TRACE1("IndexedDBTransaction::TransactionFinished", "txn.id", |
| 1780 transaction->id()); | 1760 transaction->id()); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 if (status.IsCorruption()) { | 1946 if (status.IsCorruption()) { |
| 1967 IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, | 1947 IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, |
| 1968 message); | 1948 message); |
| 1969 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1949 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1970 } else { | 1950 } else { |
| 1971 factory_->HandleBackingStoreFailure(backing_store_->origin()); | 1951 factory_->HandleBackingStoreFailure(backing_store_->origin()); |
| 1972 } | 1952 } |
| 1973 } | 1953 } |
| 1974 | 1954 |
| 1975 } // namespace content | 1955 } // namespace content |
| OLD | NEW |