| 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 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 DatabaseMetaDataKey::Encode( | 1332 DatabaseMetaDataKey::Encode( |
| 1333 *row_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER), | 1333 *row_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER), |
| 1334 DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber); | 1334 DatabaseMetaDataKey::kBlobKeyGeneratorInitialNumber); |
| 1335 | 1335 |
| 1336 s = transaction->Commit(); | 1336 s = transaction->Commit(); |
| 1337 if (!s.ok()) | 1337 if (!s.ok()) |
| 1338 INTERNAL_WRITE_ERROR_UNTESTED(CREATE_IDBDATABASE_METADATA); | 1338 INTERNAL_WRITE_ERROR_UNTESTED(CREATE_IDBDATABASE_METADATA); |
| 1339 return s; | 1339 return s; |
| 1340 } | 1340 } |
| 1341 | 1341 |
| 1342 bool IndexedDBBackingStore::UpdateIDBDatabaseIntVersion( | 1342 void IndexedDBBackingStore::UpdateIDBDatabaseIntVersion( |
| 1343 IndexedDBBackingStore::Transaction* transaction, | 1343 IndexedDBBackingStore::Transaction* transaction, |
| 1344 int64_t row_id, | 1344 int64_t row_id, |
| 1345 int64_t version) { | 1345 int64_t version) { |
| 1346 if (version == IndexedDBDatabaseMetadata::NO_VERSION) | 1346 if (version == IndexedDBDatabaseMetadata::NO_VERSION) |
| 1347 version = IndexedDBDatabaseMetadata::DEFAULT_VERSION; | 1347 version = IndexedDBDatabaseMetadata::DEFAULT_VERSION; |
| 1348 DCHECK_GE(version, 0) << "version was " << version; | 1348 DCHECK_GE(version, 0) << "version was " << version; |
| 1349 PutVarInt( | 1349 PutVarInt( |
| 1350 transaction->transaction(), | 1350 transaction->transaction(), |
| 1351 DatabaseMetaDataKey::Encode(row_id, DatabaseMetaDataKey::USER_VERSION), | 1351 DatabaseMetaDataKey::Encode(row_id, DatabaseMetaDataKey::USER_VERSION), |
| 1352 version); | 1352 version); |
| 1353 return true; | |
| 1354 } | 1353 } |
| 1355 | 1354 |
| 1356 // If you're deleting a range that contains user keys that have blob info, this | 1355 // If you're deleting a range that contains user keys that have blob info, this |
| 1357 // won't clean up the blobs. | 1356 // won't clean up the blobs. |
| 1358 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction, | 1357 static leveldb::Status DeleteRangeBasic(LevelDBTransaction* transaction, |
| 1359 const std::string& begin, | 1358 const std::string& begin, |
| 1360 const std::string& end, | 1359 const std::string& end, |
| 1361 bool upper_open, | 1360 bool upper_open, |
| 1362 size_t* delete_count) { | 1361 size_t* delete_count) { |
| 1363 DCHECK(delete_count); | 1362 DCHECK(delete_count); |
| (...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3796 transaction_->transaction()->Remove(iterator_->Key()); | 3795 transaction_->transaction()->Remove(iterator_->Key()); |
| 3797 return false; | 3796 return false; |
| 3798 } | 3797 } |
| 3799 | 3798 |
| 3800 current_value_.bits = slice.as_string(); | 3799 current_value_.bits = slice.as_string(); |
| 3801 *s = transaction_->GetBlobInfoForRecord(database_id_, primary_leveldb_key_, | 3800 *s = transaction_->GetBlobInfoForRecord(database_id_, primary_leveldb_key_, |
| 3802 ¤t_value_); | 3801 ¤t_value_); |
| 3803 return s->ok(); | 3802 return s->ok(); |
| 3804 } | 3803 } |
| 3805 | 3804 |
| 3806 bool ObjectStoreCursorOptions( | 3805 leveldb::Status ObjectStoreCursorOptions( |
| 3807 LevelDBTransaction* transaction, | 3806 LevelDBTransaction* transaction, |
| 3808 int64_t database_id, | 3807 int64_t database_id, |
| 3809 int64_t object_store_id, | 3808 int64_t object_store_id, |
| 3810 const IndexedDBKeyRange& range, | 3809 const IndexedDBKeyRange& range, |
| 3811 blink::WebIDBCursorDirection direction, | 3810 blink::WebIDBCursorDirection direction, |
| 3812 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3811 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
| 3813 cursor_options->database_id = database_id; | 3812 cursor_options->database_id = database_id; |
| 3814 cursor_options->object_store_id = object_store_id; | 3813 cursor_options->object_store_id = object_store_id; |
| 3815 | 3814 |
| 3816 bool lower_bound = range.lower().IsValid(); | 3815 bool lower_bound = range.lower().IsValid(); |
| 3817 bool upper_bound = range.upper().IsValid(); | 3816 bool upper_bound = range.upper().IsValid(); |
| 3818 cursor_options->forward = | 3817 cursor_options->forward = |
| 3819 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || | 3818 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3820 direction == blink::WebIDBCursorDirectionNext); | 3819 direction == blink::WebIDBCursorDirectionNext); |
| 3821 cursor_options->unique = | 3820 cursor_options->unique = |
| 3822 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || | 3821 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3823 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); | 3822 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); |
| 3824 | 3823 |
| 3825 if (!lower_bound) { | 3824 if (!lower_bound) { |
| 3826 cursor_options->low_key = | 3825 cursor_options->low_key = |
| 3827 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); | 3826 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); |
| 3828 cursor_options->low_open = true; // Not included. | 3827 cursor_options->low_open = true; // Not included. |
| 3829 } else { | 3828 } else { |
| 3830 cursor_options->low_key = | 3829 cursor_options->low_key = |
| 3831 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); | 3830 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); |
| 3832 cursor_options->low_open = range.lower_open(); | 3831 cursor_options->low_open = range.lower_open(); |
| 3833 } | 3832 } |
| 3834 | 3833 |
| 3835 leveldb::Status s; | 3834 leveldb::Status s = leveldb::Status::OK(); |
| 3836 | 3835 |
| 3837 if (!upper_bound) { | 3836 if (!upper_bound) { |
| 3838 cursor_options->high_key = | 3837 cursor_options->high_key = |
| 3839 ObjectStoreDataKey::Encode(database_id, object_store_id, MaxIDBKey()); | 3838 ObjectStoreDataKey::Encode(database_id, object_store_id, MaxIDBKey()); |
| 3840 | 3839 |
| 3841 if (cursor_options->forward) { | 3840 if (cursor_options->forward) { |
| 3842 cursor_options->high_open = true; // Not included. | 3841 cursor_options->high_open = true; // Not included. |
| 3843 } else { | 3842 } else { |
| 3844 // We need a key that exists. | 3843 // We need a key that exists. |
| 3845 // TODO(cmumford): Handle this error (crbug.com/363397) | |
| 3846 if (!FindGreatestKeyLessThanOrEqual(transaction, | 3844 if (!FindGreatestKeyLessThanOrEqual(transaction, |
| 3847 cursor_options->high_key, | 3845 cursor_options->high_key, |
| 3848 &cursor_options->high_key, | 3846 &cursor_options->high_key, |
| 3849 &s)) | 3847 &s)) |
| 3850 return false; | 3848 return s; |
| 3851 cursor_options->high_open = false; | 3849 cursor_options->high_open = false; |
| 3852 } | 3850 } |
| 3853 } else { | 3851 } else { |
| 3854 cursor_options->high_key = | 3852 cursor_options->high_key = |
| 3855 ObjectStoreDataKey::Encode(database_id, object_store_id, range.upper()); | 3853 ObjectStoreDataKey::Encode(database_id, object_store_id, range.upper()); |
| 3856 cursor_options->high_open = range.upper_open(); | 3854 cursor_options->high_open = range.upper_open(); |
| 3857 | 3855 |
| 3858 if (!cursor_options->forward) { | 3856 if (!cursor_options->forward) { |
| 3859 // For reverse cursors, we need a key that exists. | 3857 // For reverse cursors, we need a key that exists. |
| 3860 std::string found_high_key; | 3858 std::string found_high_key; |
| 3861 // TODO(cmumford): Handle this error (crbug.com/363397) | |
| 3862 if (!FindGreatestKeyLessThanOrEqual( | 3859 if (!FindGreatestKeyLessThanOrEqual( |
| 3863 transaction, cursor_options->high_key, &found_high_key, &s)) | 3860 transaction, cursor_options->high_key, &found_high_key, &s)) |
| 3864 return false; | 3861 return s; |
| 3865 | 3862 |
| 3866 // If the target key should not be included, but we end up with a smaller | 3863 // If the target key should not be included, but we end up with a smaller |
| 3867 // key, we should include that. | 3864 // key, we should include that. |
| 3868 if (cursor_options->high_open && | 3865 if (cursor_options->high_open && |
| 3869 CompareIndexKeys(found_high_key, cursor_options->high_key) < 0) | 3866 CompareIndexKeys(found_high_key, cursor_options->high_key) < 0) |
| 3870 cursor_options->high_open = false; | 3867 cursor_options->high_open = false; |
| 3871 | 3868 |
| 3872 cursor_options->high_key = found_high_key; | 3869 cursor_options->high_key = found_high_key; |
| 3873 } | 3870 } |
| 3874 } | 3871 } |
| 3875 | 3872 |
| 3876 return true; | 3873 return s; |
| 3877 } | 3874 } |
| 3878 | 3875 |
| 3879 bool IndexCursorOptions( | 3876 bool IndexCursorOptions( |
| 3880 LevelDBTransaction* transaction, | 3877 LevelDBTransaction* transaction, |
| 3881 int64_t database_id, | 3878 int64_t database_id, |
| 3882 int64_t object_store_id, | 3879 int64_t object_store_id, |
| 3883 int64_t index_id, | 3880 int64_t index_id, |
| 3884 const IndexedDBKeyRange& range, | 3881 const IndexedDBKeyRange& range, |
| 3885 blink::WebIDBCursorDirection direction, | 3882 blink::WebIDBCursorDirection direction, |
| 3886 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3883 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3952 | 3949 |
| 3953 std::unique_ptr<IndexedDBBackingStore::Cursor> | 3950 std::unique_ptr<IndexedDBBackingStore::Cursor> |
| 3954 IndexedDBBackingStore::OpenObjectStoreCursor( | 3951 IndexedDBBackingStore::OpenObjectStoreCursor( |
| 3955 IndexedDBBackingStore::Transaction* transaction, | 3952 IndexedDBBackingStore::Transaction* transaction, |
| 3956 int64_t database_id, | 3953 int64_t database_id, |
| 3957 int64_t object_store_id, | 3954 int64_t object_store_id, |
| 3958 const IndexedDBKeyRange& range, | 3955 const IndexedDBKeyRange& range, |
| 3959 blink::WebIDBCursorDirection direction, | 3956 blink::WebIDBCursorDirection direction, |
| 3960 leveldb::Status* s) { | 3957 leveldb::Status* s) { |
| 3961 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); | 3958 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); |
| 3962 *s = leveldb::Status::OK(); | |
| 3963 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3959 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3964 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3960 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3965 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3961 *s = ObjectStoreCursorOptions(leveldb_transaction, database_id, |
| 3966 database_id, | 3962 object_store_id, range, direction, |
| 3967 object_store_id, | 3963 &cursor_options); |
| 3968 range, | 3964 if (!s->ok()) |
| 3969 direction, | |
| 3970 &cursor_options)) | |
| 3971 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); | 3965 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); |
| 3972 std::unique_ptr<ObjectStoreCursorImpl> cursor( | 3966 std::unique_ptr<ObjectStoreCursorImpl> cursor( |
| 3973 base::MakeUnique<ObjectStoreCursorImpl>(this, transaction, database_id, | 3967 base::MakeUnique<ObjectStoreCursorImpl>(this, transaction, database_id, |
| 3974 cursor_options)); | 3968 cursor_options)); |
| 3975 if (!cursor->FirstSeek(s)) | 3969 if (!cursor->FirstSeek(s)) |
| 3976 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); | 3970 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); |
| 3977 | 3971 |
| 3978 return std::move(cursor); | 3972 return std::move(cursor); |
| 3979 } | 3973 } |
| 3980 | 3974 |
| 3981 std::unique_ptr<IndexedDBBackingStore::Cursor> | 3975 std::unique_ptr<IndexedDBBackingStore::Cursor> |
| 3982 IndexedDBBackingStore::OpenObjectStoreKeyCursor( | 3976 IndexedDBBackingStore::OpenObjectStoreKeyCursor( |
| 3983 IndexedDBBackingStore::Transaction* transaction, | 3977 IndexedDBBackingStore::Transaction* transaction, |
| 3984 int64_t database_id, | 3978 int64_t database_id, |
| 3985 int64_t object_store_id, | 3979 int64_t object_store_id, |
| 3986 const IndexedDBKeyRange& range, | 3980 const IndexedDBKeyRange& range, |
| 3987 blink::WebIDBCursorDirection direction, | 3981 blink::WebIDBCursorDirection direction, |
| 3988 leveldb::Status* s) { | 3982 leveldb::Status* s) { |
| 3989 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); | 3983 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); |
| 3990 *s = leveldb::Status::OK(); | |
| 3991 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3984 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3992 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3985 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3993 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3986 *s = ObjectStoreCursorOptions(leveldb_transaction, database_id, |
| 3994 database_id, | 3987 object_store_id, range, direction, |
| 3995 object_store_id, | 3988 &cursor_options); |
| 3996 range, | 3989 if (!s->ok()) |
| 3997 direction, | |
| 3998 &cursor_options)) | |
| 3999 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); | 3990 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); |
| 4000 std::unique_ptr<ObjectStoreKeyCursorImpl> cursor( | 3991 std::unique_ptr<ObjectStoreKeyCursorImpl> cursor( |
| 4001 base::MakeUnique<ObjectStoreKeyCursorImpl>(this, transaction, database_id, | 3992 base::MakeUnique<ObjectStoreKeyCursorImpl>(this, transaction, database_id, |
| 4002 cursor_options)); | 3993 cursor_options)); |
| 4003 if (!cursor->FirstSeek(s)) | 3994 if (!cursor->FirstSeek(s)) |
| 4004 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); | 3995 return std::unique_ptr<IndexedDBBackingStore::Cursor>(); |
| 4005 | 3996 |
| 4006 return std::move(cursor); | 3997 return std::move(cursor); |
| 4007 } | 3998 } |
| 4008 | 3999 |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4529 | 4520 |
| 4530 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4521 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4531 const WriteDescriptor& other) = default; | 4522 const WriteDescriptor& other) = default; |
| 4532 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4523 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4533 default; | 4524 default; |
| 4534 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4525 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4535 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4526 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4536 operator=(const WriteDescriptor& other) = default; | 4527 operator=(const WriteDescriptor& other) = default; |
| 4537 | 4528 |
| 4538 } // namespace content | 4529 } // namespace content |
| OLD | NEW |