| 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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 check_current); | 691 check_current); |
| 692 } | 692 } |
| 693 | 693 |
| 694 struct IndexedDBDatabase::PutOperationParams { | 694 struct IndexedDBDatabase::PutOperationParams { |
| 695 PutOperationParams() {} | 695 PutOperationParams() {} |
| 696 int64 object_store_id; | 696 int64 object_store_id; |
| 697 std::string value; | 697 std::string value; |
| 698 scoped_ptr<IndexedDBKey> key; | 698 scoped_ptr<IndexedDBKey> key; |
| 699 IndexedDBDatabase::PutMode put_mode; | 699 IndexedDBDatabase::PutMode put_mode; |
| 700 scoped_refptr<IndexedDBCallbacks> callbacks; | 700 scoped_refptr<IndexedDBCallbacks> callbacks; |
| 701 std::vector<int64> index_ids; | |
| 702 std::vector<IndexKeys> index_keys; | 701 std::vector<IndexKeys> index_keys; |
| 703 | 702 |
| 704 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 703 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
| 705 }; | 704 }; |
| 706 | 705 |
| 707 void IndexedDBDatabase::Put(int64 transaction_id, | 706 void IndexedDBDatabase::Put(int64 transaction_id, |
| 708 int64 object_store_id, | 707 int64 object_store_id, |
| 709 std::string* value, | 708 std::string* value, |
| 710 scoped_ptr<IndexedDBKey> key, | 709 scoped_ptr<IndexedDBKey> key, |
| 711 PutMode put_mode, | 710 PutMode put_mode, |
| 712 scoped_refptr<IndexedDBCallbacks> callbacks, | 711 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 713 const std::vector<int64>& index_ids, | |
| 714 const std::vector<IndexKeys>& index_keys) { | 712 const std::vector<IndexKeys>& index_keys) { |
| 715 IDB_TRACE("IndexedDBDatabase::Put"); | 713 IDB_TRACE("IndexedDBDatabase::Put"); |
| 716 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 714 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 717 if (!transaction) | 715 if (!transaction) |
| 718 return; | 716 return; |
| 719 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 717 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
| 720 | 718 |
| 721 if (!ValidateObjectStoreId(object_store_id)) | 719 if (!ValidateObjectStoreId(object_store_id)) |
| 722 return; | 720 return; |
| 723 | 721 |
| 724 DCHECK(key); | 722 DCHECK(key); |
| 725 scoped_ptr<PutOperationParams> params(new PutOperationParams()); | 723 scoped_ptr<PutOperationParams> params(new PutOperationParams()); |
| 726 params->object_store_id = object_store_id; | 724 params->object_store_id = object_store_id; |
| 727 params->value.swap(*value); | 725 params->value.swap(*value); |
| 728 params->key = key.Pass(); | 726 params->key = key.Pass(); |
| 729 params->put_mode = put_mode; | 727 params->put_mode = put_mode; |
| 730 params->callbacks = callbacks; | 728 params->callbacks = callbacks; |
| 731 params->index_ids = index_ids; | |
| 732 params->index_keys = index_keys; | 729 params->index_keys = index_keys; |
| 733 transaction->ScheduleTask(base::Bind( | 730 transaction->ScheduleTask(base::Bind( |
| 734 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); | 731 &IndexedDBDatabase::PutOperation, this, base::Passed(¶ms))); |
| 735 } | 732 } |
| 736 | 733 |
| 737 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, | 734 void IndexedDBDatabase::PutOperation(scoped_ptr<PutOperationParams> params, |
| 738 IndexedDBTransaction* transaction) { | 735 IndexedDBTransaction* transaction) { |
| 739 IDB_TRACE("IndexedDBDatabase::PutOperation"); | 736 IDB_TRACE("IndexedDBDatabase::PutOperation"); |
| 740 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 737 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
| 741 DCHECK_EQ(params->index_ids.size(), params->index_keys.size()); | |
| 742 bool key_was_generated = false; | 738 bool key_was_generated = false; |
| 743 | 739 |
| 744 DCHECK(metadata_.object_stores.find(params->object_store_id) != | 740 DCHECK(metadata_.object_stores.find(params->object_store_id) != |
| 745 metadata_.object_stores.end()); | 741 metadata_.object_stores.end()); |
| 746 const IndexedDBObjectStoreMetadata& object_store = | 742 const IndexedDBObjectStoreMetadata& object_store = |
| 747 metadata_.object_stores[params->object_store_id]; | 743 metadata_.object_stores[params->object_store_id]; |
| 748 DCHECK(object_store.auto_increment || params->key->IsValid()); | 744 DCHECK(object_store.auto_increment || params->key->IsValid()); |
| 749 | 745 |
| 750 scoped_ptr<IndexedDBKey> key; | 746 scoped_ptr<IndexedDBKey> key; |
| 751 if (params->put_mode != IndexedDBDatabase::CURSOR_UPDATE && | 747 if (params->put_mode != IndexedDBDatabase::CURSOR_UPDATE && |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 788 |
| 793 ScopedVector<IndexWriter> index_writers; | 789 ScopedVector<IndexWriter> index_writers; |
| 794 base::string16 error_message; | 790 base::string16 error_message; |
| 795 bool obeys_constraints = false; | 791 bool obeys_constraints = false; |
| 796 bool backing_store_success = MakeIndexWriters(transaction, | 792 bool backing_store_success = MakeIndexWriters(transaction, |
| 797 backing_store_.get(), | 793 backing_store_.get(), |
| 798 id(), | 794 id(), |
| 799 object_store, | 795 object_store, |
| 800 *key, | 796 *key, |
| 801 key_was_generated, | 797 key_was_generated, |
| 802 params->index_ids, | |
| 803 params->index_keys, | 798 params->index_keys, |
| 804 &index_writers, | 799 &index_writers, |
| 805 &error_message, | 800 &error_message, |
| 806 &obeys_constraints); | 801 &obeys_constraints); |
| 807 if (!backing_store_success) { | 802 if (!backing_store_success) { |
| 808 params->callbacks->OnError(IndexedDBDatabaseError( | 803 params->callbacks->OnError(IndexedDBDatabaseError( |
| 809 blink::WebIDBDatabaseExceptionUnknownError, | 804 blink::WebIDBDatabaseExceptionUnknownError, |
| 810 "Internal error: backing store error updating index keys.")); | 805 "Internal error: backing store error updating index keys.")); |
| 811 return; | 806 return; |
| 812 } | 807 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 return; | 852 return; |
| 858 } | 853 } |
| 859 } | 854 } |
| 860 | 855 |
| 861 params->callbacks->OnSuccess(*key); | 856 params->callbacks->OnSuccess(*key); |
| 862 } | 857 } |
| 863 | 858 |
| 864 void IndexedDBDatabase::SetIndexKeys(int64 transaction_id, | 859 void IndexedDBDatabase::SetIndexKeys(int64 transaction_id, |
| 865 int64 object_store_id, | 860 int64 object_store_id, |
| 866 scoped_ptr<IndexedDBKey> primary_key, | 861 scoped_ptr<IndexedDBKey> primary_key, |
| 867 const std::vector<int64>& index_ids, | |
| 868 const std::vector<IndexKeys>& index_keys) { | 862 const std::vector<IndexKeys>& index_keys) { |
| 869 IDB_TRACE("IndexedDBDatabase::SetIndexKeys"); | 863 IDB_TRACE("IndexedDBDatabase::SetIndexKeys"); |
| 870 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 864 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 871 if (!transaction) | 865 if (!transaction) |
| 872 return; | 866 return; |
| 873 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); | 867 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); |
| 874 | 868 |
| 875 // TODO(alecflett): This method could be asynchronous, but we need to | 869 // TODO(alecflett): This method could be asynchronous, but we need to |
| 876 // evaluate if it's worth the extra complexity. | 870 // evaluate if it's worth the extra complexity. |
| 877 IndexedDBBackingStore::RecordIdentifier record_identifier; | 871 IndexedDBBackingStore::RecordIdentifier record_identifier; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 902 DCHECK(metadata_.object_stores.find(object_store_id) != | 896 DCHECK(metadata_.object_stores.find(object_store_id) != |
| 903 metadata_.object_stores.end()); | 897 metadata_.object_stores.end()); |
| 904 const IndexedDBObjectStoreMetadata& object_store_metadata = | 898 const IndexedDBObjectStoreMetadata& object_store_metadata = |
| 905 metadata_.object_stores[object_store_id]; | 899 metadata_.object_stores[object_store_id]; |
| 906 bool backing_store_success = MakeIndexWriters(transaction, | 900 bool backing_store_success = MakeIndexWriters(transaction, |
| 907 backing_store_, | 901 backing_store_, |
| 908 id(), | 902 id(), |
| 909 object_store_metadata, | 903 object_store_metadata, |
| 910 *primary_key, | 904 *primary_key, |
| 911 false, | 905 false, |
| 912 index_ids, | |
| 913 index_keys, | 906 index_keys, |
| 914 &index_writers, | 907 &index_writers, |
| 915 &error_message, | 908 &error_message, |
| 916 &obeys_constraints); | 909 &obeys_constraints); |
| 917 if (!backing_store_success) { | 910 if (!backing_store_success) { |
| 918 transaction->Abort(IndexedDBDatabaseError( | 911 transaction->Abort(IndexedDBDatabaseError( |
| 919 blink::WebIDBDatabaseExceptionUnknownError, | 912 blink::WebIDBDatabaseExceptionUnknownError, |
| 920 "Internal error: backing store error updating index keys.")); | 913 "Internal error: backing store error updating index keys.")); |
| 921 return; | 914 return; |
| 922 } | 915 } |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 const base::string16& previous_version, | 1664 const base::string16& previous_version, |
| 1672 int64 previous_int_version, | 1665 int64 previous_int_version, |
| 1673 IndexedDBTransaction* transaction) { | 1666 IndexedDBTransaction* transaction) { |
| 1674 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1667 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1675 DCHECK(!transaction); | 1668 DCHECK(!transaction); |
| 1676 metadata_.version = previous_version; | 1669 metadata_.version = previous_version; |
| 1677 metadata_.int_version = previous_int_version; | 1670 metadata_.int_version = previous_int_version; |
| 1678 } | 1671 } |
| 1679 | 1672 |
| 1680 } // namespace content | 1673 } // namespace content |
| OLD | NEW |