Chromium Code Reviews| 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 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 | 799 |
| 800 void IndexedDBDatabase::AddPendingObserver( | 800 void IndexedDBDatabase::AddPendingObserver( |
| 801 IndexedDBTransaction* transaction, | 801 IndexedDBTransaction* transaction, |
| 802 int32_t observer_id, | 802 int32_t observer_id, |
| 803 const IndexedDBObserver::Options& options) { | 803 const IndexedDBObserver::Options& options) { |
| 804 DCHECK(transaction); | 804 DCHECK(transaction); |
| 805 transaction->AddPendingObserver(observer_id, options); | 805 transaction->AddPendingObserver(observer_id, options); |
| 806 } | 806 } |
| 807 | 807 |
| 808 // TODO(palakj): Augment the function with IDBValue later. Issue | 808 // TODO(palakj): Augment the function with IDBValue later. Issue |
| 809 // crbug.com/609934. | 809 // crbug.com/609934. |
|
cmumford
2017/01/09 21:31:25
Is this comment still relevant?
dmurph
2017/01/10 00:17:39
Done.
| |
| 810 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, | 810 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, |
| 811 int64_t object_store_id, | 811 int64_t object_store_id, |
| 812 blink::WebIDBOperationType type, | 812 blink::WebIDBOperationType type, |
| 813 const IndexedDBKeyRange& key_range) { | 813 const IndexedDBKeyRange& key_range, |
| 814 IndexedDBValue* value) { | |
| 814 for (auto* connection : connections_) { | 815 for (auto* connection : connections_) { |
| 815 bool recorded = false; | 816 bool recorded = false; |
| 816 for (const auto& observer : connection->active_observers()) { | 817 for (const auto& observer : connection->active_observers()) { |
| 817 if (!observer->IsRecordingType(type) || | 818 if (!observer->IsRecordingType(type) || |
| 818 !observer->IsRecordingObjectStore(object_store_id)) | 819 !observer->IsRecordingObjectStore(object_store_id)) |
| 819 continue; | 820 continue; |
| 820 if (!recorded) { | 821 if (!recorded) { |
| 821 auto observation = ::indexed_db::mojom::Observation::New(); | 822 auto observation = ::indexed_db::mojom::Observation::New(); |
| 822 observation->object_store_id = object_store_id; | 823 observation->object_store_id = object_store_id; |
| 823 observation->type = type; | 824 observation->type = type; |
| 824 if (type != blink::WebIDBClear) | 825 if (type != blink::WebIDBClear) |
| 825 observation->key_range = key_range; | 826 observation->key_range = key_range; |
| 826 transaction->AddObservation(connection->id(), std::move(observation)); | 827 transaction->AddObservation(connection->id(), std::move(observation)); |
| 827 recorded = true; | 828 recorded = true; |
| 828 } | 829 } |
| 829 transaction->RecordObserverForLastObservation(connection->id(), | 830 auto* changes_ptr = |
| 830 observer->id()); | 831 transaction->GetPendingChangesForConnection(connection->id()); |
| 832 DCHECK(changes_ptr); | |
|
cmumford
2017/01/09 21:31:25
We don't generally check for NULL ptrs just before
dmurph
2017/01/10 00:17:39
Done.
| |
| 833 ::indexed_db::mojom::ObserverChangesPtr& changes = *changes_ptr; | |
| 834 | |
| 835 changes->observation_index_map[observer->id()].push_back( | |
| 836 changes->observations.size() - 1); | |
| 837 if (observer->include_transaction() && | |
| 838 changes->transaction_map.find(observer->id()) == | |
|
cmumford
2017/01/09 21:31:25
I think this is simpler:
if (!base::ContainsKey(
dmurph
2017/01/10 00:17:39
Done.
| |
| 839 changes->transaction_map.end()) { | |
| 840 IndexedDBTransaction* observer_transaction = | |
| 841 connection->CreateTransaction( | |
| 842 connection->NextObserverTransactionId(), | |
| 843 observer->object_store_ids(), | |
| 844 blink::WebIDBTransactionModeReadOnly, | |
| 845 new IndexedDBBackingStore::Transaction(backing_store_.get())); | |
| 846 transaction_coordinator_.DidCreateObserverTransaction( | |
| 847 observer_transaction); | |
| 848 observer_transaction->Start(); | |
| 849 transaction_count_++; | |
|
cmumford
2017/01/09 21:31:25
Start posts a task. Should transaction_count_ be i
dmurph
2017/01/10 00:17:39
Done.
| |
| 850 | |
| 851 auto mojo_transaction = ::indexed_db::mojom::ObserverTransaction::New(); | |
| 852 mojo_transaction->id = observer_transaction->id(); | |
| 853 for (int64_t object_store : observer->object_store_ids()) { | |
|
cmumford
2017/01/09 21:31:25
s/object_store/id/ or maybe s/object_store/object_
dmurph
2017/01/10 00:17:39
Done.
| |
| 854 mojo_transaction->scope.push_back(object_store); | |
| 855 } | |
| 856 changes->transaction_map[observer->id()] = std::move(mojo_transaction); | |
| 857 } | |
| 858 if (value && observer->values() && !changes->observations.back()->value) { | |
| 859 IndexedDBValue copy = *value; | |
| 860 changes->observations.back()->value = | |
| 861 IndexedDBCallbacks::ConvertValue(©); | |
| 862 } | |
| 831 } | 863 } |
| 832 } | 864 } |
| 833 } | 865 } |
| 834 | 866 |
| 835 void IndexedDBDatabase::SendObservations( | 867 void IndexedDBDatabase::SendObservations( |
| 836 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) { | 868 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) { |
| 837 for (auto* conn : connections_) { | 869 for (auto* conn : connections_) { |
| 838 auto it = changes_map.find(conn->id()); | 870 auto it = changes_map.find(conn->id()); |
| 839 if (it != changes_map.end()) | 871 if (it == changes_map.end()) |
|
pwnall
2017/01/10 01:01:24
FWIW, the previous version seems mildly easier to
dmurph
2017/01/10 20:40:00
I think they're both similar, this was most likely
| |
| 840 conn->callbacks()->OnDatabaseChange(std::move(it->second)); | 872 continue; |
| 873 | |
| 874 // Create our transactions if applicable. | |
| 875 conn->callbacks()->OnDatabaseChange(std::move(it->second)); | |
| 841 } | 876 } |
| 842 } | 877 } |
| 843 | 878 |
| 844 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction, | 879 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction, |
| 845 int64_t object_store_id, | 880 int64_t object_store_id, |
| 846 int64_t index_id, | 881 int64_t index_id, |
| 847 std::unique_ptr<IndexedDBKeyRange> key_range, | 882 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 848 bool key_only, | 883 bool key_only, |
| 849 int64_t max_count, | 884 int64_t max_count, |
| 850 scoped_refptr<IndexedDBCallbacks> callbacks) { | 885 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1334 } | 1369 } |
| 1335 { | 1370 { |
| 1336 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", | 1371 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", |
| 1337 transaction->id()); | 1372 transaction->id()); |
| 1338 params->callbacks->OnSuccess(*key); | 1373 params->callbacks->OnSuccess(*key); |
| 1339 } | 1374 } |
| 1340 FilterObservation(transaction, params->object_store_id, | 1375 FilterObservation(transaction, params->object_store_id, |
| 1341 params->put_mode == blink::WebIDBPutModeAddOnly | 1376 params->put_mode == blink::WebIDBPutModeAddOnly |
| 1342 ? blink::WebIDBAdd | 1377 ? blink::WebIDBAdd |
| 1343 : blink::WebIDBPut, | 1378 : blink::WebIDBPut, |
| 1344 IndexedDBKeyRange(*key)); | 1379 IndexedDBKeyRange(*key), ¶ms->value); |
| 1345 return s; | 1380 return s; |
| 1346 } | 1381 } |
| 1347 | 1382 |
| 1348 void IndexedDBDatabase::SetIndexKeys( | 1383 void IndexedDBDatabase::SetIndexKeys( |
| 1349 IndexedDBTransaction* transaction, | 1384 IndexedDBTransaction* transaction, |
| 1350 int64_t object_store_id, | 1385 int64_t object_store_id, |
| 1351 std::unique_ptr<IndexedDBKey> primary_key, | 1386 std::unique_ptr<IndexedDBKey> primary_key, |
| 1352 const std::vector<IndexedDBIndexKeys>& index_keys) { | 1387 const std::vector<IndexedDBIndexKeys>& index_keys) { |
| 1353 DCHECK(transaction); | 1388 DCHECK(transaction); |
| 1354 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id()); | 1389 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id()); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", | 1683 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", |
| 1649 transaction->id()); | 1684 transaction->id()); |
| 1650 size_t delete_count = 0; | 1685 size_t delete_count = 0; |
| 1651 leveldb::Status s = | 1686 leveldb::Status s = |
| 1652 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), | 1687 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), |
| 1653 object_store_id, *key_range, &delete_count); | 1688 object_store_id, *key_range, &delete_count); |
| 1654 if (!s.ok()) | 1689 if (!s.ok()) |
| 1655 return s; | 1690 return s; |
| 1656 callbacks->OnSuccess(); | 1691 callbacks->OnSuccess(); |
| 1657 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, | 1692 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, |
| 1658 *key_range); | 1693 *key_range, nullptr); |
| 1659 return s; | 1694 return s; |
| 1660 } | 1695 } |
| 1661 | 1696 |
| 1662 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, | 1697 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, |
| 1663 int64_t object_store_id, | 1698 int64_t object_store_id, |
| 1664 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1699 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1665 DCHECK(transaction); | 1700 DCHECK(transaction); |
| 1666 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); | 1701 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); |
| 1667 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1702 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
| 1668 | 1703 |
| 1669 if (!ValidateObjectStoreId(object_store_id)) | 1704 if (!ValidateObjectStoreId(object_store_id)) |
| 1670 return; | 1705 return; |
| 1671 | 1706 |
| 1672 transaction->ScheduleTask(base::Bind( | 1707 transaction->ScheduleTask(base::Bind( |
| 1673 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); | 1708 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); |
| 1674 } | 1709 } |
| 1675 | 1710 |
| 1676 leveldb::Status IndexedDBDatabase::ClearOperation( | 1711 leveldb::Status IndexedDBDatabase::ClearOperation( |
| 1677 int64_t object_store_id, | 1712 int64_t object_store_id, |
| 1678 scoped_refptr<IndexedDBCallbacks> callbacks, | 1713 scoped_refptr<IndexedDBCallbacks> callbacks, |
| 1679 IndexedDBTransaction* transaction) { | 1714 IndexedDBTransaction* transaction) { |
| 1680 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); | 1715 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); |
| 1681 leveldb::Status s = backing_store_->ClearObjectStore( | 1716 leveldb::Status s = backing_store_->ClearObjectStore( |
| 1682 transaction->BackingStoreTransaction(), id(), object_store_id); | 1717 transaction->BackingStoreTransaction(), id(), object_store_id); |
| 1683 if (!s.ok()) | 1718 if (!s.ok()) |
| 1684 return s; | 1719 return s; |
| 1685 callbacks->OnSuccess(); | 1720 callbacks->OnSuccess(); |
| 1686 | 1721 |
| 1687 FilterObservation(transaction, object_store_id, blink::WebIDBClear, | 1722 FilterObservation(transaction, object_store_id, blink::WebIDBClear, |
| 1688 IndexedDBKeyRange()); | 1723 IndexedDBKeyRange(), nullptr); |
| 1689 return s; | 1724 return s; |
| 1690 } | 1725 } |
| 1691 | 1726 |
| 1692 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation( | 1727 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation( |
| 1693 int64_t object_store_id, | 1728 int64_t object_store_id, |
| 1694 IndexedDBTransaction* transaction) { | 1729 IndexedDBTransaction* transaction) { |
| 1695 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", | 1730 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", |
| 1696 "txn.id", | 1731 "txn.id", |
| 1697 transaction->id()); | 1732 transaction->id()); |
| 1698 | 1733 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1912 if (status.IsCorruption()) { | 1947 if (status.IsCorruption()) { |
| 1913 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1948 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1914 message); | 1949 message); |
| 1915 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1950 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1916 } else { | 1951 } else { |
| 1917 factory_->HandleBackingStoreFailure(backing_store_->origin()); | 1952 factory_->HandleBackingStoreFailure(backing_store_->origin()); |
| 1918 } | 1953 } |
| 1919 } | 1954 } |
| 1920 | 1955 |
| 1921 } // namespace content | 1956 } // namespace content |
| OLD | NEW |