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

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

Issue 17033004: Tell IDB frontend about data loss (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToT Created 7 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 | Annotate | Revision Log
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 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 }; 57 };
58 58
59 class IndexedDBDatabase::VersionChangeOperation 59 class IndexedDBDatabase::VersionChangeOperation
60 : public IndexedDBTransaction::Operation { 60 : public IndexedDBTransaction::Operation {
61 public: 61 public:
62 VersionChangeOperation( 62 VersionChangeOperation(
63 scoped_refptr<IndexedDBDatabase> database, 63 scoped_refptr<IndexedDBDatabase> database,
64 int64 transaction_id, 64 int64 transaction_id,
65 int64 version, 65 int64 version,
66 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, 66 scoped_refptr<IndexedDBCallbacksWrapper> callbacks,
67 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks) 67 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks,
68 WebKit::WebIDBCallbacks::DataLoss data_loss)
68 : database_(database), 69 : database_(database),
69 transaction_id_(transaction_id), 70 transaction_id_(transaction_id),
70 version_(version), 71 version_(version),
71 callbacks_(callbacks), 72 callbacks_(callbacks),
72 database_callbacks_(database_callbacks) {} 73 database_callbacks_(database_callbacks),
74 data_loss_(data_loss) {}
73 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 75 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
74 76
75 private: 77 private:
76 scoped_refptr<IndexedDBDatabase> database_; 78 scoped_refptr<IndexedDBDatabase> database_;
77 int64 transaction_id_; 79 int64 transaction_id_;
78 int64 version_; 80 int64 version_;
79 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_; 81 scoped_refptr<IndexedDBCallbacksWrapper> callbacks_;
80 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks_; 82 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks_;
83 WebKit::WebIDBCallbacks::DataLoss data_loss_;
81 }; 84 };
82 85
83 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation { 86 class CreateObjectStoreAbortOperation : public IndexedDBTransaction::Operation {
84 public: 87 public:
85 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database, 88 CreateObjectStoreAbortOperation(scoped_refptr<IndexedDBDatabase> database,
86 int64 object_store_id) 89 int64 object_store_id)
87 : database_(database), object_store_id_(object_store_id) {} 90 : database_(database), object_store_id_(object_store_id) {}
88 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE; 91 virtual void Perform(IndexedDBTransaction* transaction) OVERRIDE;
89 92
90 private: 93 private:
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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::DataLossNone;
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_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss);
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
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_NE(WebKit::WebIDBCallbacks::DataLossTotal, data_loss);
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 OnBlocked and instead wait 1656 // TODO(jsbell): Remove the call to OnBlocked 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::DataLossNone;
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 1830
1790 void IndexedDBDatabase::VersionChangeAbortOperation::Perform( 1831 void IndexedDBDatabase::VersionChangeAbortOperation::Perform(
1791 IndexedDBTransaction* transaction) { 1832 IndexedDBTransaction* transaction) {
1792 IDB_TRACE("VersionChangeAbortOperation"); 1833 IDB_TRACE("VersionChangeAbortOperation");
1793 DCHECK(!transaction); 1834 DCHECK(!transaction);
1794 database_->metadata_.version = previous_version_; 1835 database_->metadata_.version = previous_version_;
1795 database_->metadata_.int_version = previous_int_version_; 1836 database_->metadata_.int_version = previous_int_version_;
1796 } 1837 }
1797 1838
1798 } // namespace content 1839 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.h ('k') | content/browser/indexed_db/indexed_db_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698