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

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: fixed bit check 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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 } 798 }
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
809 // crbug.com/609934.
810 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, 808 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction,
811 int64_t object_store_id, 809 int64_t object_store_id,
812 blink::WebIDBOperationType type, 810 blink::WebIDBOperationType type,
813 const IndexedDBKeyRange& key_range) { 811 const IndexedDBKeyRange& key_range,
812 const IndexedDBValue* value) {
814 for (auto* connection : connections_) { 813 for (auto* connection : connections_) {
815 bool recorded = false; 814 bool recorded = false;
816 for (const auto& observer : connection->active_observers()) { 815 for (const auto& observer : connection->active_observers()) {
817 if (!observer->IsRecordingType(type) || 816 if (!observer->IsRecordingType(type) ||
818 !observer->IsRecordingObjectStore(object_store_id)) 817 !observer->IsRecordingObjectStore(object_store_id))
819 continue; 818 continue;
820 if (!recorded) { 819 if (!recorded) {
821 auto observation = ::indexed_db::mojom::Observation::New(); 820 auto observation = ::indexed_db::mojom::Observation::New();
822 observation->object_store_id = object_store_id; 821 observation->object_store_id = object_store_id;
823 observation->type = type; 822 observation->type = type;
824 if (type != blink::WebIDBClear) 823 if (type != blink::WebIDBClear)
825 observation->key_range = key_range; 824 observation->key_range = key_range;
826 transaction->AddObservation(connection->id(), std::move(observation)); 825 transaction->AddObservation(connection->id(), std::move(observation));
827 recorded = true; 826 recorded = true;
828 } 827 }
829 transaction->RecordObserverForLastObservation(connection->id(), 828 ::indexed_db::mojom::ObserverChangesPtr& changes =
830 observer->id()); 829 *transaction->GetPendingChangesForConnection(connection->id());
830
831 changes->observation_index_map[observer->id()].push_back(
832 changes->observations.size() - 1);
833 if (observer->include_transaction() &&
834 !base::ContainsKey(changes->transaction_map, observer->id())) {
835 auto mojo_transaction = ::indexed_db::mojom::ObserverTransaction::New();
836 mojo_transaction->id = connection->NewObserverTransactionId();
837 mojo_transaction->scope.insert(mojo_transaction->scope.end(),
838 observer->object_store_ids().begin(),
839 observer->object_store_ids().end());
840 changes->transaction_map[observer->id()] = std::move(mojo_transaction);
841 }
842 if (value && observer->values() && !changes->observations.back()->value) {
843 IndexedDBValue copy = *value;
844 changes->observations.back()->value =
845 IndexedDBCallbacks::ConvertValue(&copy);
846 }
831 } 847 }
832 } 848 }
833 } 849 }
834 850
835 void IndexedDBDatabase::SendObservations( 851 void IndexedDBDatabase::SendObservations(
836 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) { 852 std::map<int32_t, ::indexed_db::mojom::ObserverChangesPtr> changes_map) {
837 for (auto* conn : connections_) { 853 for (auto* conn : connections_) {
838 auto it = changes_map.find(conn->id()); 854 auto it = changes_map.find(conn->id());
839 if (it != changes_map.end()) 855 if (it == changes_map.end())
840 conn->callbacks()->OnDatabaseChange(std::move(it->second)); 856 continue;
857
858 // Start all of the transactions.
859 ::indexed_db::mojom::ObserverChangesPtr& changes = it->second;
860 for (const auto& transaction_pair : changes->transaction_map) {
861 std::set<int64_t> scope(transaction_pair.second->scope.begin(),
862 transaction_pair.second->scope.end());
863 IndexedDBTransaction* transaction = conn->CreateTransaction(
864 transaction_pair.second->id, scope,
865 blink::WebIDBTransactionModeReadOnly,
866 new IndexedDBBackingStore::Transaction(backing_store_.get()));
867 DCHECK(transaction);
868 transaction_coordinator_.DidCreateObserverTransaction(transaction);
869 transaction_count_++;
870 transaction->GrabSnapshotThenStart();
871 }
872
873 conn->callbacks()->OnDatabaseChange(std::move(it->second));
841 } 874 }
842 } 875 }
843 876
844 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction, 877 void IndexedDBDatabase::GetAll(IndexedDBTransaction* transaction,
845 int64_t object_store_id, 878 int64_t object_store_id,
846 int64_t index_id, 879 int64_t index_id,
847 std::unique_ptr<IndexedDBKeyRange> key_range, 880 std::unique_ptr<IndexedDBKeyRange> key_range,
848 bool key_only, 881 bool key_only,
849 int64_t max_count, 882 int64_t max_count,
850 scoped_refptr<IndexedDBCallbacks> callbacks) { 883 scoped_refptr<IndexedDBCallbacks> callbacks) {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 } 1367 }
1335 { 1368 {
1336 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", 1369 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id",
1337 transaction->id()); 1370 transaction->id());
1338 params->callbacks->OnSuccess(*key); 1371 params->callbacks->OnSuccess(*key);
1339 } 1372 }
1340 FilterObservation(transaction, params->object_store_id, 1373 FilterObservation(transaction, params->object_store_id,
1341 params->put_mode == blink::WebIDBPutModeAddOnly 1374 params->put_mode == blink::WebIDBPutModeAddOnly
1342 ? blink::WebIDBAdd 1375 ? blink::WebIDBAdd
1343 : blink::WebIDBPut, 1376 : blink::WebIDBPut,
1344 IndexedDBKeyRange(*key)); 1377 IndexedDBKeyRange(*key), &params->value);
1345 return s; 1378 return s;
1346 } 1379 }
1347 1380
1348 void IndexedDBDatabase::SetIndexKeys( 1381 void IndexedDBDatabase::SetIndexKeys(
1349 IndexedDBTransaction* transaction, 1382 IndexedDBTransaction* transaction,
1350 int64_t object_store_id, 1383 int64_t object_store_id,
1351 std::unique_ptr<IndexedDBKey> primary_key, 1384 std::unique_ptr<IndexedDBKey> primary_key,
1352 const std::vector<IndexedDBIndexKeys>& index_keys) { 1385 const std::vector<IndexedDBIndexKeys>& index_keys) {
1353 DCHECK(transaction); 1386 DCHECK(transaction);
1354 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id()); 1387 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction->id());
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", 1681 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id",
1649 transaction->id()); 1682 transaction->id());
1650 size_t delete_count = 0; 1683 size_t delete_count = 0;
1651 leveldb::Status s = 1684 leveldb::Status s =
1652 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), 1685 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(),
1653 object_store_id, *key_range, &delete_count); 1686 object_store_id, *key_range, &delete_count);
1654 if (!s.ok()) 1687 if (!s.ok())
1655 return s; 1688 return s;
1656 callbacks->OnSuccess(); 1689 callbacks->OnSuccess();
1657 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, 1690 FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
1658 *key_range); 1691 *key_range, nullptr);
1659 return s; 1692 return s;
1660 } 1693 }
1661 1694
1662 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction, 1695 void IndexedDBDatabase::Clear(IndexedDBTransaction* transaction,
1663 int64_t object_store_id, 1696 int64_t object_store_id,
1664 scoped_refptr<IndexedDBCallbacks> callbacks) { 1697 scoped_refptr<IndexedDBCallbacks> callbacks) {
1665 DCHECK(transaction); 1698 DCHECK(transaction);
1666 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id()); 1699 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction->id());
1667 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1700 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
1668 1701
1669 if (!ValidateObjectStoreId(object_store_id)) 1702 if (!ValidateObjectStoreId(object_store_id))
1670 return; 1703 return;
1671 1704
1672 transaction->ScheduleTask(base::Bind( 1705 transaction->ScheduleTask(base::Bind(
1673 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks)); 1706 &IndexedDBDatabase::ClearOperation, this, object_store_id, callbacks));
1674 } 1707 }
1675 1708
1676 leveldb::Status IndexedDBDatabase::ClearOperation( 1709 leveldb::Status IndexedDBDatabase::ClearOperation(
1677 int64_t object_store_id, 1710 int64_t object_store_id,
1678 scoped_refptr<IndexedDBCallbacks> callbacks, 1711 scoped_refptr<IndexedDBCallbacks> callbacks,
1679 IndexedDBTransaction* transaction) { 1712 IndexedDBTransaction* transaction) {
1680 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id()); 1713 IDB_TRACE1("IndexedDBDatabase::ClearOperation", "txn.id", transaction->id());
1681 leveldb::Status s = backing_store_->ClearObjectStore( 1714 leveldb::Status s = backing_store_->ClearObjectStore(
1682 transaction->BackingStoreTransaction(), id(), object_store_id); 1715 transaction->BackingStoreTransaction(), id(), object_store_id);
1683 if (!s.ok()) 1716 if (!s.ok())
1684 return s; 1717 return s;
1685 callbacks->OnSuccess(); 1718 callbacks->OnSuccess();
1686 1719
1687 FilterObservation(transaction, object_store_id, blink::WebIDBClear, 1720 FilterObservation(transaction, object_store_id, blink::WebIDBClear,
1688 IndexedDBKeyRange()); 1721 IndexedDBKeyRange(), nullptr);
1689 return s; 1722 return s;
1690 } 1723 }
1691 1724
1692 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation( 1725 leveldb::Status IndexedDBDatabase::DeleteObjectStoreOperation(
1693 int64_t object_store_id, 1726 int64_t object_store_id,
1694 IndexedDBTransaction* transaction) { 1727 IndexedDBTransaction* transaction) {
1695 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", 1728 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation",
1696 "txn.id", 1729 "txn.id",
1697 transaction->id()); 1730 transaction->id());
1698 1731
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 if (status.IsCorruption()) { 1945 if (status.IsCorruption()) {
1913 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1946 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1914 message); 1947 message);
1915 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1948 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1916 } else { 1949 } else {
1917 factory_->HandleBackingStoreFailure(backing_store_->origin()); 1950 factory_->HandleBackingStoreFailure(backing_store_->origin());
1918 } 1951 }
1919 } 1952 }
1920 1953
1921 } // namespace content 1954 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698