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 <memory> | 10 #include <memory> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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_observer.h" | |
| 32 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 33 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 33 #include "content/browser/indexed_db/indexed_db_return_value.h" | 34 #include "content/browser/indexed_db/indexed_db_return_value.h" |
| 34 #include "content/browser/indexed_db/indexed_db_tracing.h" | 35 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 35 #include "content/browser/indexed_db/indexed_db_transaction.h" | 36 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 36 #include "content/browser/indexed_db/indexed_db_value.h" | 37 #include "content/browser/indexed_db/indexed_db_value.h" |
| 37 #include "content/common/indexed_db/indexed_db_constants.h" | 38 #include "content/common/indexed_db/indexed_db_constants.h" |
| 38 #include "content/common/indexed_db/indexed_db_key_path.h" | 39 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 39 #include "content/common/indexed_db/indexed_db_key_range.h" | 40 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 40 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
| 41 #include "storage/browser/blob/blob_data_handle.h" | 42 #include "storage/browser/blob/blob_data_handle.h" |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 void IndexedDBDatabase::Abort(int64_t transaction_id, | 535 void IndexedDBDatabase::Abort(int64_t transaction_id, |
| 535 const IndexedDBDatabaseError& error) { | 536 const IndexedDBDatabaseError& error) { |
| 536 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); | 537 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); |
| 537 // If the transaction is unknown, then it has already been aborted by the | 538 // 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. | 539 // backend before this call so it is safe to ignore it. |
| 539 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 540 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 540 if (transaction) | 541 if (transaction) |
| 541 transaction->Abort(error); | 542 transaction->Abort(error); |
| 542 } | 543 } |
| 543 | 544 |
| 545 void IndexedDBDatabase::Observe(int64_t transaction_id, int64_t observer_id) { | |
| 546 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | |
| 547 if (!transaction) | |
| 548 return; | |
| 549 transaction->AddPendingObserver( | |
| 550 base::WrapUnique(new IndexedDBObserver(observer_id))); | |
| 551 } | |
| 552 | |
| 553 void IndexedDBDatabase::RemovePendingObservers( | |
| 554 IndexedDBConnection* connection, | |
| 555 std::vector<int32_t> observersToRemove) { | |
| 556 // TODO(palakj): Better Implementation needed. | |
| 557 TransactionMap::iterator trans_iter; | |
| 558 for (trans_iter = transactions_.begin(); | |
| 559 trans_iter != transactions_.end() && !observersToRemove.empty(); | |
| 560 trans_iter++) { | |
| 561 IndexedDBTransaction* transaction = trans_iter->second; | |
| 562 if (transaction->getConnection() == connection) { | |
| 563 // Do I move this logic to transaction. | |
|
dmurph
2016/06/22 01:09:49
Sure, it might make a little more sense.
palakj1
2016/06/23 20:56:29
Done
| |
| 564 for (uint32_t k = 0; k < transaction->pending_observers_.size(); k++) { | |
| 565 std::vector<int>::iterator it = | |
| 566 std::find(observersToRemove.begin(), observersToRemove.end(), | |
|
dmurph
2016/06/22 01:09:49
why not just observersToRemove.find? Also, remove
palakj1
2016/06/23 20:56:29
Does a vector have find function?
| |
| 567 transaction->pending_observers_[k]->id()); | |
| 568 if (it != observersToRemove.end()) { | |
| 569 transaction->pending_observers_.erase( | |
| 570 transaction->pending_observers_.begin() + k); | |
| 571 observersToRemove.erase(it); | |
| 572 } | |
| 573 } | |
| 574 } | |
| 575 } | |
| 576 } | |
| 577 | |
| 544 void IndexedDBDatabase::GetAll(int64_t transaction_id, | 578 void IndexedDBDatabase::GetAll(int64_t transaction_id, |
| 545 int64_t object_store_id, | 579 int64_t object_store_id, |
| 546 int64_t index_id, | 580 int64_t index_id, |
| 547 std::unique_ptr<IndexedDBKeyRange> key_range, | 581 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 548 bool key_only, | 582 bool key_only, |
| 549 int64_t max_count, | 583 int64_t max_count, |
| 550 scoped_refptr<IndexedDBCallbacks> callbacks) { | 584 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 551 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); | 585 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |
| 552 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 586 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 553 if (!transaction) | 587 if (!transaction) |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1658 if (transactions_.find(transaction_id) != transactions_.end()) | 1692 if (transactions_.find(transaction_id) != transactions_.end()) |
| 1659 return; | 1693 return; |
| 1660 | 1694 |
| 1661 UMA_HISTOGRAM_COUNTS_1000( | 1695 UMA_HISTOGRAM_COUNTS_1000( |
| 1662 "WebCore.IndexedDB.Database.OutstandingTransactionCount", | 1696 "WebCore.IndexedDB.Database.OutstandingTransactionCount", |
| 1663 transactions_.size()); | 1697 transactions_.size()); |
| 1664 | 1698 |
| 1665 // The transaction will add itself to this database's coordinator, which | 1699 // The transaction will add itself to this database's coordinator, which |
| 1666 // manages the lifetime of the object. | 1700 // manages the lifetime of the object. |
| 1667 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( | 1701 TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction( |
| 1668 transaction_id, connection->callbacks(), | 1702 transaction_id, connection, connection->callbacks(), |
| 1669 std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode, | 1703 std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode, |
| 1670 this, new IndexedDBBackingStore::Transaction(backing_store_.get()))); | 1704 this, new IndexedDBBackingStore::Transaction(backing_store_.get()))); |
| 1671 } | 1705 } |
| 1672 | 1706 |
| 1673 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { | 1707 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { |
| 1674 transactions_[transaction->id()] = transaction; | 1708 transactions_[transaction->id()] = transaction; |
| 1675 } | 1709 } |
| 1676 | 1710 |
| 1677 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { | 1711 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
| 1678 return !pending_delete_calls_.empty() || | 1712 return !pending_delete_calls_.empty() || |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1950 | 1984 |
| 1951 void IndexedDBDatabase::VersionChangeAbortOperation( | 1985 void IndexedDBDatabase::VersionChangeAbortOperation( |
| 1952 int64_t previous_version, | 1986 int64_t previous_version, |
| 1953 IndexedDBTransaction* transaction) { | 1987 IndexedDBTransaction* transaction) { |
| 1954 DCHECK(!transaction); | 1988 DCHECK(!transaction); |
| 1955 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1989 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1956 metadata_.version = previous_version; | 1990 metadata_.version = previous_version; |
| 1957 } | 1991 } |
| 1958 | 1992 |
| 1959 } // namespace content | 1993 } // namespace content |
| OLD | NEW |