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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 }; | 56 }; |
57 | 57 |
58 class IndexedDBDatabase::VersionChangeOperation | 58 class IndexedDBDatabase::VersionChangeOperation |
59 : public IndexedDBTransaction::Operation { | 59 : public IndexedDBTransaction::Operation { |
60 public: | 60 public: |
61 VersionChangeOperation( | 61 VersionChangeOperation( |
62 scoped_refptr<IndexedDBDatabase> database, | 62 scoped_refptr<IndexedDBDatabase> database, |
63 int64 transaction_id, | 63 int64 transaction_id, |
64 int64 version, | 64 int64 version, |
65 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 65 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
66 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks) | 66 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
67 WebKit::WebIDBCallbacks::DataLoss data_loss) | |
67 : database_(database), | 68 : database_(database), |
68 transaction_id_(transaction_id), | 69 transaction_id_(transaction_id), |
69 version_(version), | 70 version_(version), |
70 callbacks_(callbacks), | 71 callbacks_(callbacks), |
71 database_callbacks_(database_callbacks) {} | 72 database_callbacks_(database_callbacks), |
73 data_loss_(data_loss) {} | |
72 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; | 74 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; |
73 | 75 |
74 private: | 76 private: |
75 scoped_refptr<IndexedDBDatabase> database_; | 77 scoped_refptr<IndexedDBDatabase> database_; |
76 int64 transaction_id_; | 78 int64 transaction_id_; |
77 int64 version_; | 79 int64 version_; |
78 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; | 80 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; |
79 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks_; | 81 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks_; |
82 WebKit::WebIDBCallbacks::DataLoss data_loss_; | |
80 }; | 83 }; |
81 | 84 |
82 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation { | 85 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation { |
83 public: | 86 public: |
84 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database, | 87 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database, |
85 int64 object_store_id) | 88 int64 object_store_id) |
86 : database_(database), object_store_id_(object_store_id) {} | 89 : database_(database), object_store_id_(object_store_id) {} |
87 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; | 90 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; |
88 | 91 |
89 private: | 92 private: |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1387 WebKit::WebIDBDatabaseExceptionUnknownError, | 1390 WebKit::WebIDBDatabaseExceptionUnknownError, |
1388 ASCIIToUTF16("Internal error writing data to stable storage when " | 1391 ASCIIToUTF16("Internal error writing data to stable storage when " |
1389 "updating version.")); | 1392 "updating version.")); |
1390 callbacks_->OnError(error); | 1393 callbacks_->OnError(error); |
1391 transaction->Abort(error); | 1394 transaction->Abort(error); |
1392 return; | 1395 return; |
1393 } | 1396 } |
1394 DCHECK(!database_->pending_second_half_open_); | 1397 DCHECK(!database_->pending_second_half_open_); |
1395 database_->pending_second_half_open_.reset(new PendingOpenCall( | 1398 database_->pending_second_half_open_.reset(new PendingOpenCall( |
1396 callbacks_, database_callbacks_, transaction_id_, version_)); | 1399 callbacks_, database_callbacks_, transaction_id_, version_)); |
1397 callbacks_->OnUpgradeNeeded(old_version, database_, database_->metadata()); | 1400 callbacks_->OnUpgradeNeeded( |
1401 old_version, database_, database_->metadata(), data_loss_); | |
1398 } | 1402 } |
1399 | 1403 |
1400 void IndexedDBDatabase::TransactionStarted(IndexedDBTransaction* transaction) { | 1404 void IndexedDBDatabase::TransactionStarted(IndexedDBTransaction* transaction) { |
1401 | 1405 |
1402 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { | 1406 if (transaction->mode() == indexed_db::TRANSACTION_VERSION_CHANGE) { |
1403 DCHECK(!running_version_change_transaction_); | 1407 DCHECK(!running_version_change_transaction_); |
1404 running_version_change_transaction_ = transaction; | 1408 running_version_change_transaction_ = transaction; |
1405 } | 1409 } |
1406 } | 1410 } |
1407 | 1411 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1529 return !pending_delete_calls_.empty() || | 1533 return !pending_delete_calls_.empty() || |
1530 running_version_change_transaction_ || | 1534 running_version_change_transaction_ || |
1531 pending_run_version_change_transaction_call_; | 1535 pending_run_version_change_transaction_call_; |
1532 } | 1536 } |
1533 | 1537 |
1534 void IndexedDBDatabase::OpenConnection( | 1538 void IndexedDBDatabase::OpenConnection( |
1535 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 1539 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
1536 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 1540 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
1537 int64 transaction_id, | 1541 int64 transaction_id, |
1538 int64 version) { | 1542 int64 version) { |
1543 const WebKit::WebIDBCallbacks::DataLoss kDataLoss = | |
1544 WebKit::WebIDBCallbacks::None; | |
1545 OpenConnection( | |
1546 callbacks, database_callbacks, transaction_id, version, kDataLoss); | |
1547 } | |
1548 | |
1549 void IndexedDBDatabase::OpenConnection( | |
1550 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
1551 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | |
1552 int64 transaction_id, | |
1553 int64 version, | |
1554 WebKit::WebIDBCallbacks::DataLoss data_loss) { | |
1539 DCHECK(backing_store_.get()); | 1555 DCHECK(backing_store_.get()); |
1540 | 1556 |
1541 // TODO(jsbell): Should have a priority queue so that higher version | 1557 // TODO(jsbell): Should have a priority queue so that higher version |
1542 // requests are processed first. http://crbug.com/225850 | 1558 // requests are processed first. http://crbug.com/225850 |
1543 if (IsOpenConnectionBlocked()) { | 1559 if (IsOpenConnectionBlocked()) { |
1560 // The backing store only detects data loss when it is first opened. The | |
1561 // presence of existing connections means we didn't even check for data loss | |
1562 // so there'd better not be any. | |
1563 DCHECK(!data_loss); | |
jsbell
2013/06/17 23:21:48
Should be: DCHECK_NE(WebKit::WebIDBCallbacks::None
dgrogan
2013/06/17 23:52:40
Done.
| |
1544 pending_open_calls_.push_back(new PendingOpenCall( | 1564 pending_open_calls_.push_back(new PendingOpenCall( |
1545 callbacks, database_callbacks, transaction_id, version)); | 1565 callbacks, database_callbacks, transaction_id, version)); |
1546 return; | 1566 return; |
1547 } | 1567 } |
1548 | 1568 |
1549 if (metadata_.id == kInvalidId) { | 1569 if (metadata_.id == kInvalidId) { |
1550 // The database was deleted then immediately re-opened; OpenInternal() | 1570 // The database was deleted then immediately re-opened; OpenInternal() |
1551 // recreates it in the backing store. | 1571 // recreates it in the backing store. |
1552 if (OpenInternal()) { | 1572 if (OpenInternal()) { |
1553 DCHECK_EQ(metadata_.int_version, | 1573 DCHECK_EQ(metadata_.int_version, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1590 return; | 1610 return; |
1591 } | 1611 } |
1592 // Spec says: If no version is specified and no database exists, set | 1612 // Spec says: If no version is specified and no database exists, set |
1593 // database version to 1. | 1613 // database version to 1. |
1594 version = 1; | 1614 version = 1; |
1595 } | 1615 } |
1596 | 1616 |
1597 if (version > metadata_.int_version) { | 1617 if (version > metadata_.int_version) { |
1598 database_callbacks_set_.insert(database_callbacks); | 1618 database_callbacks_set_.insert(database_callbacks); |
1599 RunVersionChangeTransaction( | 1619 RunVersionChangeTransaction( |
1600 callbacks, database_callbacks, transaction_id, version); | 1620 callbacks, database_callbacks, transaction_id, version, data_loss); |
1601 return; | 1621 return; |
1602 } | 1622 } |
1603 if (version < metadata_.int_version) { | 1623 if (version < metadata_.int_version) { |
1604 callbacks->OnError(IndexedDBDatabaseError( | 1624 callbacks->OnError(IndexedDBDatabaseError( |
1605 WebKit::WebIDBDatabaseExceptionVersionError, | 1625 WebKit::WebIDBDatabaseExceptionVersionError, |
1606 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + | 1626 ASCIIToUTF16("The requested version (") + Int64ToString16(version) + |
1607 ASCIIToUTF16(") is less than the existing version (") + | 1627 ASCIIToUTF16(") is less than the existing version (") + |
1608 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); | 1628 Int64ToString16(metadata_.int_version) + ASCIIToUTF16(")."))); |
1609 return; | 1629 return; |
1610 } | 1630 } |
1611 DCHECK_EQ(version, metadata_.int_version); | 1631 DCHECK_EQ(version, metadata_.int_version); |
1612 database_callbacks_set_.insert(database_callbacks); | 1632 database_callbacks_set_.insert(database_callbacks); |
1613 callbacks->OnSuccess(this, this->metadata()); | 1633 callbacks->OnSuccess(this, this->metadata()); |
1614 } | 1634 } |
1615 | 1635 |
1616 void IndexedDBDatabase::RunVersionChangeTransaction( | 1636 void IndexedDBDatabase::RunVersionChangeTransaction( |
1617 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 1637 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
1618 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 1638 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
1619 int64 transaction_id, | 1639 int64 transaction_id, |
1620 int64 requested_version) { | 1640 int64 requested_version, |
1641 WebKit::WebIDBCallbacks::DataLoss data_loss) { | |
1621 | 1642 |
1622 DCHECK(callbacks.get()); | 1643 DCHECK(callbacks.get()); |
1623 DCHECK(database_callbacks_set_.has(database_callbacks)); | 1644 DCHECK(database_callbacks_set_.has(database_callbacks)); |
1624 if (ConnectionCount() > 1) { | 1645 if (ConnectionCount() > 1) { |
1646 DCHECK(!data_loss); | |
jsbell
2013/06/17 23:21:48
Ditto.
dgrogan
2013/06/17 23:52:40
Done.
| |
1625 // Front end ensures the event is not fired at connections that have | 1647 // Front end ensures the event is not fired at connections that have |
1626 // close_pending set. | 1648 // close_pending set. |
1627 for (DatabaseCallbacksSet::const_iterator it = | 1649 for (DatabaseCallbacksSet::const_iterator it = |
1628 database_callbacks_set_.begin(); | 1650 database_callbacks_set_.begin(); |
1629 it != database_callbacks_set_.end(); | 1651 it != database_callbacks_set_.end(); |
1630 ++it) { | 1652 ++it) { |
1631 if (it->get() != database_callbacks.get()) | 1653 if (it->get() != database_callbacks.get()) |
1632 (*it)->OnVersionChange(metadata_.int_version, requested_version); | 1654 (*it)->OnVersionChange(metadata_.int_version, requested_version); |
1633 } | 1655 } |
1634 // TODO(jsbell): Remove the call to on_blocked and instead wait | 1656 // TODO(jsbell): Remove the call to on_blocked and instead wait |
1635 // until the frontend tells us that all the "versionchange" events | 1657 // until the frontend tells us that all the "versionchange" events |
1636 // have been delivered. http://crbug.com/100123 | 1658 // have been delivered. http://crbug.com/100123 |
1637 callbacks->OnBlocked(metadata_.int_version); | 1659 callbacks->OnBlocked(metadata_.int_version); |
1638 | 1660 |
1639 DCHECK(!pending_run_version_change_transaction_call_); | 1661 DCHECK(!pending_run_version_change_transaction_call_); |
1640 pending_run_version_change_transaction_call_.reset(new PendingOpenCall( | 1662 pending_run_version_change_transaction_call_.reset(new PendingOpenCall( |
1641 callbacks, database_callbacks, transaction_id, requested_version)); | 1663 callbacks, database_callbacks, transaction_id, requested_version)); |
1642 return; | 1664 return; |
1643 } | 1665 } |
1644 RunVersionChangeTransactionFinal( | 1666 RunVersionChangeTransactionFinal(callbacks, |
1645 callbacks, database_callbacks, transaction_id, requested_version); | 1667 database_callbacks, |
1668 transaction_id, | |
1669 requested_version, | |
1670 data_loss); | |
1646 } | 1671 } |
1647 | 1672 |
1648 void IndexedDBDatabase::RunVersionChangeTransactionFinal( | 1673 void IndexedDBDatabase::RunVersionChangeTransactionFinal( |
1649 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | 1674 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, |
1650 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | 1675 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, |
1651 int64 transaction_id, | 1676 int64 transaction_id, |
1652 int64 requested_version) { | 1677 int64 requested_version) { |
1678 const WebKit::WebIDBCallbacks::DataLoss kDataLoss = | |
1679 WebKit::WebIDBCallbacks::None; | |
1680 RunVersionChangeTransactionFinal(callbacks, | |
1681 database_callbacks, | |
1682 transaction_id, | |
1683 requested_version, | |
1684 kDataLoss); | |
1685 } | |
1686 | |
1687 void IndexedDBDatabase::RunVersionChangeTransactionFinal( | |
1688 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, | |
1689 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks, | |
1690 int64 transaction_id, | |
1691 int64 requested_version, | |
1692 WebKit::WebIDBCallbacks::DataLoss data_loss) { | |
1653 | 1693 |
1654 std::vector<int64> object_store_ids; | 1694 std::vector<int64> object_store_ids; |
1655 CreateTransaction(transaction_id, | 1695 CreateTransaction(transaction_id, |
1656 database_callbacks, | 1696 database_callbacks, |
1657 object_store_ids, | 1697 object_store_ids, |
1658 indexed_db::TRANSACTION_VERSION_CHANGE); | 1698 indexed_db::TRANSACTION_VERSION_CHANGE); |
1659 scoped_refptr<IndexedDBTransaction> transaction = | 1699 scoped_refptr<IndexedDBTransaction> transaction = |
1660 transactions_[transaction_id]; | 1700 transactions_[transaction_id]; |
1661 | 1701 |
1662 transaction->ScheduleTask( | 1702 transaction->ScheduleTask( |
1663 new VersionChangeOperation(this, | 1703 new VersionChangeOperation(this, |
1664 transaction_id, | 1704 transaction_id, |
1665 requested_version, | 1705 requested_version, |
1666 callbacks, | 1706 callbacks, |
1667 database_callbacks), | 1707 database_callbacks, |
1708 data_loss), | |
1668 new VersionChangeAbortOperation( | 1709 new VersionChangeAbortOperation( |
1669 this, metadata_.version, metadata_.int_version)); | 1710 this, metadata_.version, metadata_.int_version)); |
1670 | 1711 |
1671 DCHECK(!pending_second_half_open_); | 1712 DCHECK(!pending_second_half_open_); |
1672 } | 1713 } |
1673 | 1714 |
1674 void IndexedDBDatabase::DeleteDatabase( | 1715 void IndexedDBDatabase::DeleteDatabase( |
1675 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) { | 1716 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) { |
1676 | 1717 |
1677 if (IsDeleteDatabaseBlocked()) { | 1718 if (IsDeleteDatabaseBlocked()) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1788 | 1829 |
1789 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( | 1830 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( |
1790 IndexedDBTransaction* transaction) { | 1831 IndexedDBTransaction* transaction) { |
1791 IDB_TRACE("VersionChangeAbortOperation"); | 1832 IDB_TRACE("VersionChangeAbortOperation"); |
1792 DCHECK(!transaction); | 1833 DCHECK(!transaction); |
1793 database_->metadata_.version = previous_version_; | 1834 database_->metadata_.version = previous_version_; |
1794 database_->metadata_.int_version = previous_int_version_; | 1835 database_->metadata_.int_version = previous_int_version_; |
1795 } | 1836 } |
1796 | 1837 |
1797 } // namespace content | 1838 } // namespace content |
OLD | NEW |