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

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

Issue 2601983002: [IndexedDB] Adding transaction and value support to observers (Closed)
Patch Set: rebase Created 3 years, 11 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_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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 } 793 }
794 794
795 void IndexedDBDatabase::AddPendingObserver( 795 void IndexedDBDatabase::AddPendingObserver(
796 IndexedDBTransaction* transaction, 796 IndexedDBTransaction* transaction,
797 int32_t observer_id, 797 int32_t observer_id,
798 const IndexedDBObserver::Options& options) { 798 const IndexedDBObserver::Options& options) {
799 DCHECK(transaction); 799 DCHECK(transaction);
800 transaction->AddPendingObserver(observer_id, options); 800 transaction->AddPendingObserver(observer_id, options);
801 } 801 }
802 802
803 // TODO(palakj): Augment the function with IDBValue later. Issue
804 // crbug.com/609934.
805 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, 803 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction,
806 int64_t object_store_id, 804 int64_t object_store_id,
807 blink::WebIDBOperationType type, 805 blink::WebIDBOperationType type,
808 const IndexedDBKeyRange& key_range) { 806 const IndexedDBKeyRange& key_range,
807 const IndexedDBValue* value) {
809 for (auto* connection : connections_) { 808 for (auto* connection : connections_) {
810 bool recorded = false; 809 bool recorded = false;
811 for (const auto& observer : connection->active_observers()) { 810 for (const auto& observer : connection->active_observers()) {
812 if (!observer->IsRecordingType(type) || 811 if (!observer->IsRecordingType(type) ||
813 !observer->IsRecordingObjectStore(object_store_id)) 812 !observer->IsRecordingObjectStore(object_store_id))
814 continue; 813 continue;
815 if (!recorded) { 814 if (!recorded) {
816 auto observation = ::indexed_db::mojom::Observation::New(); 815 auto observation = ::indexed_db::mojom::Observation::New();
817 observation->object_store_id = object_store_id; 816 observation->object_store_id = object_store_id;
818 observation->type = type; 817 observation->type = type;
819 if (type != blink::WebIDBClear) 818 if (type != blink::WebIDBClear)
820 observation->key_range = key_range; 819 observation->key_range = key_range;
821 transaction->AddObservation(connection->id(), std::move(observation)); 820 transaction->AddObservation(connection->id(), std::move(observation));
822 recorded = true; 821 recorded = true;
823 } 822 }
824 transaction->RecordObserverForLastObservation(connection->id(), 823 ::indexed_db::mojom::ObserverChangesPtr& changes =
825 observer->id()); 824 *transaction->GetPendingChangesForConnection(connection->id());
825
826 changes->observation_index_map[observer->id()].push_back(
827 changes->observations.size() - 1);
palmer 2017/01/18 19:56:01 Why - 1 ?
dmurph 2017/01/18 21:00:57 We want the last index.
828 if (observer->include_transaction() &&
829 !base::ContainsKey(changes->transaction_map, observer->id())) {
830 auto mojo_transaction = ::indexed_db::mojom::ObserverTransaction::New();
831 mojo_transaction->id = connection->NewObserverTransactionId();
832 mojo_transaction->scope.insert(mojo_transaction->scope.end(),
833 observer->object_store_ids().begin(),
834 observer->object_store_ids().end());
835 changes->transaction_map[observer->id()] = std::move(mojo_transaction);
836 }
837 if (value && observer->values() && !changes->observations.back()->value) {
838 IndexedDBValue copy = *value;
palmer 2017/01/18 19:56:01 Yeah, here's the copy you were talking about, righ
dmurph 2017/01/18 21:00:57 I added a bug mention here - we want to avoid Inde
839 changes->observations.back()->value =
840 IndexedDBCallbacks::ConvertValue(&copy);
841 }
826 } 842 }
827 } 843 }
828 } 844 }
829 845
830 void IndexedDBDatabase::SendObservations( 846 void IndexedDBDatabase::SendObservations(
831 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) { 847 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) {
832 for (auto* conn : connections_) { 848 for (auto* conn : connections_) {
833 auto it = changes_map.find(conn->id()); 849 auto it = changes_map.find(conn->id());
834 if (it != changes_map.end()) 850 if (it == changes_map.end())
835 conn->callbacks()->OnDatabaseChange(std::move(it->second)); 851 continue;
852
853 // Start all of the transactions.
854 ::indexed_db::mojom::ObserverChangesPtr& changes = it->second;
855 for (const auto& transaction_pair : changes->transaction_map) {
856 std::set<int64_t> scope(transaction_pair.second->scope.begin(),
857 transaction_pair.second->scope.end());
858 IndexedDBTransaction* transaction = conn->CreateTransaction(
859 transaction_pair.second->id, scope,
860 blink::WebIDBTransactionModeReadOnly,
861 new IndexedDBBackingStore::Transaction(backing_store_.get()));
862 DCHECK(transaction);
863 transaction_coordinator_.DidCreateObserverTransaction(transaction);
864 transaction_count_++;
865 transaction->GrabSnapshotThenStart();
866 }
867
868 conn->callbacks()->OnDatabaseChange(std::move(it->second));
836 } 869 }
837 } 870 }
838 871
839 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction, 872 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction,
840 int64_t object_store_id, 873 int64_t object_store_id,
841 int64_t index_id, 874 int64_t index_id,
842 std::unique_ptr<IndexedDBKeyRange> key_range, 875 std::unique_ptr<IndexedDBKeyRange> key_range,
843 bool key_only, 876 bool key_only,
844 int64_t max_count, 877 int64_t max_count,
845 scoped_refptr<IndexedDBCallbacks> callbacks) { 878 scoped_refptr<IndexedDBCallbacks> callbacks) {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1362 }
1330 { 1363 {
1331 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", 1364 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id",
1332 transaction->id()); 1365 transaction->id());
1333 params->callbacks->OnSuccess(*key); 1366 params->callbacks->OnSuccess(*key);
1334 } 1367 }
1335 FilterObservation(transaction, params->object_store_id, 1368 FilterObservation(transaction, params->object_store_id,
1336 params->put_mode == blink::WebIDBPutModeAddOnly 1369 params->put_mode == blink::WebIDBPutModeAddOnly
1337 ? blink::WebIDBAdd 1370 ? blink::WebIDBAdd
1338 : blink::WebIDBPut, 1371 : blink::WebIDBPut,
1339 IndexedDBKeyRange(*key)); 1372 IndexedDBKeyRange(*key), &params->value);
1340 return s; 1373 return s;
1341 } 1374 }
1342 1375
1343 void IndexedDBDatabase::SetIndexKeys( 1376 void IndexedDBDatabase::SetIndexKeys(
1344 IndexedDBTransaction* transaction, 1377 IndexedDBTransaction* transaction,
1345 int64_t object_store_id, 1378 int64_t object_store_id,
1346 std::unique_ptr<IndexedDBKey> primary_key, 1379 std::unique_ptr<IndexedDBKey> primary_key,
1347 const std::vector<IndexedDBIndexKeys>& index_keys) { 1380 const std::vector<IndexedDBIndexKeys>& index_keys) {
1348 DCHECK(transaction); 1381 DCHECK(transaction);
1349 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id()); 1382 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", 1676 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id",
1644 transaction->id()); 1677 transaction->id());
1645 size_t delete_count = 0; 1678 size_t delete_count = 0;
1646 leveldb::Status s = 1679 leveldb::Status s =
1647 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), 1680 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(),
1648 object_store_id, *key_range, &delete_count); 1681 object_store_id, *key_range, &delete_count);
1649 if (!s.ok()) 1682 if (!s.ok())
1650 return s; 1683 return s;
1651 callbacks->OnSuccess(); 1684 callbacks->OnSuccess();
1652 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, 1685 FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
1653 *key_range); 1686 *key_range, nullptr);
1654 return s; 1687 return s;
1655 } 1688 }
1656 1689
1657 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, 1690 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction,
1658 int64_t object_store_id, 1691 int64_t object_store_id,
1659 scoped_refptr<IndexedDBCallbacks> callbacks) { 1692 scoped_refptr<IndexedDBCallbacks> callbacks) {
1660 DCHECK(transaction); 1693 DCHECK(transaction);
1661 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); 1694 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id());
1662 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1695 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1663 1696
1664 if (!ValidateObjectStoreId(object_store_id)) 1697 if (!ValidateObjectStoreId(object_store_id))
1665 return; 1698 return;
1666 1699
1667 transaction->ScheduleTask(base::Bind( 1700 transaction->ScheduleTask(base::Bind(
1668 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); 1701 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks));
1669 } 1702 }
1670 1703
1671 leveldb::Status IndexedDBDatabase::ClearOperation( 1704 leveldb::Status IndexedDBDatabase::ClearOperation(
1672 int64_t object_store_id, 1705 int64_t object_store_id,
1673 scoped_refptr<IndexedDBCallbacks> callbacks, 1706 scoped_refptr<IndexedDBCallbacks> callbacks,
1674 IndexedDBTransaction* transaction) { 1707 IndexedDBTransaction* transaction) {
1675 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); 1708 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id());
1676 leveldb::Status s = backing_store_->ClearObjectStore( 1709 leveldb::Status s = backing_store_->ClearObjectStore(
1677 transaction->BackingStoreTransaction(), id(), object_store_id); 1710 transaction->BackingStoreTransaction(), id(), object_store_id);
1678 if (!s.ok()) 1711 if (!s.ok())
1679 return s; 1712 return s;
1680 callbacks->OnSuccess(); 1713 callbacks->OnSuccess();
1681 1714
1682 FilterObservation(transaction, object_store_id, blink::WebIDBClear, 1715 FilterObservation(transaction, object_store_id, blink::WebIDBClear,
1683 IndexedDBKeyRange()); 1716 IndexedDBKeyRange(), nullptr);
1684 return s; 1717 return s;
1685 } 1718 }
1686 1719
1687 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation( 1720 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation(
1688 int64_t object_store_id, 1721 int64_t object_store_id,
1689 IndexedDBTransaction* transaction) { 1722 IndexedDBTransaction* transaction) {
1690 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", 1723 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation",
1691 "txn.id", 1724 "txn.id",
1692 transaction->id()); 1725 transaction->id());
1693 1726
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 if (status.IsCorruption()) { 1940 if (status.IsCorruption()) {
1908 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1941 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1909 message); 1942 message);
1910 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1943 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1911 } else { 1944 } else {
1912 factory_->HandleBackingStoreFailure(backing_store_->origin()); 1945 factory_->HandleBackingStoreFailure(backing_store_->origin());
1913 } 1946 }
1914 } 1947 }
1915 1948
1916 } // namespace content 1949 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698