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 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 } | 1373 } |
1373 pending_second_half_open_.reset(); | 1374 pending_second_half_open_.reset(); |
1374 } | 1375 } |
1375 | 1376 |
1376 // Connection queue is now unblocked. | 1377 // Connection queue is now unblocked. |
1377 ProcessPendingCalls(); | 1378 ProcessPendingCalls(); |
1378 } | 1379 } |
1379 } | 1380 } |
1380 | 1381 |
1381 void IndexedDBDatabase::TransactionCommitFailed(const leveldb::Status& status) { | 1382 void IndexedDBDatabase::TransactionCommitFailed(const leveldb::Status& status) { |
1382 // Factory may be null in unit tests. | |
1383 if (!factory_) | |
1384 return; | |
1385 if (status.IsCorruption()) { | 1383 if (status.IsCorruption()) { |
1386 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1384 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1387 "Error committing transaction"); | 1385 "Error committing transaction"); |
1388 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), error); | 1386 factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), error); |
1389 } else { | 1387 } else { |
1390 factory_->HandleBackingStoreFailure(backing_store_->origin_url()); | 1388 factory_->HandleBackingStoreFailure(backing_store_->origin_url()); |
1391 } | 1389 } |
1392 } | 1390 } |
1393 | 1391 |
1394 size_t IndexedDBDatabase::ConnectionCount() const { | 1392 size_t IndexedDBDatabase::ConnectionCount() const { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 factory_->HandleBackingStoreCorruption(origin_url, error); | 1674 factory_->HandleBackingStoreCorruption(origin_url, error); |
1677 } | 1675 } |
1678 return; | 1676 return; |
1679 } | 1677 } |
1680 int64 old_version = metadata_.int_version; | 1678 int64 old_version = metadata_.int_version; |
1681 metadata_.version = kNoStringVersion; | 1679 metadata_.version = kNoStringVersion; |
1682 metadata_.id = kInvalidId; | 1680 metadata_.id = kInvalidId; |
1683 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; | 1681 metadata_.int_version = IndexedDBDatabaseMetadata::NO_INT_VERSION; |
1684 metadata_.object_stores.clear(); | 1682 metadata_.object_stores.clear(); |
1685 callbacks->OnSuccess(old_version); | 1683 callbacks->OnSuccess(old_version); |
1686 if (factory_) | 1684 factory_->DatabaseDeleted(identifier_); |
1687 factory_->DatabaseDeleted(identifier_); | |
1688 } | 1685 } |
1689 | 1686 |
1690 void IndexedDBDatabase::ForceClose() { | 1687 void IndexedDBDatabase::ForceClose() { |
1691 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. | 1688 // IndexedDBConnection::ForceClose() may delete this database, so hold ref. |
1692 scoped_refptr<IndexedDBDatabase> protect(this); | 1689 scoped_refptr<IndexedDBDatabase> protect(this); |
1693 ConnectionSet::const_iterator it = connections_.begin(); | 1690 ConnectionSet::const_iterator it = connections_.begin(); |
1694 while (it != connections_.end()) { | 1691 while (it != connections_.end()) { |
1695 IndexedDBConnection* connection = *it++; | 1692 IndexedDBConnection* connection = *it++; |
1696 connection->ForceClose(); | 1693 connection->ForceClose(); |
1697 } | 1694 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 ProcessPendingCalls(); | 1743 ProcessPendingCalls(); |
1747 | 1744 |
1748 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. | 1745 // TODO(jsbell): Add a test for the pending_open_calls_ cases below. |
1749 if (!ConnectionCount() && !pending_open_calls_.size() && | 1746 if (!ConnectionCount() && !pending_open_calls_.size() && |
1750 !pending_delete_calls_.size()) { | 1747 !pending_delete_calls_.size()) { |
1751 DCHECK(transactions_.empty()); | 1748 DCHECK(transactions_.empty()); |
1752 | 1749 |
1753 const GURL origin_url = backing_store_->origin_url(); | 1750 const GURL origin_url = backing_store_->origin_url(); |
1754 backing_store_ = NULL; | 1751 backing_store_ = NULL; |
1755 | 1752 |
1756 // factory_ should only be null in unit tests. | 1753 factory_->ReleaseDatabase(identifier_, forced); |
1757 // TODO(jsbell): DCHECK(factory_ || !in_unit_tests) - somehow. | |
1758 if (factory_) { | |
1759 factory_->ReleaseDatabase(identifier_, forced); | |
1760 factory_ = NULL; | |
1761 } | |
1762 } | 1754 } |
1763 } | 1755 } |
1764 | 1756 |
1765 void IndexedDBDatabase::CreateObjectStoreAbortOperation( | 1757 void IndexedDBDatabase::CreateObjectStoreAbortOperation( |
1766 int64 object_store_id, | 1758 int64 object_store_id, |
1767 IndexedDBTransaction* transaction) { | 1759 IndexedDBTransaction* transaction) { |
1768 DCHECK(!transaction); | 1760 DCHECK(!transaction); |
1769 IDB_TRACE1("IndexedDBDatabase::CreateObjectStoreAbortOperation", | 1761 IDB_TRACE1("IndexedDBDatabase::CreateObjectStoreAbortOperation", |
1770 "txn.id", | 1762 "txn.id", |
1771 transaction->id()); | 1763 transaction->id()); |
(...skipping 17 matching lines...) Expand all Loading... |
1789 IndexedDBTransaction* transaction) { | 1781 IndexedDBTransaction* transaction) { |
1790 DCHECK(!transaction); | 1782 DCHECK(!transaction); |
1791 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", | 1783 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", |
1792 "txn.id", | 1784 "txn.id", |
1793 transaction->id()); | 1785 transaction->id()); |
1794 metadata_.version = previous_version; | 1786 metadata_.version = previous_version; |
1795 metadata_.int_version = previous_int_version; | 1787 metadata_.int_version = previous_int_version; |
1796 } | 1788 } |
1797 | 1789 |
1798 } // namespace content | 1790 } // namespace content |
OLD | NEW |