| 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 <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 IndexedDBFactory* factory, | 116 IndexedDBFactory* factory, |
| 117 const Identifier& unique_identifier) | 117 const Identifier& unique_identifier) |
| 118 : backing_store_(backing_store), | 118 : backing_store_(backing_store), |
| 119 metadata_(name, | 119 metadata_(name, |
| 120 kInvalidId, | 120 kInvalidId, |
| 121 kNoStringVersion, | 121 kNoStringVersion, |
| 122 IndexedDBDatabaseMetadata::NO_INT_VERSION, | 122 IndexedDBDatabaseMetadata::NO_INT_VERSION, |
| 123 kInvalidId), | 123 kInvalidId), |
| 124 identifier_(unique_identifier), | 124 identifier_(unique_identifier), |
| 125 factory_(factory) { | 125 factory_(factory) { |
| 126 DCHECK(factory != NULL); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void IndexedDBDatabase::AddObjectStore( | 129 void IndexedDBDatabase::AddObjectStore( |
| 129 const IndexedDBObjectStoreMetadata& object_store, | 130 const IndexedDBObjectStoreMetadata& object_store, |
| 130 int64 new_max_object_store_id) { | 131 int64 new_max_object_store_id) { |
| 131 DCHECK(metadata_.object_stores.find(object_store.id) == | 132 DCHECK(metadata_.object_stores.find(object_store.id) == |
| 132 metadata_.object_stores.end()); | 133 metadata_.object_stores.end()); |
| 133 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { | 134 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { |
| 134 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); | 135 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); |
| 135 metadata_.max_object_store_id = new_max_object_store_id; | 136 metadata_.max_object_store_id = new_max_object_store_id; |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 } | 1354 } |
| 1354 pending_second_half_open_.reset(); | 1355 pending_second_half_open_.reset(); |
| 1355 } | 1356 } |
| 1356 | 1357 |
| 1357 // Connection queue is now unblocked. | 1358 // Connection queue is now unblocked. |
| 1358 ProcessPendingCalls(); | 1359 ProcessPendingCalls(); |
| 1359 } | 1360 } |
| 1360 } | 1361 } |
| 1361 | 1362 |
| 1362 void IndexedDBDatabase::TransactionCommitFailed() { | 1363 void IndexedDBDatabase::TransactionCommitFailed() { |
| 1363 // Factory may be null in unit tests. | |
| 1364 if (!factory_) | |
| 1365 return; | |
| 1366 factory_->HandleBackingStoreFailure(backing_store_->origin_url()); | 1364 factory_->HandleBackingStoreFailure(backing_store_->origin_url()); |
| 1367 } | 1365 } |
| 1368 | 1366 |
| 1369 size_t IndexedDBDatabase::ConnectionCount() const { | 1367 size_t IndexedDBDatabase::ConnectionCount() const { |
| 1370 // This does not include pending open calls, as those should not block version | 1368 // This does not include pending open calls, as those should not block version |
| 1371 // changes and deletes. | 1369 // changes and deletes. |
| 1372 return connections_.size(); | 1370 return connections_.size(); |
| 1373 } | 1371 } |
| 1374 | 1372 |
| 1375 size_t IndexedDBDatabase::PendingOpenCount() const { | 1373 size_t IndexedDBDatabase::PendingOpenCount() const { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1649 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 1647 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
| 1650 "Internal error deleting database.")); | 1648 "Internal error deleting database.")); |
| 1651 return; | 1649 return; |
| 1652 } | 1650 } |
| 1653 int64 old_version = metadata_.int_version; | 1651 int64 old_version = metadata_.int_version; |
| 1654 metadata_.version = kNoStringVersion; | 1652 metadata_.version = kNoStringVersion; |
| 1655 metadata_.id = kInvalidId; | 1653 metadata_.id = kInvalidId; |
| 1656 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; | 1654 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; |
| 1657 metadata_.object_stores.clear(); | 1655 metadata_.object_stores.clear(); |
| 1658 callbacks->OnSuccess(old_version); | 1656 callbacks->OnSuccess(old_version); |
| 1659 if (factory_) | 1657 factory_->DatabaseDeleted(identifier_); |
| 1660 factory_->DatabaseDeleted(identifier_); | |
| 1661 } | 1658 } |
| 1662 | 1659 |
| 1663 void IndexedDBDatabase::ForceClose() { | 1660 void IndexedDBDatabase::ForceClose() { |
| 1664 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. | 1661 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. |
| 1665 scoped_refptr<IndexedDBDatabase> protect(this); | 1662 scoped_refptr<IndexedDBDatabase> protect(this); |
| 1666 ConnectionSet::const_iterator it = connections_.begin(); | 1663 ConnectionSet::const_iterator it = connections_.begin(); |
| 1667 while (it != connections_.end()) { | 1664 while (it != connections_.end()) { |
| 1668 IndexedDBConnection* connection = *it++; | 1665 IndexedDBConnection* connection = *it++; |
| 1669 connection->ForceClose(); | 1666 connection->ForceClose(); |
| 1670 } | 1667 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 ProcessPendingCalls(); | 1703 ProcessPendingCalls(); |
| 1707 | 1704 |
| 1708 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. | 1705 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. |
| 1709 if (!ConnectionCount() && !pending_open_calls_.size() && | 1706 if (!ConnectionCount() && !pending_open_calls_.size() && |
| 1710 !pending_delete_calls_.size()) { | 1707 !pending_delete_calls_.size()) { |
| 1711 DCHECK(transactions_.empty()); | 1708 DCHECK(transactions_.empty()); |
| 1712 | 1709 |
| 1713 const GURL origin_url = backing_store_->origin_url(); | 1710 const GURL origin_url = backing_store_->origin_url(); |
| 1714 backing_store_ = NULL; | 1711 backing_store_ = NULL; |
| 1715 | 1712 |
| 1716 // factory_ should only be null in unit tests. | 1713 factory_->ReleaseDatabase(identifier_, forced); |
| 1717 // TODO(jsbell): DCHECK(factory_ || !in_unit_tests) - somehow. | |
| 1718 if (factory_) { | |
| 1719 factory_->ReleaseDatabase(identifier_, forced); | |
| 1720 factory_ = NULL; | |
| 1721 } | |
| 1722 } | 1714 } |
| 1723 } | 1715 } |
| 1724 | 1716 |
| 1725 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 1717 void IndexedDBDatabase::CreateObjectStoreAbortOperation( |
| 1726 int64 object_store_id, | 1718 int64 object_store_id, |
| 1727 IndexedDBTransaction* transaction) { | 1719 IndexedDBTransaction* transaction) { |
| 1728 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); | 1720 IDB_TRACE("IndexedDBDatabase::CreateObjectStoreAbortOperation"); |
| 1729 DCHECK(!transaction); | 1721 DCHECK(!transaction); |
| 1730 RemoveObjectStore(object_store_id); | 1722 RemoveObjectStore(object_store_id); |
| 1731 } | 1723 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1743 const base::string16& previous_version, | 1735 const base::string16& previous_version, |
| 1744 int64 previous_int_version, | 1736 int64 previous_int_version, |
| 1745 IndexedDBTransaction* transaction) { | 1737 IndexedDBTransaction* transaction) { |
| 1746 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1738 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1747 DCHECK(!transaction); | 1739 DCHECK(!transaction); |
| 1748 metadata_.version = previous_version; | 1740 metadata_.version = previous_version; |
| 1749 metadata_.int_version = previous_int_version; | 1741 metadata_.int_version = previous_int_version; |
| 1750 } | 1742 } |
| 1751 | 1743 |
| 1752 } // namespace content | 1744 } // namespace content |
| OLD | NEW |