| 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 <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/browser/indexed_db/indexed_db_return_value.h" | 31 #include "content/browser/indexed_db/indexed_db_return_value.h" |
| 32 #include "content/browser/indexed_db/indexed_db_tracing.h" | 32 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 33 #include "content/browser/indexed_db/indexed_db_transaction.h" | 33 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 34 #include "content/browser/indexed_db/indexed_db_value.h" | 34 #include "content/browser/indexed_db/indexed_db_value.h" |
| 35 #include "content/common/indexed_db/indexed_db_constants.h" | 35 #include "content/common/indexed_db/indexed_db_constants.h" |
| 36 #include "content/common/indexed_db/indexed_db_key_path.h" | 36 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 37 #include "content/common/indexed_db/indexed_db_key_range.h" | 37 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 38 #include "storage/browser/blob/blob_data_handle.h" | 38 #include "storage/browser/blob/blob_data_handle.h" |
| 39 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 39 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 40 #include "third_party/leveldatabase/env_chromium.h" | 40 #include "third_party/leveldatabase/env_chromium.h" |
| 41 #include "url/origin.h" |
| 41 | 42 |
| 42 using base::ASCIIToUTF16; | 43 using base::ASCIIToUTF16; |
| 43 using base::Int64ToString16; | 44 using base::Int64ToString16; |
| 44 using blink::WebIDBKeyTypeNumber; | 45 using blink::WebIDBKeyTypeNumber; |
| 45 | 46 |
| 46 namespace content { | 47 namespace content { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 // Used for WebCore.IndexedDB.Schema.ObjectStore.KeyPathType and | 51 // Used for WebCore.IndexedDB.Schema.ObjectStore.KeyPathType and |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 object_store_metadata.name, | 341 object_store_metadata.name, |
| 341 object_store_metadata.key_path, | 342 object_store_metadata.key_path, |
| 342 object_store_metadata.auto_increment); | 343 object_store_metadata.auto_increment); |
| 343 if (!s.ok()) { | 344 if (!s.ok()) { |
| 344 IndexedDBDatabaseError error( | 345 IndexedDBDatabaseError error( |
| 345 blink::WebIDBDatabaseExceptionUnknownError, | 346 blink::WebIDBDatabaseExceptionUnknownError, |
| 346 ASCIIToUTF16("Internal error creating object store '") + | 347 ASCIIToUTF16("Internal error creating object store '") + |
| 347 object_store_metadata.name + ASCIIToUTF16("'.")); | 348 object_store_metadata.name + ASCIIToUTF16("'.")); |
| 348 transaction->Abort(error); | 349 transaction->Abort(error); |
| 349 if (s.IsCorruption()) | 350 if (s.IsCorruption()) |
| 350 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 351 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 351 error); | |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 | 354 |
| 355 AddObjectStore(object_store_metadata, object_store_id); | 355 AddObjectStore(object_store_metadata, object_store_id); |
| 356 transaction->ScheduleAbortTask( | 356 transaction->ScheduleAbortTask( |
| 357 base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, | 357 base::Bind(&IndexedDBDatabase::CreateObjectStoreAbortOperation, |
| 358 this, | 358 this, |
| 359 object_store_id)); | 359 object_store_id)); |
| 360 } | 360 } |
| 361 | 361 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 object_store_id, | 471 object_store_id, |
| 472 index_id); | 472 index_id); |
| 473 if (!s.ok()) { | 473 if (!s.ok()) { |
| 474 base::string16 error_string = | 474 base::string16 error_string = |
| 475 ASCIIToUTF16("Internal error deleting index '") + | 475 ASCIIToUTF16("Internal error deleting index '") + |
| 476 index_metadata.name + ASCIIToUTF16("'."); | 476 index_metadata.name + ASCIIToUTF16("'."); |
| 477 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 477 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 478 error_string); | 478 error_string); |
| 479 transaction->Abort(error); | 479 transaction->Abort(error); |
| 480 if (s.IsCorruption()) | 480 if (s.IsCorruption()) |
| 481 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 481 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 482 error); | |
| 483 return; | 482 return; |
| 484 } | 483 } |
| 485 | 484 |
| 486 RemoveIndex(object_store_id, index_id); | 485 RemoveIndex(object_store_id, index_id); |
| 487 transaction->ScheduleAbortTask( | 486 transaction->ScheduleAbortTask( |
| 488 base::Bind(&IndexedDBDatabase::DeleteIndexAbortOperation, | 487 base::Bind(&IndexedDBDatabase::DeleteIndexAbortOperation, |
| 489 this, | 488 this, |
| 490 object_store_id, | 489 object_store_id, |
| 491 index_metadata)); | 490 index_metadata)); |
| 492 } | 491 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 *key_range, | 629 *key_range, |
| 631 blink::WebIDBCursorDirectionNext, | 630 blink::WebIDBCursorDirectionNext, |
| 632 &s); | 631 &s); |
| 633 } | 632 } |
| 634 | 633 |
| 635 if (!s.ok()) { | 634 if (!s.ok()) { |
| 636 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); | 635 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); |
| 637 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 636 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 638 "Internal error deleting data in range"); | 637 "Internal error deleting data in range"); |
| 639 if (s.IsCorruption()) { | 638 if (s.IsCorruption()) { |
| 640 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 639 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 641 error); | |
| 642 } | 640 } |
| 643 } | 641 } |
| 644 | 642 |
| 645 if (!backing_store_cursor) { | 643 if (!backing_store_cursor) { |
| 646 callbacks->OnSuccess(); | 644 callbacks->OnSuccess(); |
| 647 return; | 645 return; |
| 648 } | 646 } |
| 649 | 647 |
| 650 key = &backing_store_cursor->key(); | 648 key = &backing_store_cursor->key(); |
| 651 } | 649 } |
| 652 | 650 |
| 653 std::unique_ptr<IndexedDBKey> primary_key; | 651 std::unique_ptr<IndexedDBKey> primary_key; |
| 654 if (index_id == IndexedDBIndexMetadata::kInvalidId) { | 652 if (index_id == IndexedDBIndexMetadata::kInvalidId) { |
| 655 // Object Store Retrieval Operation | 653 // Object Store Retrieval Operation |
| 656 IndexedDBReturnValue value; | 654 IndexedDBReturnValue value; |
| 657 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 655 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
| 658 id(), | 656 id(), |
| 659 object_store_id, | 657 object_store_id, |
| 660 *key, | 658 *key, |
| 661 &value); | 659 &value); |
| 662 if (!s.ok()) { | 660 if (!s.ok()) { |
| 663 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 661 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 664 "Internal error in GetRecord."); | 662 "Internal error in GetRecord."); |
| 665 callbacks->OnError(error); | 663 callbacks->OnError(error); |
| 666 | 664 |
| 667 if (s.IsCorruption()) | 665 if (s.IsCorruption()) |
| 668 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 666 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 669 error); | |
| 670 return; | 667 return; |
| 671 } | 668 } |
| 672 | 669 |
| 673 if (value.empty()) { | 670 if (value.empty()) { |
| 674 callbacks->OnSuccess(); | 671 callbacks->OnSuccess(); |
| 675 return; | 672 return; |
| 676 } | 673 } |
| 677 | 674 |
| 678 if (object_store_metadata.auto_increment && | 675 if (object_store_metadata.auto_increment && |
| 679 !object_store_metadata.key_path.IsNull()) { | 676 !object_store_metadata.key_path.IsNull()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 691 id(), | 688 id(), |
| 692 object_store_id, | 689 object_store_id, |
| 693 index_id, | 690 index_id, |
| 694 *key, | 691 *key, |
| 695 &primary_key); | 692 &primary_key); |
| 696 if (!s.ok()) { | 693 if (!s.ok()) { |
| 697 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 694 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 698 "Internal error in GetPrimaryKeyViaIndex."); | 695 "Internal error in GetPrimaryKeyViaIndex."); |
| 699 callbacks->OnError(error); | 696 callbacks->OnError(error); |
| 700 if (s.IsCorruption()) | 697 if (s.IsCorruption()) |
| 701 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 698 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 702 error); | |
| 703 return; | 699 return; |
| 704 } | 700 } |
| 705 if (!primary_key) { | 701 if (!primary_key) { |
| 706 callbacks->OnSuccess(); | 702 callbacks->OnSuccess(); |
| 707 return; | 703 return; |
| 708 } | 704 } |
| 709 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 705 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
| 710 // Index Value Retrieval Operation | 706 // Index Value Retrieval Operation |
| 711 callbacks->OnSuccess(*primary_key); | 707 callbacks->OnSuccess(*primary_key); |
| 712 return; | 708 return; |
| 713 } | 709 } |
| 714 | 710 |
| 715 // Index Referenced Value Retrieval Operation | 711 // Index Referenced Value Retrieval Operation |
| 716 IndexedDBReturnValue value; | 712 IndexedDBReturnValue value; |
| 717 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 713 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
| 718 id(), | 714 id(), |
| 719 object_store_id, | 715 object_store_id, |
| 720 *primary_key, | 716 *primary_key, |
| 721 &value); | 717 &value); |
| 722 if (!s.ok()) { | 718 if (!s.ok()) { |
| 723 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 719 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 724 "Internal error in GetRecord."); | 720 "Internal error in GetRecord."); |
| 725 callbacks->OnError(error); | 721 callbacks->OnError(error); |
| 726 if (s.IsCorruption()) | 722 if (s.IsCorruption()) |
| 727 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 723 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 728 error); | |
| 729 return; | 724 return; |
| 730 } | 725 } |
| 731 | 726 |
| 732 if (value.empty()) { | 727 if (value.empty()) { |
| 733 callbacks->OnSuccess(); | 728 callbacks->OnSuccess(); |
| 734 return; | 729 return; |
| 735 } | 730 } |
| 736 if (object_store_metadata.auto_increment && | 731 if (object_store_metadata.auto_increment && |
| 737 !object_store_metadata.key_path.IsNull()) { | 732 !object_store_metadata.key_path.IsNull()) { |
| 738 value.primary_key = *primary_key; | 733 value.primary_key = *primary_key; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 index_id, *key_range, blink::WebIDBCursorDirectionNext, &s); | 784 index_id, *key_range, blink::WebIDBCursorDirectionNext, &s); |
| 790 } | 785 } |
| 791 } | 786 } |
| 792 | 787 |
| 793 if (!s.ok()) { | 788 if (!s.ok()) { |
| 794 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); | 789 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); |
| 795 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 790 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 796 "Internal error in GetAllOperation"); | 791 "Internal error in GetAllOperation"); |
| 797 callbacks->OnError(error); | 792 callbacks->OnError(error); |
| 798 if (s.IsCorruption()) { | 793 if (s.IsCorruption()) { |
| 799 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 794 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 800 error); | |
| 801 } | 795 } |
| 802 return; | 796 return; |
| 803 } | 797 } |
| 804 | 798 |
| 805 std::vector<IndexedDBKey> found_keys; | 799 std::vector<IndexedDBKey> found_keys; |
| 806 std::vector<IndexedDBReturnValue> found_values; | 800 std::vector<IndexedDBReturnValue> found_values; |
| 807 if (!cursor) { | 801 if (!cursor) { |
| 808 // Doesn't matter if key or value array here - will be empty array when it | 802 // Doesn't matter if key or value array here - will be empty array when it |
| 809 // hits JavaScript. | 803 // hits JavaScript. |
| 810 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); | 804 callbacks->OnSuccessArray(&found_values, object_store_metadata.key_path); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 823 cursor_valid = cursor->Continue(&s); | 817 cursor_valid = cursor->Continue(&s); |
| 824 } else { | 818 } else { |
| 825 cursor_valid = cursor->FirstSeek(&s); | 819 cursor_valid = cursor->FirstSeek(&s); |
| 826 did_first_seek = true; | 820 did_first_seek = true; |
| 827 } | 821 } |
| 828 if (!s.ok()) { | 822 if (!s.ok()) { |
| 829 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 823 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 830 "Internal error in GetAllOperation."); | 824 "Internal error in GetAllOperation."); |
| 831 callbacks->OnError(error); | 825 callbacks->OnError(error); |
| 832 if (s.IsCorruption()) | 826 if (s.IsCorruption()) |
| 833 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 827 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 834 error); | |
| 835 return; | 828 return; |
| 836 } | 829 } |
| 837 | 830 |
| 838 if (!cursor_valid) | 831 if (!cursor_valid) |
| 839 break; | 832 break; |
| 840 | 833 |
| 841 IndexedDBReturnValue return_value; | 834 IndexedDBReturnValue return_value; |
| 842 IndexedDBKey return_key; | 835 IndexedDBKey return_key; |
| 843 | 836 |
| 844 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 837 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 id(), | 991 id(), |
| 999 params->object_store_id, | 992 params->object_store_id, |
| 1000 *key, | 993 *key, |
| 1001 &record_identifier, | 994 &record_identifier, |
| 1002 &found); | 995 &found); |
| 1003 if (!s.ok()) { | 996 if (!s.ok()) { |
| 1004 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 997 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1005 "Internal error checking key existence."); | 998 "Internal error checking key existence."); |
| 1006 params->callbacks->OnError(error); | 999 params->callbacks->OnError(error); |
| 1007 if (s.IsCorruption()) | 1000 if (s.IsCorruption()) |
| 1008 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1001 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1009 error); | |
| 1010 return; | 1002 return; |
| 1011 } | 1003 } |
| 1012 if (found) { | 1004 if (found) { |
| 1013 params->callbacks->OnError( | 1005 params->callbacks->OnError( |
| 1014 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, | 1006 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, |
| 1015 "Key already exists in the object store.")); | 1007 "Key already exists in the object store.")); |
| 1016 return; | 1008 return; |
| 1017 } | 1009 } |
| 1018 } | 1010 } |
| 1019 | 1011 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 *key, | 1043 *key, |
| 1052 ¶ms->value, | 1044 ¶ms->value, |
| 1053 ¶ms->handles, | 1045 ¶ms->handles, |
| 1054 &record_identifier); | 1046 &record_identifier); |
| 1055 if (!s.ok()) { | 1047 if (!s.ok()) { |
| 1056 IndexedDBDatabaseError error( | 1048 IndexedDBDatabaseError error( |
| 1057 blink::WebIDBDatabaseExceptionUnknownError, | 1049 blink::WebIDBDatabaseExceptionUnknownError, |
| 1058 "Internal error: backing store error performing put/add."); | 1050 "Internal error: backing store error performing put/add."); |
| 1059 params->callbacks->OnError(error); | 1051 params->callbacks->OnError(error); |
| 1060 if (s.IsCorruption()) | 1052 if (s.IsCorruption()) |
| 1061 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1053 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1062 error); | |
| 1063 return; | 1054 return; |
| 1064 } | 1055 } |
| 1065 { | 1056 { |
| 1066 IDB_TRACE1("IndexedDBDatabase::PutOperation.UpdateIndexes", "txn.id", | 1057 IDB_TRACE1("IndexedDBDatabase::PutOperation.UpdateIndexes", "txn.id", |
| 1067 transaction->id()); | 1058 transaction->id()); |
| 1068 for (size_t i = 0; i < index_writers.size(); ++i) { | 1059 for (size_t i = 0; i < index_writers.size(); ++i) { |
| 1069 IndexWriter* index_writer = index_writers[i]; | 1060 IndexWriter* index_writer = index_writers[i]; |
| 1070 index_writer->WriteIndexKeys(record_identifier, backing_store_.get(), | 1061 index_writer->WriteIndexKeys(record_identifier, backing_store_.get(), |
| 1071 transaction->BackingStoreTransaction(), id(), | 1062 transaction->BackingStoreTransaction(), id(), |
| 1072 params->object_store_id); | 1063 params->object_store_id); |
| 1073 } | 1064 } |
| 1074 } | 1065 } |
| 1075 | 1066 |
| 1076 if (object_store.auto_increment && | 1067 if (object_store.auto_increment && |
| 1077 params->put_mode != blink::WebIDBPutModeCursorUpdate && | 1068 params->put_mode != blink::WebIDBPutModeCursorUpdate && |
| 1078 key->type() == WebIDBKeyTypeNumber) { | 1069 key->type() == WebIDBKeyTypeNumber) { |
| 1079 IDB_TRACE1("IndexedDBDatabase::PutOperation.AutoIncrement", "txn.id", | 1070 IDB_TRACE1("IndexedDBDatabase::PutOperation.AutoIncrement", "txn.id", |
| 1080 transaction->id()); | 1071 transaction->id()); |
| 1081 leveldb::Status s = UpdateKeyGenerator(backing_store_.get(), | 1072 leveldb::Status s = UpdateKeyGenerator(backing_store_.get(), |
| 1082 transaction, | 1073 transaction, |
| 1083 id(), | 1074 id(), |
| 1084 params->object_store_id, | 1075 params->object_store_id, |
| 1085 *key, | 1076 *key, |
| 1086 !key_was_generated); | 1077 !key_was_generated); |
| 1087 if (!s.ok()) { | 1078 if (!s.ok()) { |
| 1088 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1079 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1089 "Internal error updating key generator."); | 1080 "Internal error updating key generator."); |
| 1090 params->callbacks->OnError(error); | 1081 params->callbacks->OnError(error); |
| 1091 if (s.IsCorruption()) | 1082 if (s.IsCorruption()) |
| 1092 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1083 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1093 error); | |
| 1094 return; | 1084 return; |
| 1095 } | 1085 } |
| 1096 } | 1086 } |
| 1097 { | 1087 { |
| 1098 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", | 1088 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", |
| 1099 transaction->id()); | 1089 transaction->id()); |
| 1100 params->callbacks->OnSuccess(*key); | 1090 params->callbacks->OnSuccess(*key); |
| 1101 } | 1091 } |
| 1102 } | 1092 } |
| 1103 | 1093 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1120 metadata_.id, | 1110 metadata_.id, |
| 1121 object_store_id, | 1111 object_store_id, |
| 1122 *primary_key, | 1112 *primary_key, |
| 1123 &record_identifier, | 1113 &record_identifier, |
| 1124 &found); | 1114 &found); |
| 1125 if (!s.ok()) { | 1115 if (!s.ok()) { |
| 1126 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1116 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1127 "Internal error setting index keys."); | 1117 "Internal error setting index keys."); |
| 1128 transaction->Abort(error); | 1118 transaction->Abort(error); |
| 1129 if (s.IsCorruption()) | 1119 if (s.IsCorruption()) |
| 1130 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1120 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1131 error); | |
| 1132 return; | 1121 return; |
| 1133 } | 1122 } |
| 1134 if (!found) { | 1123 if (!found) { |
| 1135 transaction->Abort(IndexedDBDatabaseError( | 1124 transaction->Abort(IndexedDBDatabaseError( |
| 1136 blink::WebIDBDatabaseExceptionUnknownError, | 1125 blink::WebIDBDatabaseExceptionUnknownError, |
| 1137 "Internal error setting index keys for object store.")); | 1126 "Internal error setting index keys for object store.")); |
| 1138 return; | 1127 return; |
| 1139 } | 1128 } |
| 1140 | 1129 |
| 1141 ScopedVector<IndexWriter> index_writers; | 1130 ScopedVector<IndexWriter> index_writers; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 params->direction, | 1288 params->direction, |
| 1300 &s); | 1289 &s); |
| 1301 } | 1290 } |
| 1302 } | 1291 } |
| 1303 | 1292 |
| 1304 if (!s.ok()) { | 1293 if (!s.ok()) { |
| 1305 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); | 1294 DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); |
| 1306 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1295 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1307 "Internal error opening cursor operation"); | 1296 "Internal error opening cursor operation"); |
| 1308 if (s.IsCorruption()) { | 1297 if (s.IsCorruption()) { |
| 1309 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1298 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1310 error); | |
| 1311 } | 1299 } |
| 1312 } | 1300 } |
| 1313 | 1301 |
| 1314 if (!backing_store_cursor) { | 1302 if (!backing_store_cursor) { |
| 1315 // Why is Success being called? | 1303 // Why is Success being called? |
| 1316 params->callbacks->OnSuccess(nullptr); | 1304 params->callbacks->OnSuccess(nullptr); |
| 1317 return; | 1305 return; |
| 1318 } | 1306 } |
| 1319 | 1307 |
| 1320 scoped_refptr<IndexedDBCursor> cursor = | 1308 scoped_refptr<IndexedDBCursor> cursor = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 index_id, | 1360 index_id, |
| 1373 *key_range, | 1361 *key_range, |
| 1374 blink::WebIDBCursorDirectionNext, | 1362 blink::WebIDBCursorDirectionNext, |
| 1375 &s); | 1363 &s); |
| 1376 } | 1364 } |
| 1377 if (!s.ok()) { | 1365 if (!s.ok()) { |
| 1378 DLOG(ERROR) << "Unable perform count operation: " << s.ToString(); | 1366 DLOG(ERROR) << "Unable perform count operation: " << s.ToString(); |
| 1379 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1367 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1380 "Internal error performing count operation"); | 1368 "Internal error performing count operation"); |
| 1381 if (s.IsCorruption()) { | 1369 if (s.IsCorruption()) { |
| 1382 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1370 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1383 error); | |
| 1384 } | 1371 } |
| 1385 } | 1372 } |
| 1386 if (!backing_store_cursor) { | 1373 if (!backing_store_cursor) { |
| 1387 callbacks->OnSuccess(count); | 1374 callbacks->OnSuccess(count); |
| 1388 return; | 1375 return; |
| 1389 } | 1376 } |
| 1390 | 1377 |
| 1391 do { | 1378 do { |
| 1392 ++count; | 1379 ++count; |
| 1393 } while (backing_store_cursor->Continue(&s)); | 1380 } while (backing_store_cursor->Continue(&s)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 id(), | 1417 id(), |
| 1431 object_store_id, | 1418 object_store_id, |
| 1432 *key_range); | 1419 *key_range); |
| 1433 if (!s.ok()) { | 1420 if (!s.ok()) { |
| 1434 base::string16 error_string = | 1421 base::string16 error_string = |
| 1435 ASCIIToUTF16("Internal error deleting data in range"); | 1422 ASCIIToUTF16("Internal error deleting data in range"); |
| 1436 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1423 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1437 error_string); | 1424 error_string); |
| 1438 transaction->Abort(error); | 1425 transaction->Abort(error); |
| 1439 if (s.IsCorruption()) { | 1426 if (s.IsCorruption()) { |
| 1440 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1427 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1441 error); | |
| 1442 } | 1428 } |
| 1443 return; | 1429 return; |
| 1444 } | 1430 } |
| 1445 callbacks->OnSuccess(); | 1431 callbacks->OnSuccess(); |
| 1446 } | 1432 } |
| 1447 | 1433 |
| 1448 void IndexedDBDatabase::Clear(int64_t transaction_id, | 1434 void IndexedDBDatabase::Clear(int64_t transaction_id, |
| 1449 int64_t object_store_id, | 1435 int64_t object_store_id, |
| 1450 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1436 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1451 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); | 1437 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1466 scoped_refptr<IndexedDBCallbacks> callbacks, | 1452 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1467 IndexedDBTransaction* transaction) { | 1453 IndexedDBTransaction* transaction) { |
| 1468 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); | 1454 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); |
| 1469 leveldb::Status s = backing_store_->ClearObjectStore( | 1455 leveldb::Status s = backing_store_->ClearObjectStore( |
| 1470 transaction->BackingStoreTransaction(), id(), object_store_id); | 1456 transaction->BackingStoreTransaction(), id(), object_store_id); |
| 1471 if (!s.ok()) { | 1457 if (!s.ok()) { |
| 1472 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1458 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1473 "Internal error clearing object store"); | 1459 "Internal error clearing object store"); |
| 1474 callbacks->OnError(error); | 1460 callbacks->OnError(error); |
| 1475 if (s.IsCorruption()) { | 1461 if (s.IsCorruption()) { |
| 1476 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1462 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1477 error); | |
| 1478 } | 1463 } |
| 1479 return; | 1464 return; |
| 1480 } | 1465 } |
| 1481 callbacks->OnSuccess(); | 1466 callbacks->OnSuccess(); |
| 1482 } | 1467 } |
| 1483 | 1468 |
| 1484 void IndexedDBDatabase::DeleteObjectStoreOperation( | 1469 void IndexedDBDatabase::DeleteObjectStoreOperation( |
| 1485 int64_t object_store_id, | 1470 int64_t object_store_id, |
| 1486 IndexedDBTransaction* transaction) { | 1471 IndexedDBTransaction* transaction) { |
| 1487 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", | 1472 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", |
| 1488 "txn.id", | 1473 "txn.id", |
| 1489 transaction->id()); | 1474 transaction->id()); |
| 1490 | 1475 |
| 1491 const IndexedDBObjectStoreMetadata object_store_metadata = | 1476 const IndexedDBObjectStoreMetadata object_store_metadata = |
| 1492 metadata_.object_stores[object_store_id]; | 1477 metadata_.object_stores[object_store_id]; |
| 1493 leveldb::Status s = | 1478 leveldb::Status s = |
| 1494 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), | 1479 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), |
| 1495 transaction->database()->id(), | 1480 transaction->database()->id(), |
| 1496 object_store_id); | 1481 object_store_id); |
| 1497 if (!s.ok()) { | 1482 if (!s.ok()) { |
| 1498 base::string16 error_string = | 1483 base::string16 error_string = |
| 1499 ASCIIToUTF16("Internal error deleting object store '") + | 1484 ASCIIToUTF16("Internal error deleting object store '") + |
| 1500 object_store_metadata.name + ASCIIToUTF16("'."); | 1485 object_store_metadata.name + ASCIIToUTF16("'."); |
| 1501 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1486 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1502 error_string); | 1487 error_string); |
| 1503 transaction->Abort(error); | 1488 transaction->Abort(error); |
| 1504 if (s.IsCorruption()) | 1489 if (s.IsCorruption()) |
| 1505 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), | 1490 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1506 error); | |
| 1507 return; | 1491 return; |
| 1508 } | 1492 } |
| 1509 | 1493 |
| 1510 RemoveObjectStore(object_store_id); | 1494 RemoveObjectStore(object_store_id); |
| 1511 transaction->ScheduleAbortTask( | 1495 transaction->ScheduleAbortTask( |
| 1512 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, | 1496 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, |
| 1513 this, | 1497 this, |
| 1514 object_store_metadata)); | 1498 object_store_metadata)); |
| 1515 } | 1499 } |
| 1516 | 1500 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 | 1559 |
| 1576 // Connection queue is now unblocked. | 1560 // Connection queue is now unblocked. |
| 1577 ProcessPendingCalls(); | 1561 ProcessPendingCalls(); |
| 1578 } | 1562 } |
| 1579 } | 1563 } |
| 1580 | 1564 |
| 1581 void IndexedDBDatabase::TransactionCommitFailed(const leveldb::Status& status) { | 1565 void IndexedDBDatabase::TransactionCommitFailed(const leveldb::Status& status) { |
| 1582 if (status.IsCorruption()) { | 1566 if (status.IsCorruption()) { |
| 1583 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1567 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1584 "Error committing transaction"); | 1568 "Error committing transaction"); |
| 1585 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), error); | 1569 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1586 } else { | 1570 } else { |
| 1587 factory_->HandleBackingStoreFailure(backing_store_->origin_url()); | 1571 factory_->HandleBackingStoreFailure(backing_store_->origin()); |
| 1588 } | 1572 } |
| 1589 } | 1573 } |
| 1590 | 1574 |
| 1591 size_t IndexedDBDatabase::ConnectionCount() const { | 1575 size_t IndexedDBDatabase::ConnectionCount() const { |
| 1592 // This does not include pending open calls, as those should not block version | 1576 // This does not include pending open calls, as those should not block version |
| 1593 // changes and deletes. | 1577 // changes and deletes. |
| 1594 return connections_.size(); | 1578 return connections_.size(); |
| 1595 } | 1579 } |
| 1596 | 1580 |
| 1597 size_t IndexedDBDatabase::PendingOpenCount() const { | 1581 size_t IndexedDBDatabase::PendingOpenCount() const { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 void IndexedDBDatabase::DeleteDatabaseFinal( | 1838 void IndexedDBDatabase::DeleteDatabaseFinal( |
| 1855 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1839 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1856 DCHECK(!IsDeleteDatabaseBlocked()); | 1840 DCHECK(!IsDeleteDatabaseBlocked()); |
| 1857 DCHECK(backing_store_.get()); | 1841 DCHECK(backing_store_.get()); |
| 1858 leveldb::Status s = backing_store_->DeleteDatabase(metadata_.name); | 1842 leveldb::Status s = backing_store_->DeleteDatabase(metadata_.name); |
| 1859 if (!s.ok()) { | 1843 if (!s.ok()) { |
| 1860 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1844 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1861 "Internal error deleting database."); | 1845 "Internal error deleting database."); |
| 1862 callbacks->OnError(error); | 1846 callbacks->OnError(error); |
| 1863 if (s.IsCorruption()) { | 1847 if (s.IsCorruption()) { |
| 1864 GURL origin_url = backing_store_->origin_url(); | 1848 url::Origin origin = backing_store_->origin(); |
| 1865 backing_store_ = NULL; | 1849 backing_store_ = NULL; |
| 1866 factory_->HandleBackingStoreCorruption(origin_url, error); | 1850 factory_->HandleBackingStoreCorruption(origin, error); |
| 1867 } | 1851 } |
| 1868 return; | 1852 return; |
| 1869 } | 1853 } |
| 1870 int64_t old_version = metadata_.version; | 1854 int64_t old_version = metadata_.version; |
| 1871 metadata_.id = kInvalidId; | 1855 metadata_.id = kInvalidId; |
| 1872 metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION; | 1856 metadata_.version = IndexedDBDatabaseMetadata::NO_VERSION; |
| 1873 metadata_.object_stores.clear(); | 1857 metadata_.object_stores.clear(); |
| 1874 callbacks->OnSuccess(old_version); | 1858 callbacks->OnSuccess(old_version); |
| 1875 factory_->DatabaseDeleted(identifier_); | 1859 factory_->DatabaseDeleted(identifier_); |
| 1876 } | 1860 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 "The connection was closed.")); | 1910 "The connection was closed.")); |
| 1927 pending_second_half_open_.reset(); | 1911 pending_second_half_open_.reset(); |
| 1928 } | 1912 } |
| 1929 | 1913 |
| 1930 ProcessPendingCalls(); | 1914 ProcessPendingCalls(); |
| 1931 | 1915 |
| 1932 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. | 1916 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. |
| 1933 if (!ConnectionCount() && !pending_open_calls_.size() && | 1917 if (!ConnectionCount() && !pending_open_calls_.size() && |
| 1934 !pending_delete_calls_.size()) { | 1918 !pending_delete_calls_.size()) { |
| 1935 DCHECK(transactions_.empty()); | 1919 DCHECK(transactions_.empty()); |
| 1936 | |
| 1937 const GURL origin_url = backing_store_->origin_url(); | |
| 1938 backing_store_ = NULL; | 1920 backing_store_ = NULL; |
| 1939 | |
| 1940 factory_->ReleaseDatabase(identifier_, forced); | 1921 factory_->ReleaseDatabase(identifier_, forced); |
| 1941 } | 1922 } |
| 1942 } | 1923 } |
| 1943 | 1924 |
| 1944 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 1925 void IndexedDBDatabase::CreateObjectStoreAbortOperation( |
| 1945 int64_t object_store_id, | 1926 int64_t object_store_id, |
| 1946 IndexedDBTransaction* transaction) { | 1927 IndexedDBTransaction* transaction) { |
| 1947 DCHECK(!transaction); | 1928 DCHECK(!transaction); |
| 1948 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); | 1929 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); |
| 1949 RemoveObjectStore(object_store_id); | 1930 RemoveObjectStore(object_store_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1960 | 1941 |
| 1961 void IndexedDBDatabase::VersionChangeAbortOperation( | 1942 void IndexedDBDatabase::VersionChangeAbortOperation( |
| 1962 int64_t previous_version, | 1943 int64_t previous_version, |
| 1963 IndexedDBTransaction* transaction) { | 1944 IndexedDBTransaction* transaction) { |
| 1964 DCHECK(!transaction); | 1945 DCHECK(!transaction); |
| 1965 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1946 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1966 metadata_.version = previous_version; | 1947 metadata_.version = previous_version; |
| 1967 } | 1948 } |
| 1968 | 1949 |
| 1969 } // namespace content | 1950 } // namespace content |
| OLD | NEW |