| 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 IndexedDBBackingStore::Transaction* transaction, | 1954 IndexedDBBackingStore::Transaction* transaction, |
| 1955 int64 database_id, | 1955 int64 database_id, |
| 1956 int64 object_store_id, | 1956 int64 object_store_id, |
| 1957 const IndexedDBKeyRange& key_range) { | 1957 const IndexedDBKeyRange& key_range) { |
| 1958 leveldb::Status s; | 1958 leveldb::Status s; |
| 1959 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor = | 1959 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor = |
| 1960 OpenObjectStoreCursor(transaction, | 1960 OpenObjectStoreCursor(transaction, |
| 1961 database_id, | 1961 database_id, |
| 1962 object_store_id, | 1962 object_store_id, |
| 1963 key_range, | 1963 key_range, |
| 1964 indexed_db::CURSOR_NEXT, | 1964 blink::WebIDBCursorDirectionNext, |
| 1965 &s); | 1965 &s); |
| 1966 if (!s.ok()) | 1966 if (!s.ok()) |
| 1967 return s; | 1967 return s; |
| 1968 if (!start_cursor) | 1968 if (!start_cursor) |
| 1969 return leveldb::Status::OK(); // Empty range == delete success. | 1969 return leveldb::Status::OK(); // Empty range == delete success. |
| 1970 | 1970 |
| 1971 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = | 1971 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = |
| 1972 OpenObjectStoreCursor(transaction, | 1972 OpenObjectStoreCursor(transaction, |
| 1973 database_id, | 1973 database_id, |
| 1974 object_store_id, | 1974 object_store_id, |
| 1975 key_range, | 1975 key_range, |
| 1976 indexed_db::CURSOR_PREV, | 1976 blink::WebIDBCursorDirectionPrev, |
| 1977 &s); | 1977 &s); |
| 1978 | 1978 |
| 1979 if (!s.ok()) | 1979 if (!s.ok()) |
| 1980 return s; | 1980 return s; |
| 1981 if (!end_cursor) | 1981 if (!end_cursor) |
| 1982 return leveldb::Status::OK(); // Empty range == delete success. | 1982 return leveldb::Status::OK(); // Empty range == delete success. |
| 1983 | 1983 |
| 1984 BlobEntryKey start_blob_key, end_blob_key; | 1984 BlobEntryKey start_blob_key, end_blob_key; |
| 1985 | 1985 |
| 1986 std::string start_key = ObjectStoreDataKey::Encode( | 1986 std::string start_key = ObjectStoreDataKey::Encode( |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3566 return transaction_->GetBlobInfoForRecord(database_id_, | 3566 return transaction_->GetBlobInfoForRecord(database_id_, |
| 3567 primary_leveldb_key_, | 3567 primary_leveldb_key_, |
| 3568 ¤t_value_).ok(); | 3568 ¤t_value_).ok(); |
| 3569 } | 3569 } |
| 3570 | 3570 |
| 3571 bool ObjectStoreCursorOptions( | 3571 bool ObjectStoreCursorOptions( |
| 3572 LevelDBTransaction* transaction, | 3572 LevelDBTransaction* transaction, |
| 3573 int64 database_id, | 3573 int64 database_id, |
| 3574 int64 object_store_id, | 3574 int64 object_store_id, |
| 3575 const IndexedDBKeyRange& range, | 3575 const IndexedDBKeyRange& range, |
| 3576 indexed_db::CursorDirection direction, | 3576 blink::WebIDBCursorDirection direction, |
| 3577 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3577 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
| 3578 cursor_options->database_id = database_id; | 3578 cursor_options->database_id = database_id; |
| 3579 cursor_options->object_store_id = object_store_id; | 3579 cursor_options->object_store_id = object_store_id; |
| 3580 | 3580 |
| 3581 bool lower_bound = range.lower().IsValid(); | 3581 bool lower_bound = range.lower().IsValid(); |
| 3582 bool upper_bound = range.upper().IsValid(); | 3582 bool upper_bound = range.upper().IsValid(); |
| 3583 cursor_options->forward = | 3583 cursor_options->forward = |
| 3584 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3584 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3585 direction == indexed_db::CURSOR_NEXT); | 3585 direction == blink::WebIDBCursorDirectionNext); |
| 3586 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3586 cursor_options->unique = |
| 3587 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE); | 3587 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3588 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); |
| 3588 | 3589 |
| 3589 if (!lower_bound) { | 3590 if (!lower_bound) { |
| 3590 cursor_options->low_key = | 3591 cursor_options->low_key = |
| 3591 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); | 3592 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); |
| 3592 cursor_options->low_open = true; // Not included. | 3593 cursor_options->low_open = true; // Not included. |
| 3593 } else { | 3594 } else { |
| 3594 cursor_options->low_key = | 3595 cursor_options->low_key = |
| 3595 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); | 3596 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); |
| 3596 cursor_options->low_open = range.lowerOpen(); | 3597 cursor_options->low_open = range.lowerOpen(); |
| 3597 } | 3598 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3639 | 3640 |
| 3640 return true; | 3641 return true; |
| 3641 } | 3642 } |
| 3642 | 3643 |
| 3643 bool IndexCursorOptions( | 3644 bool IndexCursorOptions( |
| 3644 LevelDBTransaction* transaction, | 3645 LevelDBTransaction* transaction, |
| 3645 int64 database_id, | 3646 int64 database_id, |
| 3646 int64 object_store_id, | 3647 int64 object_store_id, |
| 3647 int64 index_id, | 3648 int64 index_id, |
| 3648 const IndexedDBKeyRange& range, | 3649 const IndexedDBKeyRange& range, |
| 3649 indexed_db::CursorDirection direction, | 3650 blink::WebIDBCursorDirection direction, |
| 3650 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3651 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
| 3651 DCHECK(transaction); | 3652 DCHECK(transaction); |
| 3652 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) | 3653 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) |
| 3653 return false; | 3654 return false; |
| 3654 | 3655 |
| 3655 cursor_options->database_id = database_id; | 3656 cursor_options->database_id = database_id; |
| 3656 cursor_options->object_store_id = object_store_id; | 3657 cursor_options->object_store_id = object_store_id; |
| 3657 cursor_options->index_id = index_id; | 3658 cursor_options->index_id = index_id; |
| 3658 | 3659 |
| 3659 bool lower_bound = range.lower().IsValid(); | 3660 bool lower_bound = range.lower().IsValid(); |
| 3660 bool upper_bound = range.upper().IsValid(); | 3661 bool upper_bound = range.upper().IsValid(); |
| 3661 cursor_options->forward = | 3662 cursor_options->forward = |
| 3662 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3663 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3663 direction == indexed_db::CURSOR_NEXT); | 3664 direction == blink::WebIDBCursorDirectionNext); |
| 3664 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3665 cursor_options->unique = |
| 3665 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE); | 3666 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3667 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); |
| 3666 | 3668 |
| 3667 if (!lower_bound) { | 3669 if (!lower_bound) { |
| 3668 cursor_options->low_key = | 3670 cursor_options->low_key = |
| 3669 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); | 3671 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); |
| 3670 cursor_options->low_open = false; // Included. | 3672 cursor_options->low_open = false; // Included. |
| 3671 } else { | 3673 } else { |
| 3672 cursor_options->low_key = IndexDataKey::Encode( | 3674 cursor_options->low_key = IndexDataKey::Encode( |
| 3673 database_id, object_store_id, index_id, range.lower()); | 3675 database_id, object_store_id, index_id, range.lower()); |
| 3674 cursor_options->low_open = range.lowerOpen(); | 3676 cursor_options->low_open = range.lowerOpen(); |
| 3675 } | 3677 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3712 | 3714 |
| 3713 return true; | 3715 return true; |
| 3714 } | 3716 } |
| 3715 | 3717 |
| 3716 scoped_ptr<IndexedDBBackingStore::Cursor> | 3718 scoped_ptr<IndexedDBBackingStore::Cursor> |
| 3717 IndexedDBBackingStore::OpenObjectStoreCursor( | 3719 IndexedDBBackingStore::OpenObjectStoreCursor( |
| 3718 IndexedDBBackingStore::Transaction* transaction, | 3720 IndexedDBBackingStore::Transaction* transaction, |
| 3719 int64 database_id, | 3721 int64 database_id, |
| 3720 int64 object_store_id, | 3722 int64 object_store_id, |
| 3721 const IndexedDBKeyRange& range, | 3723 const IndexedDBKeyRange& range, |
| 3722 indexed_db::CursorDirection direction, | 3724 blink::WebIDBCursorDirection direction, |
| 3723 leveldb::Status* s) { | 3725 leveldb::Status* s) { |
| 3724 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); | 3726 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); |
| 3725 *s = leveldb::Status::OK(); | 3727 *s = leveldb::Status::OK(); |
| 3726 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3728 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3727 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3729 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3728 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3730 if (!ObjectStoreCursorOptions(leveldb_transaction, |
| 3729 database_id, | 3731 database_id, |
| 3730 object_store_id, | 3732 object_store_id, |
| 3731 range, | 3733 range, |
| 3732 direction, | 3734 direction, |
| 3733 &cursor_options)) | 3735 &cursor_options)) |
| 3734 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3736 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3735 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl( | 3737 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl( |
| 3736 this, transaction, database_id, cursor_options)); | 3738 this, transaction, database_id, cursor_options)); |
| 3737 if (!cursor->FirstSeek(s)) | 3739 if (!cursor->FirstSeek(s)) |
| 3738 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3740 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3739 | 3741 |
| 3740 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3742 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
| 3741 } | 3743 } |
| 3742 | 3744 |
| 3743 scoped_ptr<IndexedDBBackingStore::Cursor> | 3745 scoped_ptr<IndexedDBBackingStore::Cursor> |
| 3744 IndexedDBBackingStore::OpenObjectStoreKeyCursor( | 3746 IndexedDBBackingStore::OpenObjectStoreKeyCursor( |
| 3745 IndexedDBBackingStore::Transaction* transaction, | 3747 IndexedDBBackingStore::Transaction* transaction, |
| 3746 int64 database_id, | 3748 int64 database_id, |
| 3747 int64 object_store_id, | 3749 int64 object_store_id, |
| 3748 const IndexedDBKeyRange& range, | 3750 const IndexedDBKeyRange& range, |
| 3749 indexed_db::CursorDirection direction, | 3751 blink::WebIDBCursorDirection direction, |
| 3750 leveldb::Status* s) { | 3752 leveldb::Status* s) { |
| 3751 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); | 3753 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); |
| 3752 *s = leveldb::Status::OK(); | 3754 *s = leveldb::Status::OK(); |
| 3753 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3755 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3754 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3756 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3755 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3757 if (!ObjectStoreCursorOptions(leveldb_transaction, |
| 3756 database_id, | 3758 database_id, |
| 3757 object_store_id, | 3759 object_store_id, |
| 3758 range, | 3760 range, |
| 3759 direction, | 3761 direction, |
| 3760 &cursor_options)) | 3762 &cursor_options)) |
| 3761 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3763 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3762 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl( | 3764 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl( |
| 3763 this, transaction, database_id, cursor_options)); | 3765 this, transaction, database_id, cursor_options)); |
| 3764 if (!cursor->FirstSeek(s)) | 3766 if (!cursor->FirstSeek(s)) |
| 3765 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3767 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3766 | 3768 |
| 3767 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3769 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
| 3768 } | 3770 } |
| 3769 | 3771 |
| 3770 scoped_ptr<IndexedDBBackingStore::Cursor> | 3772 scoped_ptr<IndexedDBBackingStore::Cursor> |
| 3771 IndexedDBBackingStore::OpenIndexKeyCursor( | 3773 IndexedDBBackingStore::OpenIndexKeyCursor( |
| 3772 IndexedDBBackingStore::Transaction* transaction, | 3774 IndexedDBBackingStore::Transaction* transaction, |
| 3773 int64 database_id, | 3775 int64 database_id, |
| 3774 int64 object_store_id, | 3776 int64 object_store_id, |
| 3775 int64 index_id, | 3777 int64 index_id, |
| 3776 const IndexedDBKeyRange& range, | 3778 const IndexedDBKeyRange& range, |
| 3777 indexed_db::CursorDirection direction, | 3779 blink::WebIDBCursorDirection direction, |
| 3778 leveldb::Status* s) { | 3780 leveldb::Status* s) { |
| 3779 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor"); | 3781 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor"); |
| 3780 *s = leveldb::Status::OK(); | 3782 *s = leveldb::Status::OK(); |
| 3781 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3783 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3782 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3784 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3783 if (!IndexCursorOptions(leveldb_transaction, | 3785 if (!IndexCursorOptions(leveldb_transaction, |
| 3784 database_id, | 3786 database_id, |
| 3785 object_store_id, | 3787 object_store_id, |
| 3786 index_id, | 3788 index_id, |
| 3787 range, | 3789 range, |
| 3788 direction, | 3790 direction, |
| 3789 &cursor_options)) | 3791 &cursor_options)) |
| 3790 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3792 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3791 scoped_ptr<IndexKeyCursorImpl> cursor( | 3793 scoped_ptr<IndexKeyCursorImpl> cursor( |
| 3792 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options)); | 3794 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options)); |
| 3793 if (!cursor->FirstSeek(s)) | 3795 if (!cursor->FirstSeek(s)) |
| 3794 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3796 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
| 3795 | 3797 |
| 3796 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3798 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
| 3797 } | 3799 } |
| 3798 | 3800 |
| 3799 scoped_ptr<IndexedDBBackingStore::Cursor> | 3801 scoped_ptr<IndexedDBBackingStore::Cursor> |
| 3800 IndexedDBBackingStore::OpenIndexCursor( | 3802 IndexedDBBackingStore::OpenIndexCursor( |
| 3801 IndexedDBBackingStore::Transaction* transaction, | 3803 IndexedDBBackingStore::Transaction* transaction, |
| 3802 int64 database_id, | 3804 int64 database_id, |
| 3803 int64 object_store_id, | 3805 int64 object_store_id, |
| 3804 int64 index_id, | 3806 int64 index_id, |
| 3805 const IndexedDBKeyRange& range, | 3807 const IndexedDBKeyRange& range, |
| 3806 indexed_db::CursorDirection direction, | 3808 blink::WebIDBCursorDirection direction, |
| 3807 leveldb::Status* s) { | 3809 leveldb::Status* s) { |
| 3808 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor"); | 3810 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor"); |
| 3809 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3811 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
| 3810 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3812 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
| 3811 if (!IndexCursorOptions(leveldb_transaction, | 3813 if (!IndexCursorOptions(leveldb_transaction, |
| 3812 database_id, | 3814 database_id, |
| 3813 object_store_id, | 3815 object_store_id, |
| 3814 index_id, | 3816 index_id, |
| 3815 range, | 3817 range, |
| 3816 direction, | 3818 direction, |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 int64_t size, | 4242 int64_t size, |
| 4241 base::Time last_modified) | 4243 base::Time last_modified) |
| 4242 : is_file_(true), | 4244 : is_file_(true), |
| 4243 file_path_(file_path), | 4245 file_path_(file_path), |
| 4244 key_(key), | 4246 key_(key), |
| 4245 size_(size), | 4247 size_(size), |
| 4246 last_modified_(last_modified) { | 4248 last_modified_(last_modified) { |
| 4247 } | 4249 } |
| 4248 | 4250 |
| 4249 } // namespace content | 4251 } // namespace content |
| OLD | NEW |