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