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_database.h" | 5 #include "content/browser/indexed_db/indexed_db_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "content/browser/indexed_db/indexed_db_connection.h" | 16 #include "content/browser/indexed_db/indexed_db_connection.h" |
17 #include "content/browser/indexed_db/indexed_db_cursor.h" | 17 #include "content/browser/indexed_db/indexed_db_cursor.h" |
18 #include "content/browser/indexed_db/indexed_db_factory.h" | 18 #include "content/browser/indexed_db/indexed_db_factory.h" |
19 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 19 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
20 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 20 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
21 #include "content/browser/indexed_db/indexed_db_tracing.h" | 21 #include "content/browser/indexed_db/indexed_db_tracing.h" |
22 #include "content/browser/indexed_db/indexed_db_transaction.h" | 22 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 23 #include "content/browser/indexed_db/indexed_db_value.h" |
23 #include "content/common/indexed_db/indexed_db_key_path.h" | 24 #include "content/common/indexed_db/indexed_db_key_path.h" |
24 #include "content/common/indexed_db/indexed_db_key_range.h" | 25 #include "content/common/indexed_db/indexed_db_key_range.h" |
25 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 26 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
26 | 27 |
27 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
28 using base::Int64ToString16; | 29 using base::Int64ToString16; |
29 using blink::WebIDBKeyTypeNumber; | 30 using blink::WebIDBKeyTypeNumber; |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 return; | 555 return; |
555 } | 556 } |
556 | 557 |
557 key = &backing_store_cursor->key(); | 558 key = &backing_store_cursor->key(); |
558 } | 559 } |
559 | 560 |
560 scoped_ptr<IndexedDBKey> primary_key; | 561 scoped_ptr<IndexedDBKey> primary_key; |
561 leveldb::Status s; | 562 leveldb::Status s; |
562 if (index_id == IndexedDBIndexMetadata::kInvalidId) { | 563 if (index_id == IndexedDBIndexMetadata::kInvalidId) { |
563 // Object Store Retrieval Operation | 564 // Object Store Retrieval Operation |
564 std::string value; | 565 IndexedDBValue value; |
565 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 566 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
566 id(), | 567 id(), |
567 object_store_id, | 568 object_store_id, |
568 *key, | 569 *key, |
569 &value); | 570 &value); |
570 if (!s.ok()) { | 571 if (!s.ok()) { |
571 callbacks->OnError( | 572 callbacks->OnError( |
572 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 573 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
573 "Internal error in GetRecord.")); | 574 "Internal error in GetRecord.")); |
574 return; | 575 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 callbacks->OnSuccess(); | 608 callbacks->OnSuccess(); |
608 return; | 609 return; |
609 } | 610 } |
610 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 611 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
611 // Index Value Retrieval Operation | 612 // Index Value Retrieval Operation |
612 callbacks->OnSuccess(*primary_key); | 613 callbacks->OnSuccess(*primary_key); |
613 return; | 614 return; |
614 } | 615 } |
615 | 616 |
616 // Index Referenced Value Retrieval Operation | 617 // Index Referenced Value Retrieval Operation |
617 std::string value; | 618 IndexedDBValue value; |
618 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 619 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
619 id(), | 620 id(), |
620 object_store_id, | 621 object_store_id, |
621 *primary_key, | 622 *primary_key, |
622 &value); | 623 &value); |
623 if (!s.ok()) { | 624 if (!s.ok()) { |
624 callbacks->OnError( | 625 callbacks->OnError( |
625 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 626 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
626 "Internal error in GetRecord.")); | 627 "Internal error in GetRecord.")); |
627 return; | 628 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 transaction->BackingStoreTransaction(), | 674 transaction->BackingStoreTransaction(), |
674 database_id, | 675 database_id, |
675 object_store_id, | 676 object_store_id, |
676 static_cast<int64>(floor(key.number())) + 1, | 677 static_cast<int64>(floor(key.number())) + 1, |
677 check_current); | 678 check_current); |
678 } | 679 } |
679 | 680 |
680 struct IndexedDBDatabase::PutOperationParams { | 681 struct IndexedDBDatabase::PutOperationParams { |
681 PutOperationParams() {} | 682 PutOperationParams() {} |
682 int64 object_store_id; | 683 int64 object_store_id; |
683 std::string value; | 684 IndexedDBValue value; |
684 scoped_ptr<IndexedDBKey> key; | 685 scoped_ptr<IndexedDBKey> key; |
685 IndexedDBDatabase::PutMode put_mode; | 686 IndexedDBDatabase::PutMode put_mode; |
686 scoped_refptr<IndexedDBCallbacks> callbacks; | 687 scoped_refptr<IndexedDBCallbacks> callbacks; |
687 std::vector<IndexKeys> index_keys; | 688 std::vector<IndexKeys> index_keys; |
688 | 689 |
689 private: | 690 private: |
690 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 691 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
691 }; | 692 }; |
692 | 693 |
693 void IndexedDBDatabase::Put(int64 transaction_id, | 694 void IndexedDBDatabase::Put(int64 transaction_id, |
694 int64 object_store_id, | 695 int64 object_store_id, |
695 std::string* value, | 696 IndexedDBValue* value, |
696 scoped_ptr<IndexedDBKey> key, | 697 scoped_ptr<IndexedDBKey> key, |
697 PutMode put_mode, | 698 PutMode put_mode, |
698 scoped_refptr<IndexedDBCallbacks> callbacks, | 699 scoped_refptr<IndexedDBCallbacks> callbacks, |
699 const std::vector<IndexKeys>& index_keys) { | 700 const std::vector<IndexKeys>& index_keys) { |
700 IDB_TRACE("IndexedDBDatabase::Put"); | 701 IDB_TRACE("IndexedDBDatabase::Put"); |
701 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 702 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
702 if (!transaction) | 703 if (!transaction) |
703 return; | 704 return; |
704 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 705 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
705 | 706 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 transaction->BackingStoreTransaction(), | 1030 transaction->BackingStoreTransaction(), |
1030 id(), | 1031 id(), |
1031 params->object_store_id, | 1032 params->object_store_id, |
1032 params->index_id, | 1033 params->index_id, |
1033 *params->key_range, | 1034 *params->key_range, |
1034 params->direction); | 1035 params->direction); |
1035 } | 1036 } |
1036 } | 1037 } |
1037 | 1038 |
1038 if (!backing_store_cursor) { | 1039 if (!backing_store_cursor) { |
1039 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); | 1040 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
1040 return; | 1041 return; |
1041 } | 1042 } |
1042 | 1043 |
1043 scoped_refptr<IndexedDBCursor> cursor = | 1044 scoped_refptr<IndexedDBCursor> cursor = |
1044 new IndexedDBCursor(backing_store_cursor.Pass(), | 1045 new IndexedDBCursor(backing_store_cursor.Pass(), |
1045 params->cursor_type, | 1046 params->cursor_type, |
1046 params->task_type, | 1047 params->task_type, |
1047 transaction); | 1048 transaction); |
1048 params->callbacks->OnSuccess( | 1049 params->callbacks->OnSuccess( |
1049 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1050 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 const base::string16& previous_version, | 1655 const base::string16& previous_version, |
1655 int64 previous_int_version, | 1656 int64 previous_int_version, |
1656 IndexedDBTransaction* transaction) { | 1657 IndexedDBTransaction* transaction) { |
1657 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1658 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1658 DCHECK(!transaction); | 1659 DCHECK(!transaction); |
1659 metadata_.version = previous_version; | 1660 metadata_.version = previous_version; |
1660 metadata_.int_version = previous_int_version; | 1661 metadata_.int_version = previous_int_version; |
1661 } | 1662 } |
1662 | 1663 |
1663 } // namespace content | 1664 } // namespace content |
OLD | NEW |