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 12 matching lines...) Expand all Loading... |
23 #include "content/browser/indexed_db/indexed_db_value.h" | 23 #include "content/browser/indexed_db/indexed_db_value.h" |
24 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" | 24 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" |
25 #include "content/browser/indexed_db/leveldb/leveldb_database.h" | 25 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
26 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 26 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
27 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 27 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
28 #include "content/common/indexed_db/indexed_db_key.h" | 28 #include "content/common/indexed_db/indexed_db_key.h" |
29 #include "content/common/indexed_db/indexed_db_key_path.h" | 29 #include "content/common/indexed_db/indexed_db_key_path.h" |
30 #include "content/common/indexed_db/indexed_db_key_range.h" | 30 #include "content/common/indexed_db/indexed_db_key_range.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "net/url_request/url_request_context.h" | 32 #include "net/url_request/url_request_context.h" |
33 #include "third_party/WebKit/public/platform/WebIDBTypes.h" | |
34 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" | 33 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" |
35 #include "third_party/leveldatabase/env_chromium.h" | 34 #include "third_party/leveldatabase/env_chromium.h" |
36 #include "webkit/browser/blob/blob_data_handle.h" | 35 #include "webkit/browser/blob/blob_data_handle.h" |
37 #include "webkit/browser/fileapi/file_stream_writer.h" | 36 #include "webkit/browser/fileapi/file_stream_writer.h" |
38 #include "webkit/browser/fileapi/file_writer_delegate.h" | 37 #include "webkit/browser/fileapi/file_writer_delegate.h" |
39 #include "webkit/browser/fileapi/local_file_stream_writer.h" | 38 #include "webkit/browser/fileapi/local_file_stream_writer.h" |
40 #include "webkit/common/database/database_identifier.h" | 39 #include "webkit/common/database/database_identifier.h" |
41 | 40 |
42 using base::FilePath; | 41 using base::FilePath; |
43 using base::StringPiece; | 42 using base::StringPiece; |
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 IndexedDBBackingStore::Transaction* transaction, | 1949 IndexedDBBackingStore::Transaction* transaction, |
1951 int64 database_id, | 1950 int64 database_id, |
1952 int64 object_store_id, | 1951 int64 object_store_id, |
1953 const IndexedDBKeyRange& key_range) { | 1952 const IndexedDBKeyRange& key_range) { |
1954 leveldb::Status s; | 1953 leveldb::Status s; |
1955 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor = | 1954 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor = |
1956 OpenObjectStoreCursor(transaction, | 1955 OpenObjectStoreCursor(transaction, |
1957 database_id, | 1956 database_id, |
1958 object_store_id, | 1957 object_store_id, |
1959 key_range, | 1958 key_range, |
1960 indexed_db::CURSOR_NEXT, | 1959 blink::WebIDBCursorDirectionNext, |
1961 &s); | 1960 &s); |
1962 if (!s.ok()) | 1961 if (!s.ok()) |
1963 return s; | 1962 return s; |
1964 if (!start_cursor) | 1963 if (!start_cursor) |
1965 return leveldb::Status::OK(); // Empty range == delete success. | 1964 return leveldb::Status::OK(); // Empty range == delete success. |
1966 | 1965 |
1967 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = | 1966 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = |
1968 OpenObjectStoreCursor(transaction, | 1967 OpenObjectStoreCursor(transaction, |
1969 database_id, | 1968 database_id, |
1970 object_store_id, | 1969 object_store_id, |
1971 key_range, | 1970 key_range, |
1972 indexed_db::CURSOR_PREV, | 1971 blink::WebIDBCursorDirectionPrev, |
1973 &s); | 1972 &s); |
1974 | 1973 |
1975 if (!s.ok()) | 1974 if (!s.ok()) |
1976 return s; | 1975 return s; |
1977 if (!end_cursor) | 1976 if (!end_cursor) |
1978 return leveldb::Status::OK(); // Empty range == delete success. | 1977 return leveldb::Status::OK(); // Empty range == delete success. |
1979 | 1978 |
1980 BlobEntryKey start_blob_key, end_blob_key; | 1979 BlobEntryKey start_blob_key, end_blob_key; |
1981 | 1980 |
1982 std::string start_key = ObjectStoreDataKey::Encode( | 1981 std::string start_key = ObjectStoreDataKey::Encode( |
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 return transaction_->GetBlobInfoForRecord(database_id_, | 3551 return transaction_->GetBlobInfoForRecord(database_id_, |
3553 primary_leveldb_key_, | 3552 primary_leveldb_key_, |
3554 ¤t_value_).ok(); | 3553 ¤t_value_).ok(); |
3555 } | 3554 } |
3556 | 3555 |
3557 bool ObjectStoreCursorOptions( | 3556 bool ObjectStoreCursorOptions( |
3558 LevelDBTransaction* transaction, | 3557 LevelDBTransaction* transaction, |
3559 int64 database_id, | 3558 int64 database_id, |
3560 int64 object_store_id, | 3559 int64 object_store_id, |
3561 const IndexedDBKeyRange& range, | 3560 const IndexedDBKeyRange& range, |
3562 indexed_db::CursorDirection direction, | 3561 blink::WebIDBCursorDirection direction, |
3563 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3562 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
3564 cursor_options->database_id = database_id; | 3563 cursor_options->database_id = database_id; |
3565 cursor_options->object_store_id = object_store_id; | 3564 cursor_options->object_store_id = object_store_id; |
3566 | 3565 |
3567 bool lower_bound = range.lower().IsValid(); | 3566 bool lower_bound = range.lower().IsValid(); |
3568 bool upper_bound = range.upper().IsValid(); | 3567 bool upper_bound = range.upper().IsValid(); |
3569 cursor_options->forward = | 3568 cursor_options->forward = |
3570 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3569 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
3571 direction == indexed_db::CURSOR_NEXT); | 3570 direction == blink::WebIDBCursorDirectionNext); |
3572 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3571 cursor_options->unique = |
3573 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE); | 3572 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3573 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); |
3574 | 3574 |
3575 if (!lower_bound) { | 3575 if (!lower_bound) { |
3576 cursor_options->low_key = | 3576 cursor_options->low_key = |
3577 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); | 3577 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); |
3578 cursor_options->low_open = true; // Not included. | 3578 cursor_options->low_open = true; // Not included. |
3579 } else { | 3579 } else { |
3580 cursor_options->low_key = | 3580 cursor_options->low_key = |
3581 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); | 3581 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); |
3582 cursor_options->low_open = range.lowerOpen(); | 3582 cursor_options->low_open = range.lowerOpen(); |
3583 } | 3583 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3625 | 3625 |
3626 return true; | 3626 return true; |
3627 } | 3627 } |
3628 | 3628 |
3629 bool IndexCursorOptions( | 3629 bool IndexCursorOptions( |
3630 LevelDBTransaction* transaction, | 3630 LevelDBTransaction* transaction, |
3631 int64 database_id, | 3631 int64 database_id, |
3632 int64 object_store_id, | 3632 int64 object_store_id, |
3633 int64 index_id, | 3633 int64 index_id, |
3634 const IndexedDBKeyRange& range, | 3634 const IndexedDBKeyRange& range, |
3635 indexed_db::CursorDirection direction, | 3635 blink::WebIDBCursorDirection direction, |
3636 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3636 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
3637 DCHECK(transaction); | 3637 DCHECK(transaction); |
3638 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) | 3638 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) |
3639 return false; | 3639 return false; |
3640 | 3640 |
3641 cursor_options->database_id = database_id; | 3641 cursor_options->database_id = database_id; |
3642 cursor_options->object_store_id = object_store_id; | 3642 cursor_options->object_store_id = object_store_id; |
3643 cursor_options->index_id = index_id; | 3643 cursor_options->index_id = index_id; |
3644 | 3644 |
3645 bool lower_bound = range.lower().IsValid(); | 3645 bool lower_bound = range.lower().IsValid(); |
3646 bool upper_bound = range.upper().IsValid(); | 3646 bool upper_bound = range.upper().IsValid(); |
3647 cursor_options->forward = | 3647 cursor_options->forward = |
3648 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3648 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
3649 direction == indexed_db::CURSOR_NEXT); | 3649 direction == blink::WebIDBCursorDirectionNext); |
3650 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || | 3650 cursor_options->unique = |
3651 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE); | 3651 (direction == blink::WebIDBCursorDirectionNextNoDuplicate || |
| 3652 direction == blink::WebIDBCursorDirectionPrevNoDuplicate); |
3652 | 3653 |
3653 if (!lower_bound) { | 3654 if (!lower_bound) { |
3654 cursor_options->low_key = | 3655 cursor_options->low_key = |
3655 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); | 3656 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); |
3656 cursor_options->low_open = false; // Included. | 3657 cursor_options->low_open = false; // Included. |
3657 } else { | 3658 } else { |
3658 cursor_options->low_key = IndexDataKey::Encode( | 3659 cursor_options->low_key = IndexDataKey::Encode( |
3659 database_id, object_store_id, index_id, range.lower()); | 3660 database_id, object_store_id, index_id, range.lower()); |
3660 cursor_options->low_open = range.lowerOpen(); | 3661 cursor_options->low_open = range.lowerOpen(); |
3661 } | 3662 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3698 | 3699 |
3699 return true; | 3700 return true; |
3700 } | 3701 } |
3701 | 3702 |
3702 scoped_ptr<IndexedDBBackingStore::Cursor> | 3703 scoped_ptr<IndexedDBBackingStore::Cursor> |
3703 IndexedDBBackingStore::OpenObjectStoreCursor( | 3704 IndexedDBBackingStore::OpenObjectStoreCursor( |
3704 IndexedDBBackingStore::Transaction* transaction, | 3705 IndexedDBBackingStore::Transaction* transaction, |
3705 int64 database_id, | 3706 int64 database_id, |
3706 int64 object_store_id, | 3707 int64 object_store_id, |
3707 const IndexedDBKeyRange& range, | 3708 const IndexedDBKeyRange& range, |
3708 indexed_db::CursorDirection direction, | 3709 blink::WebIDBCursorDirection direction, |
3709 leveldb::Status* s) { | 3710 leveldb::Status* s) { |
3710 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); | 3711 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); |
3711 *s = leveldb::Status::OK(); | 3712 *s = leveldb::Status::OK(); |
3712 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3713 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
3713 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3714 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
3714 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3715 if (!ObjectStoreCursorOptions(leveldb_transaction, |
3715 database_id, | 3716 database_id, |
3716 object_store_id, | 3717 object_store_id, |
3717 range, | 3718 range, |
3718 direction, | 3719 direction, |
3719 &cursor_options)) | 3720 &cursor_options)) |
3720 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3721 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3721 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl( | 3722 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl( |
3722 this, transaction, database_id, cursor_options)); | 3723 this, transaction, database_id, cursor_options)); |
3723 if (!cursor->FirstSeek(s)) | 3724 if (!cursor->FirstSeek(s)) |
3724 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3725 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3725 | 3726 |
3726 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3727 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
3727 } | 3728 } |
3728 | 3729 |
3729 scoped_ptr<IndexedDBBackingStore::Cursor> | 3730 scoped_ptr<IndexedDBBackingStore::Cursor> |
3730 IndexedDBBackingStore::OpenObjectStoreKeyCursor( | 3731 IndexedDBBackingStore::OpenObjectStoreKeyCursor( |
3731 IndexedDBBackingStore::Transaction* transaction, | 3732 IndexedDBBackingStore::Transaction* transaction, |
3732 int64 database_id, | 3733 int64 database_id, |
3733 int64 object_store_id, | 3734 int64 object_store_id, |
3734 const IndexedDBKeyRange& range, | 3735 const IndexedDBKeyRange& range, |
3735 indexed_db::CursorDirection direction, | 3736 blink::WebIDBCursorDirection direction, |
3736 leveldb::Status* s) { | 3737 leveldb::Status* s) { |
3737 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); | 3738 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); |
3738 *s = leveldb::Status::OK(); | 3739 *s = leveldb::Status::OK(); |
3739 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3740 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
3740 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3741 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
3741 if (!ObjectStoreCursorOptions(leveldb_transaction, | 3742 if (!ObjectStoreCursorOptions(leveldb_transaction, |
3742 database_id, | 3743 database_id, |
3743 object_store_id, | 3744 object_store_id, |
3744 range, | 3745 range, |
3745 direction, | 3746 direction, |
3746 &cursor_options)) | 3747 &cursor_options)) |
3747 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3748 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3748 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl( | 3749 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl( |
3749 this, transaction, database_id, cursor_options)); | 3750 this, transaction, database_id, cursor_options)); |
3750 if (!cursor->FirstSeek(s)) | 3751 if (!cursor->FirstSeek(s)) |
3751 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3752 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3752 | 3753 |
3753 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3754 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
3754 } | 3755 } |
3755 | 3756 |
3756 scoped_ptr<IndexedDBBackingStore::Cursor> | 3757 scoped_ptr<IndexedDBBackingStore::Cursor> |
3757 IndexedDBBackingStore::OpenIndexKeyCursor( | 3758 IndexedDBBackingStore::OpenIndexKeyCursor( |
3758 IndexedDBBackingStore::Transaction* transaction, | 3759 IndexedDBBackingStore::Transaction* transaction, |
3759 int64 database_id, | 3760 int64 database_id, |
3760 int64 object_store_id, | 3761 int64 object_store_id, |
3761 int64 index_id, | 3762 int64 index_id, |
3762 const IndexedDBKeyRange& range, | 3763 const IndexedDBKeyRange& range, |
3763 indexed_db::CursorDirection direction, | 3764 blink::WebIDBCursorDirection direction, |
3764 leveldb::Status* s) { | 3765 leveldb::Status* s) { |
3765 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor"); | 3766 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor"); |
3766 *s = leveldb::Status::OK(); | 3767 *s = leveldb::Status::OK(); |
3767 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3768 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
3768 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3769 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
3769 if (!IndexCursorOptions(leveldb_transaction, | 3770 if (!IndexCursorOptions(leveldb_transaction, |
3770 database_id, | 3771 database_id, |
3771 object_store_id, | 3772 object_store_id, |
3772 index_id, | 3773 index_id, |
3773 range, | 3774 range, |
3774 direction, | 3775 direction, |
3775 &cursor_options)) | 3776 &cursor_options)) |
3776 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3777 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3777 scoped_ptr<IndexKeyCursorImpl> cursor( | 3778 scoped_ptr<IndexKeyCursorImpl> cursor( |
3778 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options)); | 3779 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options)); |
3779 if (!cursor->FirstSeek(s)) | 3780 if (!cursor->FirstSeek(s)) |
3780 return scoped_ptr<IndexedDBBackingStore::Cursor>(); | 3781 return scoped_ptr<IndexedDBBackingStore::Cursor>(); |
3781 | 3782 |
3782 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); | 3783 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); |
3783 } | 3784 } |
3784 | 3785 |
3785 scoped_ptr<IndexedDBBackingStore::Cursor> | 3786 scoped_ptr<IndexedDBBackingStore::Cursor> |
3786 IndexedDBBackingStore::OpenIndexCursor( | 3787 IndexedDBBackingStore::OpenIndexCursor( |
3787 IndexedDBBackingStore::Transaction* transaction, | 3788 IndexedDBBackingStore::Transaction* transaction, |
3788 int64 database_id, | 3789 int64 database_id, |
3789 int64 object_store_id, | 3790 int64 object_store_id, |
3790 int64 index_id, | 3791 int64 index_id, |
3791 const IndexedDBKeyRange& range, | 3792 const IndexedDBKeyRange& range, |
3792 indexed_db::CursorDirection direction, | 3793 blink::WebIDBCursorDirection direction, |
3793 leveldb::Status* s) { | 3794 leveldb::Status* s) { |
3794 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor"); | 3795 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor"); |
3795 LevelDBTransaction* leveldb_transaction = transaction->transaction(); | 3796 LevelDBTransaction* leveldb_transaction = transaction->transaction(); |
3796 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; | 3797 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; |
3797 if (!IndexCursorOptions(leveldb_transaction, | 3798 if (!IndexCursorOptions(leveldb_transaction, |
3798 database_id, | 3799 database_id, |
3799 object_store_id, | 3800 object_store_id, |
3800 index_id, | 3801 index_id, |
3801 range, | 3802 range, |
3802 direction, | 3803 direction, |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4178 const GURL& url, | 4179 const GURL& url, |
4179 int64_t key) | 4180 int64_t key) |
4180 : is_file_(false), url_(url), key_(key) {} | 4181 : is_file_(false), url_(url), key_(key) {} |
4181 | 4182 |
4182 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4183 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
4183 const FilePath& file_path, | 4184 const FilePath& file_path, |
4184 int64_t key) | 4185 int64_t key) |
4185 : is_file_(true), file_path_(file_path), key_(key) {} | 4186 : is_file_(true), file_path_(file_path), key_(key) {} |
4186 | 4187 |
4187 } // namespace content | 4188 } // namespace content |
OLD | NEW |