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

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

Issue 320833002: [IndexedDB] Use consistent enums on both sides of IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 "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
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" 33 #include "third_party/WebKit/public/platform/WebIDBTypes.h"
jsbell 2014/06/09 16:38:27 This include can be removed when added to the .h
Pritam Nikam 2014/06/11 14:05:16 Done.
34 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" 34 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h"
35 #include "third_party/leveldatabase/env_chromium.h" 35 #include "third_party/leveldatabase/env_chromium.h"
36 #include "webkit/browser/blob/blob_data_handle.h" 36 #include "webkit/browser/blob/blob_data_handle.h"
37 #include "webkit/browser/fileapi/file_stream_writer.h" 37 #include "webkit/browser/fileapi/file_stream_writer.h"
38 #include "webkit/browser/fileapi/file_writer_delegate.h" 38 #include "webkit/browser/fileapi/file_writer_delegate.h"
39 #include "webkit/browser/fileapi/local_file_stream_writer.h" 39 #include "webkit/browser/fileapi/local_file_stream_writer.h"
40 #include "webkit/common/database/database_identifier.h" 40 #include "webkit/common/database/database_identifier.h"
41 41
42 using base::FilePath; 42 using base::FilePath;
43 using base::StringPiece; 43 using base::StringPiece;
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 IndexedDBBackingStore::Transaction* transaction, 1950 IndexedDBBackingStore::Transaction* transaction,
1951 int64 database_id, 1951 int64 database_id,
1952 int64 object_store_id, 1952 int64 object_store_id,
1953 const IndexedDBKeyRange& key_range) { 1953 const IndexedDBKeyRange& key_range) {
1954 leveldb::Status s; 1954 leveldb::Status s;
1955 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor = 1955 scoped_ptr<IndexedDBBackingStore::Cursor> start_cursor =
1956 OpenObjectStoreCursor(transaction, 1956 OpenObjectStoreCursor(transaction,
1957 database_id, 1957 database_id,
1958 object_store_id, 1958 object_store_id,
1959 key_range, 1959 key_range,
1960 indexed_db::CURSOR_NEXT, 1960 blink::Next,
1961 &s); 1961 &s);
1962 if (!s.ok()) 1962 if (!s.ok())
1963 return s; 1963 return s;
1964 if (!start_cursor) 1964 if (!start_cursor)
1965 return leveldb::Status::OK(); // Empty range == delete success. 1965 return leveldb::Status::OK(); // Empty range == delete success.
1966 1966
1967 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = 1967 scoped_ptr<IndexedDBBackingStore::Cursor> end_cursor = OpenObjectStoreCursor(
1968 OpenObjectStoreCursor(transaction, 1968 transaction, database_id, object_store_id, key_range, blink::Prev, &s);
1969 database_id,
1970 object_store_id,
1971 key_range,
1972 indexed_db::CURSOR_PREV,
1973 &s);
1974 1969
1975 if (!s.ok()) 1970 if (!s.ok())
1976 return s; 1971 return s;
1977 if (!end_cursor) 1972 if (!end_cursor)
1978 return leveldb::Status::OK(); // Empty range == delete success. 1973 return leveldb::Status::OK(); // Empty range == delete success.
1979 1974
1980 BlobEntryKey start_blob_key, end_blob_key; 1975 BlobEntryKey start_blob_key, end_blob_key;
1981 1976
1982 std::string start_key = ObjectStoreDataKey::Encode( 1977 std::string start_key = ObjectStoreDataKey::Encode(
1983 database_id, object_store_id, start_cursor->key()); 1978 database_id, object_store_id, start_cursor->key());
(...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after
3552 return transaction_->GetBlobInfoForRecord(database_id_, 3547 return transaction_->GetBlobInfoForRecord(database_id_,
3553 primary_leveldb_key_, 3548 primary_leveldb_key_,
3554 &current_value_).ok(); 3549 &current_value_).ok();
3555 } 3550 }
3556 3551
3557 bool ObjectStoreCursorOptions( 3552 bool ObjectStoreCursorOptions(
3558 LevelDBTransaction* transaction, 3553 LevelDBTransaction* transaction,
3559 int64 database_id, 3554 int64 database_id,
3560 int64 object_store_id, 3555 int64 object_store_id,
3561 const IndexedDBKeyRange& range, 3556 const IndexedDBKeyRange& range,
3562 indexed_db::CursorDirection direction, 3557 blink::Direction direction,
3563 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { 3558 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) {
3564 cursor_options->database_id = database_id; 3559 cursor_options->database_id = database_id;
3565 cursor_options->object_store_id = object_store_id; 3560 cursor_options->object_store_id = object_store_id;
3566 3561
3567 bool lower_bound = range.lower().IsValid(); 3562 bool lower_bound = range.lower().IsValid();
3568 bool upper_bound = range.upper().IsValid(); 3563 bool upper_bound = range.upper().IsValid();
3569 cursor_options->forward = 3564 cursor_options->forward =
3570 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || 3565 (direction == blink::NextNoDuplicate || direction == blink::Next);
3571 direction == indexed_db::CURSOR_NEXT); 3566 cursor_options->unique = (direction == blink::NextNoDuplicate ||
3572 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || 3567 direction == blink::PrevNoDuplicate);
3573 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE);
3574 3568
3575 if (!lower_bound) { 3569 if (!lower_bound) {
3576 cursor_options->low_key = 3570 cursor_options->low_key =
3577 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey()); 3571 ObjectStoreDataKey::Encode(database_id, object_store_id, MinIDBKey());
3578 cursor_options->low_open = true; // Not included. 3572 cursor_options->low_open = true; // Not included.
3579 } else { 3573 } else {
3580 cursor_options->low_key = 3574 cursor_options->low_key =
3581 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower()); 3575 ObjectStoreDataKey::Encode(database_id, object_store_id, range.lower());
3582 cursor_options->low_open = range.lowerOpen(); 3576 cursor_options->low_open = range.lowerOpen();
3583 } 3577 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3625 3619
3626 return true; 3620 return true;
3627 } 3621 }
3628 3622
3629 bool IndexCursorOptions( 3623 bool IndexCursorOptions(
3630 LevelDBTransaction* transaction, 3624 LevelDBTransaction* transaction,
3631 int64 database_id, 3625 int64 database_id,
3632 int64 object_store_id, 3626 int64 object_store_id,
3633 int64 index_id, 3627 int64 index_id,
3634 const IndexedDBKeyRange& range, 3628 const IndexedDBKeyRange& range,
3635 indexed_db::CursorDirection direction, 3629 blink::Direction direction,
3636 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { 3630 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) {
3637 DCHECK(transaction); 3631 DCHECK(transaction);
3638 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) 3632 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id))
3639 return false; 3633 return false;
3640 3634
3641 cursor_options->database_id = database_id; 3635 cursor_options->database_id = database_id;
3642 cursor_options->object_store_id = object_store_id; 3636 cursor_options->object_store_id = object_store_id;
3643 cursor_options->index_id = index_id; 3637 cursor_options->index_id = index_id;
3644 3638
3645 bool lower_bound = range.lower().IsValid(); 3639 bool lower_bound = range.lower().IsValid();
3646 bool upper_bound = range.upper().IsValid(); 3640 bool upper_bound = range.upper().IsValid();
3647 cursor_options->forward = 3641 cursor_options->forward =
3648 (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || 3642 (direction == blink::NextNoDuplicate || direction == blink::Next);
3649 direction == indexed_db::CURSOR_NEXT); 3643 cursor_options->unique = (direction == blink::NextNoDuplicate ||
3650 cursor_options->unique = (direction == indexed_db::CURSOR_NEXT_NO_DUPLICATE || 3644 direction == blink::PrevNoDuplicate);
3651 direction == indexed_db::CURSOR_PREV_NO_DUPLICATE);
3652 3645
3653 if (!lower_bound) { 3646 if (!lower_bound) {
3654 cursor_options->low_key = 3647 cursor_options->low_key =
3655 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); 3648 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id);
3656 cursor_options->low_open = false; // Included. 3649 cursor_options->low_open = false; // Included.
3657 } else { 3650 } else {
3658 cursor_options->low_key = IndexDataKey::Encode( 3651 cursor_options->low_key = IndexDataKey::Encode(
3659 database_id, object_store_id, index_id, range.lower()); 3652 database_id, object_store_id, index_id, range.lower());
3660 cursor_options->low_open = range.lowerOpen(); 3653 cursor_options->low_open = range.lowerOpen();
3661 } 3654 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 3691
3699 return true; 3692 return true;
3700 } 3693 }
3701 3694
3702 scoped_ptr<IndexedDBBackingStore::Cursor> 3695 scoped_ptr<IndexedDBBackingStore::Cursor>
3703 IndexedDBBackingStore::OpenObjectStoreCursor( 3696 IndexedDBBackingStore::OpenObjectStoreCursor(
3704 IndexedDBBackingStore::Transaction* transaction, 3697 IndexedDBBackingStore::Transaction* transaction,
3705 int64 database_id, 3698 int64 database_id,
3706 int64 object_store_id, 3699 int64 object_store_id,
3707 const IndexedDBKeyRange& range, 3700 const IndexedDBKeyRange& range,
3708 indexed_db::CursorDirection direction, 3701 blink::Direction direction,
3709 leveldb::Status* s) { 3702 leveldb::Status* s) {
3710 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor"); 3703 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreCursor");
3711 *s = leveldb::Status::OK(); 3704 *s = leveldb::Status::OK();
3712 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 3705 LevelDBTransaction* leveldb_transaction = transaction->transaction();
3713 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; 3706 IndexedDBBackingStore::Cursor::CursorOptions cursor_options;
3714 if (!ObjectStoreCursorOptions(leveldb_transaction, 3707 if (!ObjectStoreCursorOptions(leveldb_transaction,
3715 database_id, 3708 database_id,
3716 object_store_id, 3709 object_store_id,
3717 range, 3710 range,
3718 direction, 3711 direction,
3719 &cursor_options)) 3712 &cursor_options))
3720 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3713 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3721 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl( 3714 scoped_ptr<ObjectStoreCursorImpl> cursor(new ObjectStoreCursorImpl(
3722 this, transaction, database_id, cursor_options)); 3715 this, transaction, database_id, cursor_options));
3723 if (!cursor->FirstSeek(s)) 3716 if (!cursor->FirstSeek(s))
3724 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3717 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3725 3718
3726 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); 3719 return cursor.PassAs<IndexedDBBackingStore::Cursor>();
3727 } 3720 }
3728 3721
3729 scoped_ptr<IndexedDBBackingStore::Cursor> 3722 scoped_ptr<IndexedDBBackingStore::Cursor>
3730 IndexedDBBackingStore::OpenObjectStoreKeyCursor( 3723 IndexedDBBackingStore::OpenObjectStoreKeyCursor(
3731 IndexedDBBackingStore::Transaction* transaction, 3724 IndexedDBBackingStore::Transaction* transaction,
3732 int64 database_id, 3725 int64 database_id,
3733 int64 object_store_id, 3726 int64 object_store_id,
3734 const IndexedDBKeyRange& range, 3727 const IndexedDBKeyRange& range,
3735 indexed_db::CursorDirection direction, 3728 blink::Direction direction,
3736 leveldb::Status* s) { 3729 leveldb::Status* s) {
3737 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor"); 3730 IDB_TRACE("IndexedDBBackingStore::OpenObjectStoreKeyCursor");
3738 *s = leveldb::Status::OK(); 3731 *s = leveldb::Status::OK();
3739 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 3732 LevelDBTransaction* leveldb_transaction = transaction->transaction();
3740 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; 3733 IndexedDBBackingStore::Cursor::CursorOptions cursor_options;
3741 if (!ObjectStoreCursorOptions(leveldb_transaction, 3734 if (!ObjectStoreCursorOptions(leveldb_transaction,
3742 database_id, 3735 database_id,
3743 object_store_id, 3736 object_store_id,
3744 range, 3737 range,
3745 direction, 3738 direction,
3746 &cursor_options)) 3739 &cursor_options))
3747 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3740 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3748 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl( 3741 scoped_ptr<ObjectStoreKeyCursorImpl> cursor(new ObjectStoreKeyCursorImpl(
3749 this, transaction, database_id, cursor_options)); 3742 this, transaction, database_id, cursor_options));
3750 if (!cursor->FirstSeek(s)) 3743 if (!cursor->FirstSeek(s))
3751 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3744 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3752 3745
3753 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); 3746 return cursor.PassAs<IndexedDBBackingStore::Cursor>();
3754 } 3747 }
3755 3748
3756 scoped_ptr<IndexedDBBackingStore::Cursor> 3749 scoped_ptr<IndexedDBBackingStore::Cursor>
3757 IndexedDBBackingStore::OpenIndexKeyCursor( 3750 IndexedDBBackingStore::OpenIndexKeyCursor(
3758 IndexedDBBackingStore::Transaction* transaction, 3751 IndexedDBBackingStore::Transaction* transaction,
3759 int64 database_id, 3752 int64 database_id,
3760 int64 object_store_id, 3753 int64 object_store_id,
3761 int64 index_id, 3754 int64 index_id,
3762 const IndexedDBKeyRange& range, 3755 const IndexedDBKeyRange& range,
3763 indexed_db::CursorDirection direction, 3756 blink::Direction direction,
3764 leveldb::Status* s) { 3757 leveldb::Status* s) {
3765 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor"); 3758 IDB_TRACE("IndexedDBBackingStore::OpenIndexKeyCursor");
3766 *s = leveldb::Status::OK(); 3759 *s = leveldb::Status::OK();
3767 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 3760 LevelDBTransaction* leveldb_transaction = transaction->transaction();
3768 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; 3761 IndexedDBBackingStore::Cursor::CursorOptions cursor_options;
3769 if (!IndexCursorOptions(leveldb_transaction, 3762 if (!IndexCursorOptions(leveldb_transaction,
3770 database_id, 3763 database_id,
3771 object_store_id, 3764 object_store_id,
3772 index_id, 3765 index_id,
3773 range, 3766 range,
3774 direction, 3767 direction,
3775 &cursor_options)) 3768 &cursor_options))
3776 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3769 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3777 scoped_ptr<IndexKeyCursorImpl> cursor( 3770 scoped_ptr<IndexKeyCursorImpl> cursor(
3778 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options)); 3771 new IndexKeyCursorImpl(this, transaction, database_id, cursor_options));
3779 if (!cursor->FirstSeek(s)) 3772 if (!cursor->FirstSeek(s))
3780 return scoped_ptr<IndexedDBBackingStore::Cursor>(); 3773 return scoped_ptr<IndexedDBBackingStore::Cursor>();
3781 3774
3782 return cursor.PassAs<IndexedDBBackingStore::Cursor>(); 3775 return cursor.PassAs<IndexedDBBackingStore::Cursor>();
3783 } 3776 }
3784 3777
3785 scoped_ptr<IndexedDBBackingStore::Cursor> 3778 scoped_ptr<IndexedDBBackingStore::Cursor>
3786 IndexedDBBackingStore::OpenIndexCursor( 3779 IndexedDBBackingStore::OpenIndexCursor(
3787 IndexedDBBackingStore::Transaction* transaction, 3780 IndexedDBBackingStore::Transaction* transaction,
3788 int64 database_id, 3781 int64 database_id,
3789 int64 object_store_id, 3782 int64 object_store_id,
3790 int64 index_id, 3783 int64 index_id,
3791 const IndexedDBKeyRange& range, 3784 const IndexedDBKeyRange& range,
3792 indexed_db::CursorDirection direction, 3785 blink::Direction direction,
3793 leveldb::Status* s) { 3786 leveldb::Status* s) {
3794 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor"); 3787 IDB_TRACE("IndexedDBBackingStore::OpenIndexCursor");
3795 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 3788 LevelDBTransaction* leveldb_transaction = transaction->transaction();
3796 IndexedDBBackingStore::Cursor::CursorOptions cursor_options; 3789 IndexedDBBackingStore::Cursor::CursorOptions cursor_options;
3797 if (!IndexCursorOptions(leveldb_transaction, 3790 if (!IndexCursorOptions(leveldb_transaction,
3798 database_id, 3791 database_id,
3799 object_store_id, 3792 object_store_id,
3800 index_id, 3793 index_id,
3801 range, 3794 range,
3802 direction, 3795 direction,
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 const GURL& url, 4171 const GURL& url,
4179 int64_t key) 4172 int64_t key)
4180 : is_file_(false), url_(url), key_(key) {} 4173 : is_file_(false), url_(url), key_(key) {}
4181 4174
4182 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4175 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4183 const FilePath& file_path, 4176 const FilePath& file_path,
4184 int64_t key) 4177 int64_t key)
4185 : is_file_(true), file_path_(file_path), key_(key) {} 4178 : is_file_(true), file_path_(file_path), key_(key) {}
4186 4179
4187 } // namespace content 4180 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698