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

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

Issue 2276593002: Support renaming of IndexedDB indexes and object stores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test coverage for the (slightly incorrect) behavior in strict mode when our flag is not enabl… Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 } 1817 }
1818 1818
1819 if (!s.ok()) { 1819 if (!s.ok()) {
1820 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE); 1820 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE);
1821 return s; 1821 return s;
1822 } 1822 }
1823 1823
1824 return ClearObjectStore(transaction, database_id, object_store_id); 1824 return ClearObjectStore(transaction, database_id, object_store_id);
1825 } 1825 }
1826 1826
1827 leveldb::Status IndexedDBBackingStore::RenameObjectStore(
1828 IndexedDBBackingStore::Transaction* transaction,
1829 int64_t database_id,
1830 int64_t object_store_id,
1831 const base::string16& new_name) {
1832 IDB_TRACE("IndexedDBBackingStore::RenameObjectStore");
1833 if (!KeyPrefix::ValidIds(database_id, object_store_id))
1834 return InvalidDBKeyStatus();
1835 LevelDBTransaction* leveldb_transaction = transaction->transaction();
1836
1837 const std::string name_key = ObjectStoreMetaDataKey::Encode(
1838 database_id, object_store_id, ObjectStoreMetaDataKey::NAME);
1839 const std::string new_names_key = ObjectStoreNamesKey::Encode(
1840 database_id, new_name);
1841
1842 base::string16 old_name;
1843 bool found = false;
1844 leveldb::Status s =
1845 GetString(leveldb_transaction, name_key, &old_name, &found);
1846 if (!s.ok()) {
1847 INTERNAL_READ_ERROR_UNTESTED(DELETE_OBJECT_STORE);
1848 return s;
1849 }
1850 if (!found) {
1851 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE);
1852 return InternalInconsistencyStatus();
1853 }
1854 const std::string old_names_key = ObjectStoreNamesKey::Encode(
1855 database_id, old_name);
1856
1857 PutString(leveldb_transaction, name_key, new_name);
1858 PutInt(leveldb_transaction, new_names_key, object_store_id);
1859 leveldb_transaction->Remove(old_names_key);
1860 return s;
1861 }
1862
1827 leveldb::Status IndexedDBBackingStore::GetRecord( 1863 leveldb::Status IndexedDBBackingStore::GetRecord(
1828 IndexedDBBackingStore::Transaction* transaction, 1864 IndexedDBBackingStore::Transaction* transaction,
1829 int64_t database_id, 1865 int64_t database_id,
1830 int64_t object_store_id, 1866 int64_t object_store_id,
1831 const IndexedDBKey& key, 1867 const IndexedDBKey& key,
1832 IndexedDBValue* record) { 1868 IndexedDBValue* record) {
1833 IDB_TRACE("IndexedDBBackingStore::GetRecord"); 1869 IDB_TRACE("IndexedDBBackingStore::GetRecord");
1834 if (!KeyPrefix::ValidIds(database_id, object_store_id)) 1870 if (!KeyPrefix::ValidIds(database_id, object_store_id))
1835 return InvalidDBKeyStatus(); 1871 return InvalidDBKeyStatus();
1836 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 1872 LevelDBTransaction* leveldb_transaction = transaction->transaction();
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 s = DeleteRangeBasic(leveldb_transaction, index_data_start, index_data_end, 2895 s = DeleteRangeBasic(leveldb_transaction, index_data_start, index_data_end,
2860 true, &delete_count); 2896 true, &delete_count);
2861 } 2897 }
2862 2898
2863 if (!s.ok()) 2899 if (!s.ok())
2864 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX); 2900 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX);
2865 2901
2866 return s; 2902 return s;
2867 } 2903 }
2868 2904
2905 leveldb::Status IndexedDBBackingStore::RenameIndex(
2906 IndexedDBBackingStore::Transaction* transaction,
2907 int64_t database_id,
2908 int64_t object_store_id,
2909 int64_t index_id,
2910 const base::string16& new_name) {
2911 IDB_TRACE("IndexedDBBackingStore::RenameIndex");
2912 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id))
2913 return InvalidDBKeyStatus();
2914 LevelDBTransaction* leveldb_transaction = transaction->transaction();
2915
2916 const std::string name_key = IndexMetaDataKey::Encode(
2917 database_id, object_store_id, index_id, IndexMetaDataKey::NAME);
2918
2919 PutString(leveldb_transaction, name_key, new_name);
2920 return leveldb::Status::OK();
2921 }
2922
2869 leveldb::Status IndexedDBBackingStore::PutIndexDataForRecord( 2923 leveldb::Status IndexedDBBackingStore::PutIndexDataForRecord(
2870 IndexedDBBackingStore::Transaction* transaction, 2924 IndexedDBBackingStore::Transaction* transaction,
2871 int64_t database_id, 2925 int64_t database_id,
2872 int64_t object_store_id, 2926 int64_t object_store_id,
2873 int64_t index_id, 2927 int64_t index_id,
2874 const IndexedDBKey& key, 2928 const IndexedDBKey& key,
2875 const RecordIdentifier& record_identifier) { 2929 const RecordIdentifier& record_identifier) {
2876 IDB_TRACE("IndexedDBBackingStore::PutIndexDataForRecord"); 2930 IDB_TRACE("IndexedDBBackingStore::PutIndexDataForRecord");
2877 DCHECK(key.IsValid()); 2931 DCHECK(key.IsValid());
2878 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) 2932 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id))
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
4476 4530
4477 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4531 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4478 const WriteDescriptor& other) = default; 4532 const WriteDescriptor& other) = default;
4479 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4533 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4480 default; 4534 default;
4481 IndexedDBBackingStore::Transaction::WriteDescriptor& 4535 IndexedDBBackingStore::Transaction::WriteDescriptor&
4482 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4536 IndexedDBBackingStore::Transaction::WriteDescriptor::
4483 operator=(const WriteDescriptor& other) = default; 4537 operator=(const WriteDescriptor& other) = default;
4484 4538
4485 } // namespace content 4539 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698