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_tracing.h" | 20 #include "content/browser/indexed_db/indexed_db_tracing.h" |
21 #include "content/browser/indexed_db/indexed_db_transaction.h" | 21 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 22 #include "content/browser/indexed_db/indexed_db_value.h" |
22 #include "content/common/indexed_db/indexed_db_key_path.h" | 23 #include "content/common/indexed_db/indexed_db_key_path.h" |
23 #include "content/common/indexed_db/indexed_db_key_range.h" | 24 #include "content/common/indexed_db/indexed_db_key_range.h" |
24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" | 25 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" |
25 | 26 |
26 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
27 using base::Int64ToString16; | 28 using base::Int64ToString16; |
28 using blink::WebIDBKeyTypeNumber; | 29 using blink::WebIDBKeyTypeNumber; |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 return; | 568 return; |
568 } | 569 } |
569 | 570 |
570 key = &backing_store_cursor->key(); | 571 key = &backing_store_cursor->key(); |
571 } | 572 } |
572 | 573 |
573 scoped_ptr<IndexedDBKey> primary_key; | 574 scoped_ptr<IndexedDBKey> primary_key; |
574 leveldb::Status s; | 575 leveldb::Status s; |
575 if (index_id == IndexedDBIndexMetadata::kInvalidId) { | 576 if (index_id == IndexedDBIndexMetadata::kInvalidId) { |
576 // Object Store Retrieval Operation | 577 // Object Store Retrieval Operation |
577 std::string value; | 578 IndexedDBValue value; |
578 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 579 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
579 id(), | 580 id(), |
580 object_store_id, | 581 object_store_id, |
581 *key, | 582 *key, |
582 &value); | 583 &value); |
583 if (!s.ok()) { | 584 if (!s.ok()) { |
584 callbacks->OnError( | 585 callbacks->OnError( |
585 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 586 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
586 "Internal error in GetRecord.")); | 587 "Internal error in GetRecord.")); |
587 return; | 588 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 callbacks->OnSuccess(); | 621 callbacks->OnSuccess(); |
621 return; | 622 return; |
622 } | 623 } |
623 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { | 624 if (cursor_type == indexed_db::CURSOR_KEY_ONLY) { |
624 // Index Value Retrieval Operation | 625 // Index Value Retrieval Operation |
625 callbacks->OnSuccess(*primary_key); | 626 callbacks->OnSuccess(*primary_key); |
626 return; | 627 return; |
627 } | 628 } |
628 | 629 |
629 // Index Referenced Value Retrieval Operation | 630 // Index Referenced Value Retrieval Operation |
630 std::string value; | 631 IndexedDBValue value; |
631 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), | 632 s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), |
632 id(), | 633 id(), |
633 object_store_id, | 634 object_store_id, |
634 *primary_key, | 635 *primary_key, |
635 &value); | 636 &value); |
636 if (!s.ok()) { | 637 if (!s.ok()) { |
637 callbacks->OnError( | 638 callbacks->OnError( |
638 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 639 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
639 "Internal error in GetRecord.")); | 640 "Internal error in GetRecord.")); |
640 return; | 641 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 transaction->BackingStoreTransaction(), | 687 transaction->BackingStoreTransaction(), |
687 database_id, | 688 database_id, |
688 object_store_id, | 689 object_store_id, |
689 static_cast<int64>(floor(key.number())) + 1, | 690 static_cast<int64>(floor(key.number())) + 1, |
690 check_current); | 691 check_current); |
691 } | 692 } |
692 | 693 |
693 struct IndexedDBDatabase::PutOperationParams { | 694 struct IndexedDBDatabase::PutOperationParams { |
694 PutOperationParams() {} | 695 PutOperationParams() {} |
695 int64 object_store_id; | 696 int64 object_store_id; |
696 std::string value; | 697 IndexedDBValue value; |
697 scoped_ptr<IndexedDBKey> key; | 698 scoped_ptr<IndexedDBKey> key; |
698 IndexedDBDatabase::PutMode put_mode; | 699 IndexedDBDatabase::PutMode put_mode; |
699 scoped_refptr<IndexedDBCallbacks> callbacks; | 700 scoped_refptr<IndexedDBCallbacks> callbacks; |
700 std::vector<IndexKeys> index_keys; | 701 std::vector<IndexKeys> index_keys; |
701 | 702 |
702 private: | 703 private: |
703 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); | 704 DISALLOW_COPY_AND_ASSIGN(PutOperationParams); |
704 }; | 705 }; |
705 | 706 |
706 void IndexedDBDatabase::Put(int64 transaction_id, | 707 void IndexedDBDatabase::Put(int64 transaction_id, |
707 int64 object_store_id, | 708 int64 object_store_id, |
708 std::string* value, | 709 IndexedDBValue* value, |
709 scoped_ptr<IndexedDBKey> key, | 710 scoped_ptr<IndexedDBKey> key, |
710 PutMode put_mode, | 711 PutMode put_mode, |
711 scoped_refptr<IndexedDBCallbacks> callbacks, | 712 scoped_refptr<IndexedDBCallbacks> callbacks, |
712 const std::vector<IndexKeys>& index_keys) { | 713 const std::vector<IndexKeys>& index_keys) { |
713 IDB_TRACE("IndexedDBDatabase::Put"); | 714 IDB_TRACE("IndexedDBDatabase::Put"); |
714 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 715 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
715 if (!transaction) | 716 if (!transaction) |
716 return; | 717 return; |
717 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); | 718 DCHECK_NE(transaction->mode(), indexed_db::TRANSACTION_READ_ONLY); |
718 | 719 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 transaction->BackingStoreTransaction(), | 1043 transaction->BackingStoreTransaction(), |
1043 id(), | 1044 id(), |
1044 params->object_store_id, | 1045 params->object_store_id, |
1045 params->index_id, | 1046 params->index_id, |
1046 *params->key_range, | 1047 *params->key_range, |
1047 params->direction); | 1048 params->direction); |
1048 } | 1049 } |
1049 } | 1050 } |
1050 | 1051 |
1051 if (!backing_store_cursor) { | 1052 if (!backing_store_cursor) { |
1052 params->callbacks->OnSuccess(static_cast<std::string*>(NULL)); | 1053 params->callbacks->OnSuccess(static_cast<IndexedDBValue*>(NULL)); |
1053 return; | 1054 return; |
1054 } | 1055 } |
1055 | 1056 |
1056 scoped_refptr<IndexedDBCursor> cursor = | 1057 scoped_refptr<IndexedDBCursor> cursor = |
1057 new IndexedDBCursor(backing_store_cursor.Pass(), | 1058 new IndexedDBCursor(backing_store_cursor.Pass(), |
1058 params->cursor_type, | 1059 params->cursor_type, |
1059 params->task_type, | 1060 params->task_type, |
1060 transaction); | 1061 transaction); |
1061 params->callbacks->OnSuccess( | 1062 params->callbacks->OnSuccess( |
1062 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); | 1063 cursor, cursor->key(), cursor->primary_key(), cursor->Value()); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 const base::string16& previous_version, | 1668 const base::string16& previous_version, |
1668 int64 previous_int_version, | 1669 int64 previous_int_version, |
1669 IndexedDBTransaction* transaction) { | 1670 IndexedDBTransaction* transaction) { |
1670 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1671 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1671 DCHECK(!transaction); | 1672 DCHECK(!transaction); |
1672 metadata_.version = previous_version; | 1673 metadata_.version = previous_version; |
1673 metadata_.int_version = previous_int_version; | 1674 metadata_.int_version = previous_int_version; |
1674 } | 1675 } |
1675 | 1676 |
1676 } // namespace content | 1677 } // namespace content |
OLD | NEW |