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_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 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 DatabaseMetaDataKey::Encode(row_id, DatabaseMetaDataKey::USER_VERSION), | 1356 DatabaseMetaDataKey::Encode(row_id, DatabaseMetaDataKey::USER_VERSION), |
| 1357 version); | 1357 version); |
| 1358 return true; | 1358 return true; |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 // If you're deleting a range that contains user keys that have blob info, this | 1361 // If you're deleting a range that contains user keys that have blob info, this |
| 1362 // won't clean up the blobs. | 1362 // won't clean up the blobs. |
| 1363 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction, | 1363 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction, |
| 1364 const std::string& begin, | 1364 const std::string& begin, |
| 1365 const std::string& end, | 1365 const std::string& end, |
| 1366 bool upper_open) { | 1366 bool upper_open, |
| 1367 size_t* delete_count) { | |
| 1367 std::unique_ptr<LevelDBIterator> it = transaction->CreateIterator(); | 1368 std::unique_ptr<LevelDBIterator> it = transaction->CreateIterator(); |
| 1368 leveldb::Status s; | 1369 leveldb::Status s; |
| 1370 if (delete_count) { | |
|
dmurph
2016/05/19 01:01:38
Remove brackets here and keep on same line.(https:
cmumford
2016/05/19 17:07:15
My preference would be to make delete_count a requ
palakj1
2016/05/19 23:47:52
Done. nullptr not permitted.
| |
| 1371 *delete_count = 0; | |
| 1372 } | |
| 1369 for (s = it->Seek(begin); s.ok() && it->IsValid() && | 1373 for (s = it->Seek(begin); s.ok() && it->IsValid() && |
| 1370 (upper_open ? CompareKeys(it->Key(), end) < 0 | 1374 (upper_open ? CompareKeys(it->Key(), end) < 0 |
| 1371 : CompareKeys(it->Key(), end) <= 0); | 1375 : CompareKeys(it->Key(), end) <= 0); |
| 1372 s = it->Next()) | 1376 s = it->Next()) { |
| 1373 transaction->Remove(it->Key()); | 1377 if (transaction->Remove(it->Key())) { |
| 1378 if (delete_count) { | |
| 1379 (*delete_count)++; | |
| 1380 } | |
| 1381 } | |
| 1382 } | |
| 1374 return s; | 1383 return s; |
| 1375 } | 1384 } |
| 1376 | 1385 |
| 1377 static leveldb::Status DeleteBlobsInRange( | 1386 static leveldb::Status DeleteBlobsInRange( |
| 1378 IndexedDBBackingStore::Transaction* transaction, | 1387 IndexedDBBackingStore::Transaction* transaction, |
| 1379 int64_t database_id, | 1388 int64_t database_id, |
| 1380 int64_t object_store_id, | 1389 int64_t object_store_id, |
| 1381 const std::string& start_key, | 1390 const std::string& start_key, |
| 1382 const std::string& end_key, | 1391 const std::string& end_key, |
| 1383 bool upper_open) { | 1392 bool upper_open) { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 | 1794 |
| 1786 s = DeleteBlobsInObjectStore(transaction, database_id, object_store_id); | 1795 s = DeleteBlobsInObjectStore(transaction, database_id, object_store_id); |
| 1787 if (!s.ok()) { | 1796 if (!s.ok()) { |
| 1788 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE); | 1797 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE); |
| 1789 return s; | 1798 return s; |
| 1790 } | 1799 } |
| 1791 | 1800 |
| 1792 s = DeleteRangeBasic( | 1801 s = DeleteRangeBasic( |
| 1793 leveldb_transaction, | 1802 leveldb_transaction, |
| 1794 ObjectStoreMetaDataKey::Encode(database_id, object_store_id, 0), | 1803 ObjectStoreMetaDataKey::Encode(database_id, object_store_id, 0), |
| 1795 ObjectStoreMetaDataKey::EncodeMaxKey(database_id, object_store_id), | 1804 ObjectStoreMetaDataKey::EncodeMaxKey(database_id, object_store_id), true, |
| 1796 true); | 1805 NULL); |
|
cmumford
2016/05/19 17:07:15
At a minimum s/NULL/nullptr/g.
I still prefer to
palakj1
2016/05/19 23:47:52
Done
| |
| 1797 | 1806 |
| 1798 if (s.ok()) { | 1807 if (s.ok()) { |
| 1799 leveldb_transaction->Remove( | 1808 leveldb_transaction->Remove( |
| 1800 ObjectStoreNamesKey::Encode(database_id, object_store_name)); | 1809 ObjectStoreNamesKey::Encode(database_id, object_store_name)); |
| 1801 | 1810 |
| 1802 s = DeleteRangeBasic( | 1811 s = DeleteRangeBasic( |
| 1803 leveldb_transaction, | 1812 leveldb_transaction, |
| 1804 IndexFreeListKey::Encode(database_id, object_store_id, 0), | 1813 IndexFreeListKey::Encode(database_id, object_store_id, 0), |
| 1805 IndexFreeListKey::EncodeMaxKey(database_id, object_store_id), | 1814 IndexFreeListKey::EncodeMaxKey(database_id, object_store_id), true, |
| 1806 true); | 1815 NULL); |
| 1807 } | 1816 } |
| 1808 | 1817 |
| 1809 if (s.ok()) { | 1818 if (s.ok()) { |
| 1810 s = DeleteRangeBasic( | 1819 s = DeleteRangeBasic( |
| 1811 leveldb_transaction, | 1820 leveldb_transaction, |
| 1812 IndexMetaDataKey::Encode(database_id, object_store_id, 0, 0), | 1821 IndexMetaDataKey::Encode(database_id, object_store_id, 0, 0), |
| 1813 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id), | 1822 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id), true, |
| 1814 true); | 1823 NULL); |
| 1815 } | 1824 } |
| 1816 | 1825 |
| 1817 if (!s.ok()) { | 1826 if (!s.ok()) { |
| 1818 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE); | 1827 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE); |
| 1819 return s; | 1828 return s; |
| 1820 } | 1829 } |
| 1821 | 1830 |
| 1822 return ClearObjectStore(transaction, database_id, object_store_id); | 1831 return ClearObjectStore(transaction, database_id, object_store_id); |
| 1823 } | 1832 } |
| 1824 | 1833 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1948 IndexedDBBackingStore::Transaction* transaction, | 1957 IndexedDBBackingStore::Transaction* transaction, |
| 1949 int64_t database_id, | 1958 int64_t database_id, |
| 1950 int64_t object_store_id) { | 1959 int64_t object_store_id) { |
| 1951 IDB_TRACE("IndexedDBBackingStore::ClearObjectStore"); | 1960 IDB_TRACE("IndexedDBBackingStore::ClearObjectStore"); |
| 1952 if (!KeyPrefix::ValidIds(database_id, object_store_id)) | 1961 if (!KeyPrefix::ValidIds(database_id, object_store_id)) |
| 1953 return InvalidDBKeyStatus(); | 1962 return InvalidDBKeyStatus(); |
| 1954 const std::string start_key = | 1963 const std::string start_key = |
| 1955 KeyPrefix(database_id, object_store_id).Encode(); | 1964 KeyPrefix(database_id, object_store_id).Encode(); |
| 1956 const std::string stop_key = | 1965 const std::string stop_key = |
| 1957 KeyPrefix(database_id, object_store_id + 1).Encode(); | 1966 KeyPrefix(database_id, object_store_id + 1).Encode(); |
| 1958 | 1967 leveldb::Status s = DeleteRangeBasic(transaction->transaction(), start_key, |
| 1959 leveldb::Status s = | 1968 stop_key, true, NULL); |
| 1960 DeleteRangeBasic(transaction->transaction(), start_key, stop_key, true); | |
| 1961 if (!s.ok()) { | 1969 if (!s.ok()) { |
| 1962 INTERNAL_WRITE_ERROR(CLEAR_OBJECT_STORE); | 1970 INTERNAL_WRITE_ERROR(CLEAR_OBJECT_STORE); |
| 1963 return s; | 1971 return s; |
| 1964 } | 1972 } |
| 1965 return DeleteBlobsInObjectStore(transaction, database_id, object_store_id); | 1973 return DeleteBlobsInObjectStore(transaction, database_id, object_store_id); |
| 1966 } | 1974 } |
| 1967 | 1975 |
| 1968 leveldb::Status IndexedDBBackingStore::DeleteRecord( | 1976 leveldb::Status IndexedDBBackingStore::DeleteRecord( |
| 1969 IndexedDBBackingStore::Transaction* transaction, | 1977 IndexedDBBackingStore::Transaction* transaction, |
| 1970 int64_t database_id, | 1978 int64_t database_id, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1986 const std::string exists_entry_key = ExistsEntryKey::Encode( | 1994 const std::string exists_entry_key = ExistsEntryKey::Encode( |
| 1987 database_id, object_store_id, record_identifier.primary_key()); | 1995 database_id, object_store_id, record_identifier.primary_key()); |
| 1988 leveldb_transaction->Remove(exists_entry_key); | 1996 leveldb_transaction->Remove(exists_entry_key); |
| 1989 return leveldb::Status::OK(); | 1997 return leveldb::Status::OK(); |
| 1990 } | 1998 } |
| 1991 | 1999 |
| 1992 leveldb::Status IndexedDBBackingStore::DeleteRange( | 2000 leveldb::Status IndexedDBBackingStore::DeleteRange( |
| 1993 IndexedDBBackingStore::Transaction* transaction, | 2001 IndexedDBBackingStore::Transaction* transaction, |
| 1994 int64_t database_id, | 2002 int64_t database_id, |
| 1995 int64_t object_store_id, | 2003 int64_t object_store_id, |
| 1996 const IndexedDBKeyRange& key_range) { | 2004 const IndexedDBKeyRange& key_range, |
| 2005 size_t* delete_count) { | |
| 1997 leveldb::Status s; | 2006 leveldb::Status s; |
| 2007 if (delete_count) | |
| 2008 (*delete_count) = 0; // set delete_count to 0 for empty ranges | |
|
cmumford
2016/05/19 17:07:15
I think the reason to initialize delete_count is o
palakj1
2016/05/19 23:47:52
Done
| |
| 1998 std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor = | 2009 std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor = |
| 1999 OpenObjectStoreCursor(transaction, database_id, object_store_id, | 2010 OpenObjectStoreCursor(transaction, database_id, object_store_id, |
| 2000 key_range, blink::WebIDBCursorDirectionNext, &s); | 2011 key_range, blink::WebIDBCursorDirectionNext, &s); |
| 2001 if (!s.ok()) | 2012 if (!s.ok()) |
| 2002 return s; | 2013 return s; |
| 2003 if (!start_cursor) | 2014 if (!start_cursor) |
| 2004 return leveldb::Status::OK(); // Empty range == delete success. | 2015 return leveldb::Status::OK(); // Empty range == delete success. |
| 2005 | |
| 2006 std::unique_ptr<IndexedDBBackingStore::Cursor> end_cursor = | 2016 std::unique_ptr<IndexedDBBackingStore::Cursor> end_cursor = |
| 2007 OpenObjectStoreCursor(transaction, database_id, object_store_id, | 2017 OpenObjectStoreCursor(transaction, database_id, object_store_id, |
| 2008 key_range, blink::WebIDBCursorDirectionPrev, &s); | 2018 key_range, blink::WebIDBCursorDirectionPrev, &s); |
| 2009 | 2019 |
| 2010 if (!s.ok()) | 2020 if (!s.ok()) |
| 2011 return s; | 2021 return s; |
| 2012 if (!end_cursor) | 2022 if (!end_cursor) |
| 2013 return leveldb::Status::OK(); // Empty range == delete success. | 2023 return leveldb::Status::OK(); // Empty range == delete success. |
| 2014 | 2024 |
| 2015 BlobEntryKey start_blob_key, end_blob_key; | 2025 BlobEntryKey start_blob_key, end_blob_key; |
| 2016 | |
| 2017 std::string start_key = ObjectStoreDataKey::Encode( | 2026 std::string start_key = ObjectStoreDataKey::Encode( |
| 2018 database_id, object_store_id, start_cursor->key()); | 2027 database_id, object_store_id, start_cursor->key()); |
| 2019 base::StringPiece start_key_piece(start_key); | 2028 base::StringPiece start_key_piece(start_key); |
| 2020 if (!BlobEntryKey::FromObjectStoreDataKey(&start_key_piece, &start_blob_key)) | 2029 if (!BlobEntryKey::FromObjectStoreDataKey(&start_key_piece, &start_blob_key)) |
| 2021 return InternalInconsistencyStatus(); | 2030 return InternalInconsistencyStatus(); |
| 2022 std::string stop_key = ObjectStoreDataKey::Encode( | 2031 std::string stop_key = ObjectStoreDataKey::Encode( |
| 2023 database_id, object_store_id, end_cursor->key()); | 2032 database_id, object_store_id, end_cursor->key()); |
| 2024 base::StringPiece stop_key_piece(stop_key); | 2033 base::StringPiece stop_key_piece(stop_key); |
| 2025 if (!BlobEntryKey::FromObjectStoreDataKey(&stop_key_piece, &end_blob_key)) | 2034 if (!BlobEntryKey::FromObjectStoreDataKey(&stop_key_piece, &end_blob_key)) |
| 2026 return InternalInconsistencyStatus(); | 2035 return InternalInconsistencyStatus(); |
| 2027 | 2036 |
| 2028 s = DeleteBlobsInRange(transaction, | 2037 s = DeleteBlobsInRange(transaction, |
| 2029 database_id, | 2038 database_id, |
| 2030 object_store_id, | 2039 object_store_id, |
| 2031 start_blob_key.Encode(), | 2040 start_blob_key.Encode(), |
| 2032 end_blob_key.Encode(), | 2041 end_blob_key.Encode(), |
| 2033 false); | 2042 false); |
| 2034 if (!s.ok()) | 2043 if (!s.ok()) |
| 2035 return s; | 2044 return s; |
| 2036 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false); | 2045 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false, |
|
dmurph
2016/05/19 01:01:38
Since both of these calls are going to make delete
cmumford
2016/05/19 17:07:15
jsbell please confirm, but I believe they will bot
jsbell
2016/05/19 18:23:42
Alternately, call the first one data_count and the
palakj1
2016/05/19 23:47:52
Thanks for this bit of explanation. Changed as per
| |
| 2046 delete_count); | |
| 2037 if (!s.ok()) | 2047 if (!s.ok()) |
| 2038 return s; | 2048 return s; |
| 2039 start_key = | 2049 start_key = |
| 2040 ExistsEntryKey::Encode(database_id, object_store_id, start_cursor->key()); | 2050 ExistsEntryKey::Encode(database_id, object_store_id, start_cursor->key()); |
| 2041 stop_key = | 2051 stop_key = |
| 2042 ExistsEntryKey::Encode(database_id, object_store_id, end_cursor->key()); | 2052 ExistsEntryKey::Encode(database_id, object_store_id, end_cursor->key()); |
| 2043 return DeleteRangeBasic( | 2053 |
| 2044 transaction->transaction(), start_key, stop_key, false); | 2054 return DeleteRangeBasic(transaction->transaction(), start_key, stop_key, |
| 2055 false, delete_count); | |
| 2045 } | 2056 } |
| 2046 | 2057 |
| 2047 leveldb::Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber( | 2058 leveldb::Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber( |
| 2048 IndexedDBBackingStore::Transaction* transaction, | 2059 IndexedDBBackingStore::Transaction* transaction, |
| 2049 int64_t database_id, | 2060 int64_t database_id, |
| 2050 int64_t object_store_id, | 2061 int64_t object_store_id, |
| 2051 int64_t* key_generator_current_number) { | 2062 int64_t* key_generator_current_number) { |
| 2052 if (!KeyPrefix::ValidIds(database_id, object_store_id)) | 2063 if (!KeyPrefix::ValidIds(database_id, object_store_id)) |
| 2053 return InvalidDBKeyStatus(); | 2064 return InvalidDBKeyStatus(); |
| 2054 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 2065 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2832 int64_t index_id) { | 2843 int64_t index_id) { |
| 2833 IDB_TRACE("IndexedDBBackingStore::DeleteIndex"); | 2844 IDB_TRACE("IndexedDBBackingStore::DeleteIndex"); |
| 2834 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) | 2845 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) |
| 2835 return InvalidDBKeyStatus(); | 2846 return InvalidDBKeyStatus(); |
| 2836 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 2847 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 2837 | 2848 |
| 2838 const std::string index_meta_data_start = | 2849 const std::string index_meta_data_start = |
| 2839 IndexMetaDataKey::Encode(database_id, object_store_id, index_id, 0); | 2850 IndexMetaDataKey::Encode(database_id, object_store_id, index_id, 0); |
| 2840 const std::string index_meta_data_end = | 2851 const std::string index_meta_data_end = |
| 2841 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id, index_id); | 2852 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id, index_id); |
| 2842 leveldb::Status s = DeleteRangeBasic( | 2853 leveldb::Status s = |
| 2843 leveldb_transaction, index_meta_data_start, index_meta_data_end, true); | 2854 DeleteRangeBasic(leveldb_transaction, index_meta_data_start, |
| 2855 index_meta_data_end, true, NULL); | |
|
dmurph
2016/05/19 01:01:38
we use 'nullptr'
https://google.github.io/stylegui
palakj1
2016/05/19 23:47:52
value not null anymore
| |
| 2844 | 2856 |
| 2845 if (s.ok()) { | 2857 if (s.ok()) { |
| 2846 const std::string index_data_start = | 2858 const std::string index_data_start = |
| 2847 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); | 2859 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); |
| 2848 const std::string index_data_end = | 2860 const std::string index_data_end = |
| 2849 IndexDataKey::EncodeMaxKey(database_id, object_store_id, index_id); | 2861 IndexDataKey::EncodeMaxKey(database_id, object_store_id, index_id); |
| 2850 s = DeleteRangeBasic( | 2862 s = DeleteRangeBasic(leveldb_transaction, index_data_start, index_data_end, |
| 2851 leveldb_transaction, index_data_start, index_data_end, true); | 2863 true, NULL); |
| 2852 } | 2864 } |
| 2853 | 2865 |
| 2854 if (!s.ok()) | 2866 if (!s.ok()) |
| 2855 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX); | 2867 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX); |
| 2856 | 2868 |
| 2857 return s; | 2869 return s; |
| 2858 } | 2870 } |
| 2859 | 2871 |
| 2860 leveldb::Status IndexedDBBackingStore::PutIndexDataForRecord( | 2872 leveldb::Status IndexedDBBackingStore::PutIndexDataForRecord( |
| 2861 IndexedDBBackingStore::Transaction* transaction, | 2873 IndexedDBBackingStore::Transaction* transaction, |
| (...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4459 | 4471 |
| 4460 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4472 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4461 const WriteDescriptor& other) = default; | 4473 const WriteDescriptor& other) = default; |
| 4462 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4474 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4463 default; | 4475 default; |
| 4464 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4476 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4465 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4477 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4466 operator=(const WriteDescriptor& other) = default; | 4478 operator=(const WriteDescriptor& other) = default; |
| 4467 | 4479 |
| 4468 } // namespace content | 4480 } // namespace content |
| OLD | NEW |