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 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 } | 933 } |
934 | 934 |
935 ScopedVector<IndexWriter> index_writers; | 935 ScopedVector<IndexWriter> index_writers; |
936 base::string16 error_message; | 936 base::string16 error_message; |
937 bool obeys_constraints = false; | 937 bool obeys_constraints = false; |
938 DCHECK(metadata_.object_stores.find(object_store_id) != | 938 DCHECK(metadata_.object_stores.find(object_store_id) != |
939 metadata_.object_stores.end()); | 939 metadata_.object_stores.end()); |
940 const IndexedDBObjectStoreMetadata& object_store_metadata = | 940 const IndexedDBObjectStoreMetadata& object_store_metadata = |
941 metadata_.object_stores[object_store_id]; | 941 metadata_.object_stores[object_store_id]; |
942 bool backing_store_success = MakeIndexWriters(transaction, | 942 bool backing_store_success = MakeIndexWriters(transaction, |
943 backing_store_, | 943 backing_store_.get(), |
944 id(), | 944 id(), |
945 object_store_metadata, | 945 object_store_metadata, |
946 *primary_key, | 946 *primary_key, |
947 false, | 947 false, |
948 index_keys, | 948 index_keys, |
949 &index_writers, | 949 &index_writers, |
950 &error_message, | 950 &error_message, |
951 &obeys_constraints); | 951 &obeys_constraints); |
952 if (!backing_store_success) { | 952 if (!backing_store_success) { |
953 transaction->Abort(IndexedDBDatabaseError( | 953 transaction->Abort(IndexedDBDatabaseError( |
954 blink::WebIDBDatabaseExceptionUnknownError, | 954 blink::WebIDBDatabaseExceptionUnknownError, |
955 "Internal error: backing store error updating index keys.")); | 955 "Internal error: backing store error updating index keys.")); |
956 return; | 956 return; |
957 } | 957 } |
958 if (!obeys_constraints) { | 958 if (!obeys_constraints) { |
959 transaction->Abort(IndexedDBDatabaseError( | 959 transaction->Abort(IndexedDBDatabaseError( |
960 blink::WebIDBDatabaseExceptionConstraintError, error_message)); | 960 blink::WebIDBDatabaseExceptionConstraintError, error_message)); |
961 return; | 961 return; |
962 } | 962 } |
963 | 963 |
964 for (size_t i = 0; i < index_writers.size(); ++i) { | 964 for (size_t i = 0; i < index_writers.size(); ++i) { |
965 IndexWriter* index_writer = index_writers[i]; | 965 IndexWriter* index_writer = index_writers[i]; |
966 index_writer->WriteIndexKeys(record_identifier, | 966 index_writer->WriteIndexKeys(record_identifier, |
967 backing_store_, | 967 backing_store_.get(), |
968 transaction->BackingStoreTransaction(), | 968 transaction->BackingStoreTransaction(), |
969 id(), | 969 id(), |
970 object_store_id); | 970 object_store_id); |
971 } | 971 } |
972 } | 972 } |
973 | 973 |
974 void IndexedDBDatabase::SetIndexesReady(int64 transaction_id, | 974 void IndexedDBDatabase::SetIndexesReady(int64 transaction_id, |
975 int64, | 975 int64, |
976 const std::vector<int64>& index_ids) { | 976 const std::vector<int64>& index_ids) { |
977 IDB_TRACE1("IndexedDBDatabase::SetIndexesReady", "txn.id", transaction_id); | 977 IDB_TRACE1("IndexedDBDatabase::SetIndexesReady", "txn.id", transaction_id); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 return; | 1467 return; |
1468 | 1468 |
1469 // The transaction will add itself to this database's coordinator, which | 1469 // The transaction will add itself to this database's coordinator, which |
1470 // manages the lifetime of the object. | 1470 // manages the lifetime of the object. |
1471 TransactionCreated(new IndexedDBTransaction( | 1471 TransactionCreated(new IndexedDBTransaction( |
1472 transaction_id, | 1472 transaction_id, |
1473 connection->callbacks(), | 1473 connection->callbacks(), |
1474 std::set<int64>(object_store_ids.begin(), object_store_ids.end()), | 1474 std::set<int64>(object_store_ids.begin(), object_store_ids.end()), |
1475 mode, | 1475 mode, |
1476 this, | 1476 this, |
1477 new IndexedDBBackingStore::Transaction(backing_store_))); | 1477 new IndexedDBBackingStore::Transaction(backing_store_.get()))); |
1478 } | 1478 } |
1479 | 1479 |
1480 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { | 1480 void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { |
1481 transactions_[transaction->id()] = transaction; | 1481 transactions_[transaction->id()] = transaction; |
1482 } | 1482 } |
1483 | 1483 |
1484 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { | 1484 bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
1485 return !pending_delete_calls_.empty() || | 1485 return !pending_delete_calls_.empty() || |
1486 transaction_coordinator_.IsRunningVersionChangeTransaction() || | 1486 transaction_coordinator_.IsRunningVersionChangeTransaction() || |
1487 pending_run_version_change_transaction_call_; | 1487 pending_run_version_change_transaction_call_; |
1488 } | 1488 } |
1489 | 1489 |
1490 void IndexedDBDatabase::OpenConnection( | 1490 void IndexedDBDatabase::OpenConnection( |
1491 const IndexedDBPendingConnection& connection) { | 1491 const IndexedDBPendingConnection& connection) { |
1492 DCHECK(backing_store_); | 1492 DCHECK(backing_store_.get()); |
1493 | 1493 |
1494 // TODO(jsbell): Should have a priority queue so that higher version | 1494 // TODO(jsbell): Should have a priority queue so that higher version |
1495 // requests are processed first. http://crbug.com/225850 | 1495 // requests are processed first. http://crbug.com/225850 |
1496 if (IsOpenConnectionBlocked()) { | 1496 if (IsOpenConnectionBlocked()) { |
1497 // The backing store only detects data loss when it is first opened. The | 1497 // The backing store only detects data loss when it is first opened. The |
1498 // presence of existing connections means we didn't even check for data loss | 1498 // presence of existing connections means we didn't even check for data loss |
1499 // so there'd better not be any. | 1499 // so there'd better not be any. |
1500 DCHECK_NE(blink::WebIDBDataLossTotal, connection.callbacks->data_loss()); | 1500 DCHECK_NE(blink::WebIDBDataLossTotal, connection.callbacks->data_loss()); |
1501 pending_open_calls_.push_back(connection); | 1501 pending_open_calls_.push_back(connection); |
1502 return; | 1502 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 CreateConnection(connection.database_callbacks, | 1579 CreateConnection(connection.database_callbacks, |
1580 connection.child_process_id), | 1580 connection.child_process_id), |
1581 this->metadata()); | 1581 this->metadata()); |
1582 } | 1582 } |
1583 | 1583 |
1584 void IndexedDBDatabase::RunVersionChangeTransaction( | 1584 void IndexedDBDatabase::RunVersionChangeTransaction( |
1585 scoped_refptr<IndexedDBCallbacks> callbacks, | 1585 scoped_refptr<IndexedDBCallbacks> callbacks, |
1586 scoped_ptr<IndexedDBConnection> connection, | 1586 scoped_ptr<IndexedDBConnection> connection, |
1587 int64 transaction_id, | 1587 int64 transaction_id, |
1588 int64 requested_version) { | 1588 int64 requested_version) { |
1589 | 1589 DCHECK(callbacks.get()); |
1590 DCHECK(callbacks); | |
1591 DCHECK(connections_.count(connection.get())); | 1590 DCHECK(connections_.count(connection.get())); |
1592 if (ConnectionCount() > 1) { | 1591 if (ConnectionCount() > 1) { |
1593 DCHECK_NE(blink::WebIDBDataLossTotal, callbacks->data_loss()); | 1592 DCHECK_NE(blink::WebIDBDataLossTotal, callbacks->data_loss()); |
1594 // Front end ensures the event is not fired at connections that have | 1593 // Front end ensures the event is not fired at connections that have |
1595 // close_pending set. | 1594 // close_pending set. |
1596 for (ConnectionSet::const_iterator it = connections_.begin(); | 1595 for (ConnectionSet::const_iterator it = connections_.begin(); |
1597 it != connections_.end(); | 1596 it != connections_.end(); |
1598 ++it) { | 1597 ++it) { |
1599 if (*it != connection.get()) { | 1598 if (*it != connection.get()) { |
1600 (*it)->callbacks()->OnVersionChange(metadata_.int_version, | 1599 (*it)->callbacks()->OnVersionChange(metadata_.int_version, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 DeleteDatabaseFinal(callbacks); | 1654 DeleteDatabaseFinal(callbacks); |
1656 } | 1655 } |
1657 | 1656 |
1658 bool IndexedDBDatabase::IsDeleteDatabaseBlocked() const { | 1657 bool IndexedDBDatabase::IsDeleteDatabaseBlocked() const { |
1659 return !!ConnectionCount(); | 1658 return !!ConnectionCount(); |
1660 } | 1659 } |
1661 | 1660 |
1662 void IndexedDBDatabase::DeleteDatabaseFinal( | 1661 void IndexedDBDatabase::DeleteDatabaseFinal( |
1663 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1662 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1664 DCHECK(!IsDeleteDatabaseBlocked()); | 1663 DCHECK(!IsDeleteDatabaseBlocked()); |
1665 DCHECK(backing_store_); | 1664 DCHECK(backing_store_.get()); |
1666 leveldb::Status s = backing_store_->DeleteDatabase(metadata_.name); | 1665 leveldb::Status s = backing_store_->DeleteDatabase(metadata_.name); |
1667 if (!s.ok()) { | 1666 if (!s.ok()) { |
1668 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1667 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1669 "Internal error deleting database."); | 1668 "Internal error deleting database."); |
1670 callbacks->OnError(error); | 1669 callbacks->OnError(error); |
1671 if (s.IsCorruption()) { | 1670 if (s.IsCorruption()) { |
1672 GURL origin_url = backing_store_->origin_url(); | 1671 GURL origin_url = backing_store_->origin_url(); |
1673 backing_store_ = NULL; | 1672 backing_store_ = NULL; |
1674 factory_->HandleBackingStoreCorruption(origin_url, error); | 1673 factory_->HandleBackingStoreCorruption(origin_url, error); |
1675 } | 1674 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 IndexedDBTransaction* transaction) { | 1780 IndexedDBTransaction* transaction) { |
1782 DCHECK(!transaction); | 1781 DCHECK(!transaction); |
1783 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", | 1782 IDB_TRACE1("IndexedDBDatabase::VersionChangeAbortOperation", |
1784 "txn.id", | 1783 "txn.id", |
1785 transaction->id()); | 1784 transaction->id()); |
1786 metadata_.version = previous_version; | 1785 metadata_.version = previous_version; |
1787 metadata_.int_version = previous_int_version; | 1786 metadata_.int_version = previous_int_version; |
1788 } | 1787 } |
1789 | 1788 |
1790 } // namespace content | 1789 } // namespace content |
OLD | NEW |