Chromium Code Reviews| 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 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 25 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
| 26 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 26 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
| 27 #include "content/browser/indexed_db/indexed_db_connection.h" | 27 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 28 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 28 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 29 #include "content/browser/indexed_db/indexed_db_cursor.h" | 29 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 30 #include "content/browser/indexed_db/indexed_db_factory.h" | 30 #include "content/browser/indexed_db/indexed_db_factory.h" |
| 31 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 31 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
| 32 #include "content/browser/indexed_db/indexed_db_observation.h" | |
| 33 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | |
| 32 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 34 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| 33 #include "content/browser/indexed_db/indexed_db_return_value.h" | 35 #include "content/browser/indexed_db/indexed_db_return_value.h" |
| 34 #include "content/browser/indexed_db/indexed_db_tracing.h" | 36 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 35 #include "content/browser/indexed_db/indexed_db_transaction.h" | 37 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 36 #include "content/browser/indexed_db/indexed_db_value.h" | 38 #include "content/browser/indexed_db/indexed_db_value.h" |
| 37 #include "content/common/indexed_db/indexed_db_constants.h" | 39 #include "content/common/indexed_db/indexed_db_constants.h" |
| 38 #include "content/common/indexed_db/indexed_db_key_path.h" | 40 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 39 #include "content/common/indexed_db/indexed_db_key_range.h" | 41 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 40 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 41 #include "storage/browser/blob/blob_data_handle.h" | 43 #include "storage/browser/blob/blob_data_handle.h" |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 const IndexedDBDatabaseError& error) { | 537 const IndexedDBDatabaseError& error) { |
| 536 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); | 538 IDB_TRACE1("IndexedDBDatabase::Abort(error)", "txn.id", transaction_id); |
| 537 // If the transaction is unknown, then it has already been aborted by the | 539 // If the transaction is unknown, then it has already been aborted by the |
| 538 // backend before this call so it is safe to ignore it. | 540 // backend before this call so it is safe to ignore it. |
| 539 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 541 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 540 if (transaction) | 542 if (transaction) |
| 541 transaction->Abort(error); | 543 transaction->Abort(error); |
| 542 } | 544 } |
| 543 | 545 |
| 544 void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id, | 546 void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id, |
| 545 int32_t observer_id) { | 547 int32_t observer_id, |
| 548 bool includeTransaction, | |
|
jsbell
2016/07/14 20:08:13
Would it make sense to bundle these up into an Ind
palakj1
2016/07/15 20:16:04
True. Done.
| |
| 549 bool noRecords, | |
|
cmumford
2016/07/14 21:11:35
+1 to jsbell's suggestion. Also naming convention
| |
| 550 bool values) { | |
| 546 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 551 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 547 if (!transaction) | 552 if (!transaction) |
| 548 return; | 553 return; |
| 549 transaction->AddPendingObserver(observer_id); | 554 transaction->AddPendingObserver(observer_id, includeTransaction, noRecords, |
| 555 values); | |
| 550 } | 556 } |
| 551 | 557 |
| 552 void IndexedDBDatabase::RemovePendingObservers( | 558 void IndexedDBDatabase::RemovePendingObservers( |
| 553 IndexedDBConnection* connection, | 559 IndexedDBConnection* connection, |
| 554 const std::vector<int32_t>& pending_observer_ids) { | 560 const std::vector<int32_t>& pending_observer_ids) { |
| 555 TransactionMap::iterator it; | 561 TransactionMap::iterator it; |
| 556 for (it = transactions_.begin(); it != transactions_.end(); it++) { | 562 for (it = transactions_.begin(); it != transactions_.end(); it++) { |
| 557 // Avoid call to RemovePendingObservers for transactions on other | 563 // Avoid call to RemovePendingObservers for transactions on other |
| 558 // connections. | 564 // connections. |
| 559 if (it->second->connection() == connection) | 565 if (it->second->connection() == connection) |
| 560 it->second->RemovePendingObservers(pending_observer_ids); | 566 it->second->RemovePendingObservers(pending_observer_ids); |
| 561 } | 567 } |
| 562 } | 568 } |
| 563 | 569 |
| 570 // TODO(palakj): Augment the function with IDBValue later. | |
| 571 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, | |
| 572 int64_t object_store_id, | |
| 573 blink::WebIDBOperationType type, | |
| 574 const IndexedDBKeyRange& key_range) { | |
| 575 for (const auto* connection : connections_) { | |
| 576 bool recorded = false; | |
| 577 for (const auto& observer : connection->active_observers()) { | |
| 578 if (!observer->IsRecordingType(type) || | |
| 579 !observer->IsRecordingObjectStore(object_store_id)) | |
| 580 continue; | |
| 581 if (!recorded) { | |
| 582 if (type == blink::WebIDBClear) { | |
| 583 transaction->AddObservation(connection->id(), | |
| 584 base::WrapUnique(new IndexedDBObservation( | |
| 585 object_store_id, type))); | |
| 586 } else { | |
| 587 transaction->AddObservation(connection->id(), | |
| 588 base::WrapUnique(new IndexedDBObservation( | |
| 589 object_store_id, type, key_range))); | |
| 590 } | |
| 591 recorded = true; | |
| 592 } | |
| 593 transaction->RecordObserverForLastObservation(connection->id(), | |
| 594 observer->id()); | |
| 595 } | |
| 596 } | |
| 597 } | |
| 598 | |
| 599 void IndexedDBDatabase::SendObservations( | |
| 600 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) { | |
| 601 for (const auto& conn : connections_) { | |
| 602 auto it = changes_map.find(conn->id()); | |
| 603 if (it != changes_map.end()) | |
| 604 conn->callbacks()->OnDatabaseChange(it->first, std::move(it->second)); | |
| 605 } | |
| 606 } | |
| 607 | |
| 564 void IndexedDBDatabase::GetAll(int64_t transaction_id, | 608 void IndexedDBDatabase::GetAll(int64_t transaction_id, |
| 565 int64_t object_store_id, | 609 int64_t object_store_id, |
| 566 int64_t index_id, | 610 int64_t index_id, |
| 567 std::unique_ptr<IndexedDBKeyRange> key_range, | 611 std::unique_ptr<IndexedDBKeyRange> key_range, |
| 568 bool key_only, | 612 bool key_only, |
| 569 int64_t max_count, | 613 int64_t max_count, |
| 570 scoped_refptr<IndexedDBCallbacks> callbacks) { | 614 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 571 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); | 615 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |
| 572 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 616 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 573 if (!transaction) | 617 if (!transaction) |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 if (s.IsCorruption()) | 1152 if (s.IsCorruption()) |
| 1109 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1153 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1110 return; | 1154 return; |
| 1111 } | 1155 } |
| 1112 } | 1156 } |
| 1113 { | 1157 { |
| 1114 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", | 1158 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", |
| 1115 transaction->id()); | 1159 transaction->id()); |
| 1116 params->callbacks->OnSuccess(*key); | 1160 params->callbacks->OnSuccess(*key); |
| 1117 } | 1161 } |
| 1162 FilterObservation(transaction, params->object_store_id, | |
| 1163 params->put_mode == blink::WebIDBPutModeAddOnly | |
| 1164 ? blink::WebIDBAdd | |
| 1165 : blink::WebIDBPut, | |
| 1166 IndexedDBKeyRange(*key)); | |
| 1118 } | 1167 } |
| 1119 | 1168 |
| 1120 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, | 1169 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, |
| 1121 int64_t object_store_id, | 1170 int64_t object_store_id, |
| 1122 std::unique_ptr<IndexedDBKey> primary_key, | 1171 std::unique_ptr<IndexedDBKey> primary_key, |
| 1123 const std::vector<IndexKeys>& index_keys) { | 1172 const std::vector<IndexKeys>& index_keys) { |
| 1124 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); | 1173 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); |
| 1125 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1174 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 1126 if (!transaction) | 1175 if (!transaction) |
| 1127 return; | 1176 return; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 if (s.IsCorruption()) { | 1500 if (s.IsCorruption()) { |
| 1452 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1501 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1453 } | 1502 } |
| 1454 return; | 1503 return; |
| 1455 } | 1504 } |
| 1456 if (experimental_web_platform_features_enabled_) { | 1505 if (experimental_web_platform_features_enabled_) { |
| 1457 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); | 1506 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); |
| 1458 } else { | 1507 } else { |
| 1459 callbacks->OnSuccess(); | 1508 callbacks->OnSuccess(); |
| 1460 } | 1509 } |
| 1510 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, | |
| 1511 *key_range); | |
| 1461 } | 1512 } |
| 1462 | 1513 |
| 1463 void IndexedDBDatabase::Clear(int64_t transaction_id, | 1514 void IndexedDBDatabase::Clear(int64_t transaction_id, |
| 1464 int64_t object_store_id, | 1515 int64_t object_store_id, |
| 1465 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1516 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 1466 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); | 1517 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |
| 1467 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1518 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| 1468 if (!transaction) | 1519 if (!transaction) |
| 1469 return; | 1520 return; |
| 1470 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1521 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1486 if (!s.ok()) { | 1537 if (!s.ok()) { |
| 1487 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1538 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| 1488 "Internal error clearing object store"); | 1539 "Internal error clearing object store"); |
| 1489 callbacks->OnError(error); | 1540 callbacks->OnError(error); |
| 1490 if (s.IsCorruption()) { | 1541 if (s.IsCorruption()) { |
| 1491 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1542 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
| 1492 } | 1543 } |
| 1493 return; | 1544 return; |
| 1494 } | 1545 } |
| 1495 callbacks->OnSuccess(); | 1546 callbacks->OnSuccess(); |
| 1547 | |
| 1548 FilterObservation(transaction, object_store_id, blink::WebIDBClear, | |
| 1549 IndexedDBKeyRange()); | |
| 1496 } | 1550 } |
| 1497 | 1551 |
| 1498 void IndexedDBDatabase::DeleteObjectStoreOperation( | 1552 void IndexedDBDatabase::DeleteObjectStoreOperation( |
| 1499 int64_t object_store_id, | 1553 int64_t object_store_id, |
| 1500 IndexedDBTransaction* transaction) { | 1554 IndexedDBTransaction* transaction) { |
| 1501 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", | 1555 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", |
| 1502 "txn.id", | 1556 "txn.id", |
| 1503 transaction->id()); | 1557 transaction->id()); |
| 1504 | 1558 |
| 1505 const IndexedDBObjectStoreMetadata object_store_metadata = | 1559 const IndexedDBObjectStoreMetadata object_store_metadata = |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1970 | 2024 |
| 1971 void IndexedDBDatabase::VersionChangeAbortOperation( | 2025 void IndexedDBDatabase::VersionChangeAbortOperation( |
| 1972 int64_t previous_version, | 2026 int64_t previous_version, |
| 1973 IndexedDBTransaction* transaction) { | 2027 IndexedDBTransaction* transaction) { |
| 1974 DCHECK(!transaction); | 2028 DCHECK(!transaction); |
| 1975 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2029 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
| 1976 metadata_.version = previous_version; | 2030 metadata_.version = previous_version; |
| 1977 } | 2031 } |
| 1978 | 2032 |
| 1979 } // namespace content | 2033 } // namespace content |
| OLD | NEW |