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

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

Issue 2160163002: [IndexedDB] Propogating Changes to Observer : Browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expected tests updated Created 4 years, 5 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 <memory> 10 #include <memory>
(...skipping 11 matching lines...) Expand all
22 #include "base/stl_util.h" 22 #include "base/stl_util.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "content/browser/indexed_db/indexed_db_blob_info.h" 25 #include "content/browser/indexed_db/indexed_db_blob_info.h"
26 #include "content/browser/indexed_db/indexed_db_class_factory.h" 26 #include "content/browser/indexed_db/indexed_db_class_factory.h"
27 #include "content/browser/indexed_db/indexed_db_connection.h" 27 #include "content/browser/indexed_db/indexed_db_connection.h"
28 #include "content/browser/indexed_db/indexed_db_context_impl.h" 28 #include "content/browser/indexed_db/indexed_db_context_impl.h"
29 #include "content/browser/indexed_db/indexed_db_cursor.h" 29 #include "content/browser/indexed_db/indexed_db_cursor.h"
30 #include "content/browser/indexed_db/indexed_db_factory.h" 30 #include "content/browser/indexed_db/indexed_db_factory.h"
31 #include "content/browser/indexed_db/indexed_db_index_writer.h" 31 #include "content/browser/indexed_db/indexed_db_index_writer.h"
32 #include "content/browser/indexed_db/indexed_db_observation.h"
33 #include "content/browser/indexed_db/indexed_db_observer_changes.h"
32 #include "content/browser/indexed_db/indexed_db_pending_connection.h" 34 #include "content/browser/indexed_db/indexed_db_pending_connection.h"
33 #include "content/browser/indexed_db/indexed_db_return_value.h" 35 #include "content/browser/indexed_db/indexed_db_return_value.h"
34 #include "content/browser/indexed_db/indexed_db_tracing.h" 36 #include "content/browser/indexed_db/indexed_db_tracing.h"
35 #include "content/browser/indexed_db/indexed_db_transaction.h" 37 #include "content/browser/indexed_db/indexed_db_transaction.h"
36 #include "content/browser/indexed_db/indexed_db_value.h" 38 #include "content/browser/indexed_db/indexed_db_value.h"
37 #include "content/common/indexed_db/indexed_db_constants.h" 39 #include "content/common/indexed_db/indexed_db_constants.h"
38 #include "content/common/indexed_db/indexed_db_key_path.h" 40 #include "content/common/indexed_db/indexed_db_key_path.h"
39 #include "content/common/indexed_db/indexed_db_key_range.h" 41 #include "content/common/indexed_db/indexed_db_key_range.h"
40 #include "content/public/common/content_switches.h" 42 #include "content/public/common/content_switches.h"
41 #include "storage/browser/blob/blob_data_handle.h" 43 #include "storage/browser/blob/blob_data_handle.h"
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 void IndexedDBDatabase::Abort(int64_t transaction_id, 755 void IndexedDBDatabase::Abort(int64_t transaction_id,
754 const IndexedDBDatabaseError& error) { 756 const IndexedDBDatabaseError& error) {
755 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); 757 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id);
756 // If the transaction is unknown, then it has already been aborted by the 758 // If the transaction is unknown, then it has already been aborted by the
757 // backend before this call so it is safe to ignore it. 759 // backend before this call so it is safe to ignore it.
758 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 760 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
759 if (transaction) 761 if (transaction)
760 transaction->Abort(error); 762 transaction->Abort(error);
761 } 763 }
762 764
763 void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id, 765 void IndexedDBDatabase::AddPendingObserver(
764 int32_t observer_id) { 766 int64_t transaction_id,
767 int32_t observer_id,
768 const IndexedDBObserver::Options& options) {
765 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 769 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
766 if (!transaction) 770 if (!transaction)
767 return; 771 return;
768 transaction->AddPendingObserver(observer_id); 772 transaction->AddPendingObserver(observer_id, options);
769 } 773 }
770 774
771 void IndexedDBDatabase::RemovePendingObservers( 775 void IndexedDBDatabase::RemovePendingObservers(
772 IndexedDBConnection* connection, 776 IndexedDBConnection* connection,
773 const std::vector<int32_t>& pending_observer_ids) { 777 const std::vector<int32_t>& pending_observer_ids) {
774 for (const auto& it : transactions_) { 778 for (const auto& it : transactions_) {
775 // Avoid call to RemovePendingObservers for transactions on other 779 // Avoid call to RemovePendingObservers for transactions on other
776 // connections. 780 // connections.
777 if (it.second->connection() == connection) 781 if (it.second->connection() == connection)
778 it.second->RemovePendingObservers(pending_observer_ids); 782 it.second->RemovePendingObservers(pending_observer_ids);
779 } 783 }
780 } 784 }
781 785
786 // TODO(palakj): Augment the function with IDBValue later. Issue
787 // crbug.com/609934.
788 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction,
789 int64_t object_store_id,
790 blink::WebIDBOperationType type,
791 const IndexedDBKeyRange& key_range) {
792 for (const auto& connection : connections_) {
793 bool recorded = false;
794 for (const auto& observer : connection->active_observers()) {
795 if (!observer->IsRecordingType(type) ||
796 !observer->IsRecordingObjectStore(object_store_id))
797 continue;
798 if (!recorded) {
799 if (type == blink::WebIDBClear) {
800 transaction->AddObservation(connection->id(),
801 base::WrapUnique(new IndexedDBObservation(
802 object_store_id, type)));
803 } else {
804 transaction->AddObservation(connection->id(),
805 base::WrapUnique(new IndexedDBObservation(
806 object_store_id, type, key_range)));
807 }
808 recorded = true;
809 }
810 transaction->RecordObserverForLastObservation(connection->id(),
811 observer->id());
812 }
813 }
814 }
815
816 void IndexedDBDatabase::SendObservations(
817 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) {
818 for (const auto& conn : connections_) {
819 auto it = changes_map.find(conn->id());
820 if (it != changes_map.end())
821 conn->callbacks()->OnDatabaseChange(it->first, std::move(it->second));
822 }
823 }
824
782 void IndexedDBDatabase::GetAll(int64_t transaction_id, 825 void IndexedDBDatabase::GetAll(int64_t transaction_id,
783 int64_t object_store_id, 826 int64_t object_store_id,
784 int64_t index_id, 827 int64_t index_id,
785 std::unique_ptr<IndexedDBKeyRange> key_range, 828 std::unique_ptr<IndexedDBKeyRange> key_range,
786 bool key_only, 829 bool key_only,
787 int64_t max_count, 830 int64_t max_count,
788 scoped_refptr<IndexedDBCallbacks> callbacks) { 831 scoped_refptr<IndexedDBCallbacks> callbacks) {
789 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); 832 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id);
790 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 833 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
791 if (!transaction) 834 if (!transaction)
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 if (s.IsCorruption()) 1369 if (s.IsCorruption())
1327 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1370 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1328 return; 1371 return;
1329 } 1372 }
1330 } 1373 }
1331 { 1374 {
1332 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", 1375 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id",
1333 transaction->id()); 1376 transaction->id());
1334 params->callbacks->OnSuccess(*key); 1377 params->callbacks->OnSuccess(*key);
1335 } 1378 }
1379 FilterObservation(transaction, params->object_store_id,
1380 params->put_mode == blink::WebIDBPutModeAddOnly
1381 ? blink::WebIDBAdd
1382 : blink::WebIDBPut,
1383 IndexedDBKeyRange(*key));
1336 } 1384 }
1337 1385
1338 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, 1386 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id,
1339 int64_t object_store_id, 1387 int64_t object_store_id,
1340 std::unique_ptr<IndexedDBKey> primary_key, 1388 std::unique_ptr<IndexedDBKey> primary_key,
1341 const std::vector<IndexKeys>& index_keys) { 1389 const std::vector<IndexKeys>& index_keys) {
1342 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); 1390 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id);
1343 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1391 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1344 if (!transaction) 1392 if (!transaction)
1345 return; 1393 return;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 if (s.IsCorruption()) { 1717 if (s.IsCorruption()) {
1670 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1718 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1671 } 1719 }
1672 return; 1720 return;
1673 } 1721 }
1674 if (experimental_web_platform_features_enabled_) { 1722 if (experimental_web_platform_features_enabled_) {
1675 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); 1723 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count));
1676 } else { 1724 } else {
1677 callbacks->OnSuccess(); 1725 callbacks->OnSuccess();
1678 } 1726 }
1727 FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
1728 *key_range);
1679 } 1729 }
1680 1730
1681 void IndexedDBDatabase::Clear(int64_t transaction_id, 1731 void IndexedDBDatabase::Clear(int64_t transaction_id,
1682 int64_t object_store_id, 1732 int64_t object_store_id,
1683 scoped_refptr<IndexedDBCallbacks> callbacks) { 1733 scoped_refptr<IndexedDBCallbacks> callbacks) {
1684 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); 1734 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id);
1685 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 1735 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
1686 if (!transaction) 1736 if (!transaction)
1687 return; 1737 return;
1688 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); 1738 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly);
(...skipping 15 matching lines...) Expand all
1704 if (!s.ok()) { 1754 if (!s.ok()) {
1705 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1755 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1706 "Internal error clearing object store"); 1756 "Internal error clearing object store");
1707 callbacks->OnError(error); 1757 callbacks->OnError(error);
1708 if (s.IsCorruption()) { 1758 if (s.IsCorruption()) {
1709 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1759 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1710 } 1760 }
1711 return; 1761 return;
1712 } 1762 }
1713 callbacks->OnSuccess(); 1763 callbacks->OnSuccess();
1764
1765 FilterObservation(transaction, object_store_id, blink::WebIDBClear,
1766 IndexedDBKeyRange());
1714 } 1767 }
1715 1768
1716 void IndexedDBDatabase::DeleteObjectStoreOperation( 1769 void IndexedDBDatabase::DeleteObjectStoreOperation(
1717 int64_t object_store_id, 1770 int64_t object_store_id,
1718 IndexedDBTransaction* transaction) { 1771 IndexedDBTransaction* transaction) {
1719 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", 1772 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation",
1720 "txn.id", 1773 "txn.id",
1721 transaction->id()); 1774 transaction->id());
1722 1775
1723 const IndexedDBObjectStoreMetadata object_store_metadata = 1776 const IndexedDBObjectStoreMetadata object_store_metadata =
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 2005
1953 void IndexedDBDatabase::VersionChangeAbortOperation( 2006 void IndexedDBDatabase::VersionChangeAbortOperation(
1954 int64_t previous_version, 2007 int64_t previous_version,
1955 IndexedDBTransaction* transaction) { 2008 IndexedDBTransaction* transaction) {
1956 DCHECK(!transaction); 2009 DCHECK(!transaction);
1957 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 2010 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1958 metadata_.version = previous_version; 2011 metadata_.version = previous_version;
1959 } 2012 }
1960 2013
1961 } // namespace content 2014 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.h ('k') | content/browser/indexed_db/indexed_db_database_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698