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

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

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Post dmurph review 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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 void IndexedDBDatabase::Abort(int64_t transaction_id, 534 void IndexedDBDatabase::Abort(int64_t transaction_id,
535 const IndexedDBDatabaseError& error) { 535 const IndexedDBDatabaseError& error) {
536 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); 536 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id);
537 // If the transaction is unknown, then it has already been aborted by the 537 // If the transaction is unknown, then it has already been aborted by the
538 // backend before this call so it is safe to ignore it. 538 // backend before this call so it is safe to ignore it.
539 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 539 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
540 if (transaction) 540 if (transaction)
541 transaction->Abort(error); 541 transaction->Abort(error);
542 } 542 }
543 543
544 void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id,
545 int64_t observer_id) {
546 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
547 if (!transaction)
548 return;
549 transaction->AddPendingObserver(observer_id);
550 }
551
552 void IndexedDBDatabase::RemovePendingObservers(
553 IndexedDBConnection* connection,
554 const std::vector<int32_t>& pending_observer_ids) {
555 TransactionMap::iterator it;
556 for (it = transactions_.begin(); it != transactions_.end(); it++) {
557 // Avoid call to RemovePendingObservers for transactions on other
558 // connections.
559 if (it->second->connection() == connection)
560 it->second->RemovePendingObservers(pending_observer_ids);
561 }
562 }
563
544 void IndexedDBDatabase::GetAll(int64_t transaction_id, 564 void IndexedDBDatabase::GetAll(int64_t transaction_id,
545 int64_t object_store_id, 565 int64_t object_store_id,
546 int64_t index_id, 566 int64_t index_id,
547 std::unique_ptr<IndexedDBKeyRange> key_range, 567 std::unique_ptr<IndexedDBKeyRange> key_range,
548 bool key_only, 568 bool key_only,
549 int64_t max_count, 569 int64_t max_count,
550 scoped_refptr<IndexedDBCallbacks> callbacks) { 570 scoped_refptr<IndexedDBCallbacks> callbacks) {
551 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); 571 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id);
552 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 572 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
553 if (!transaction) 573 if (!transaction)
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 if (transactions_.find(transaction_id) != transactions_.end()) 1678 if (transactions_.find(transaction_id) != transactions_.end())
1659 return; 1679 return;
1660 1680
1661 UMA_HISTOGRAM_COUNTS_1000( 1681 UMA_HISTOGRAM_COUNTS_1000(
1662 "WebCore.IndexedDB.Database.OutstandingTransactionCount", 1682 "WebCore.IndexedDB.Database.OutstandingTransactionCount",
1663 transactions_.size()); 1683 transactions_.size());
1664 1684
1665 // The transaction will add itself to this database's coordinator, which 1685 // The transaction will add itself to this database's coordinator, which
1666 // manages the lifetime of the object. 1686 // manages the lifetime of the object.
1667 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( 1687 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction(
1668 transaction_id, connection->callbacks(), 1688 transaction_id, connection->GetWeakPtr(), connection->callbacks(),
cmumford 2016/06/28 20:26:22 Nit: If CreateIndexedDBTransaction has the connect
palakj1 2016/06/29 23:02:40 I can eliminate both callbacks and database.
1669 std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode, 1689 std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode,
1670 this, new IndexedDBBackingStore::Transaction(backing_store_.get()))); 1690 this, new IndexedDBBackingStore::Transaction(backing_store_.get())));
1671 } 1691 }
1672 1692
1673 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { 1693 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) {
1674 transactions_[transaction->id()] = transaction; 1694 transactions_[transaction->id()] = transaction;
1675 } 1695 }
1676 1696
1677 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { 1697 bool IndexedDBDatabase::IsOpenConnectionBlocked() const {
1678 return !pending_delete_calls_.empty() || 1698 return !pending_delete_calls_.empty() ||
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 1918
1899 connections_.erase(connection); 1919 connections_.erase(connection);
1900 1920
1901 // Abort outstanding transactions from the closing connection. This 1921 // Abort outstanding transactions from the closing connection. This
1902 // can not happen if the close is requested by the connection itself 1922 // can not happen if the close is requested by the connection itself
1903 // as the front-end defers the close until all transactions are 1923 // as the front-end defers the close until all transactions are
1904 // complete, but can occur on process termination or forced close. 1924 // complete, but can occur on process termination or forced close.
1905 { 1925 {
1906 TransactionMap transactions(transactions_); 1926 TransactionMap transactions(transactions_);
1907 for (const auto& it : transactions) { 1927 for (const auto& it : transactions) {
1908 if (it.second->connection() == connection->callbacks()) 1928 if (it.second->callbacks() == connection->callbacks())
1909 it.second->Abort( 1929 it.second->Abort(
1910 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, 1930 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
1911 "Connection is closing.")); 1931 "Connection is closing."));
1912 } 1932 }
1913 } 1933 }
1914 1934
1915 if (pending_second_half_open_ && 1935 if (pending_second_half_open_ &&
1916 pending_second_half_open_->connection() == connection) { 1936 pending_second_half_open_->connection() == connection) {
1917 pending_second_half_open_->callbacks()->OnError( 1937 pending_second_half_open_->callbacks()->OnError(
1918 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError, 1938 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionAbortError,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 1970
1951 void IndexedDBDatabase::VersionChangeAbortOperation( 1971 void IndexedDBDatabase::VersionChangeAbortOperation(
1952 int64_t previous_version, 1972 int64_t previous_version,
1953 IndexedDBTransaction* transaction) { 1973 IndexedDBTransaction* transaction) {
1954 DCHECK(!transaction); 1974 DCHECK(!transaction);
1955 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1975 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1956 metadata_.version = previous_version; 1976 metadata_.version = previous_version;
1957 } 1977 }
1958 1978
1959 } // namespace content 1979 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698