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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 const std::vector<int32_t>& pending_observer_ids) { | 556 const std::vector<int32_t>& pending_observer_ids) { |
555 TransactionMap::iterator it; | 557 TransactionMap::iterator it; |
556 for (it = transactions_.begin(); it != transactions_.end(); it++) { | 558 for (it = transactions_.begin(); it != transactions_.end(); it++) { |
557 // Avoid call to RemovePendingObservers for transactions on other | 559 // Avoid call to RemovePendingObservers for transactions on other |
558 // connections. | 560 // connections. |
559 if (it->second->connection() == connection) | 561 if (it->second->connection() == connection) |
560 it->second->RemovePendingObservers(pending_observer_ids); | 562 it->second->RemovePendingObservers(pending_observer_ids); |
561 } | 563 } |
562 } | 564 } |
563 | 565 |
566 // TODO(palakj): Augment the function with IDBValue later. | |
567 void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, | |
568 int64_t object_store_id, | |
569 blink::WebIDBOperationType type, | |
570 const IndexedDBKeyRange& key_range) { | |
571 for (const auto* connection : connections_) { | |
572 bool recorded = false; | |
573 for (const auto& observer : connection->active_observers()) { | |
574 if (observer->IsRecordingType(type) && | |
575 observer->IsRecordingObjectStore(object_store_id)) { | |
jsbell
2016/07/11 18:25:33
It might be more readable to invert this test and
palakj1
2016/07/11 22:25:40
Done.
| |
576 if (!recorded) { | |
577 if (type == blink::WebIDBClear) { | |
578 transaction->AddObservation( | |
579 connection->id(), base::WrapUnique(new IndexedDBObservation( | |
580 object_store_id, type))); | |
581 } else { | |
582 transaction->AddObservation( | |
583 connection->id(), base::WrapUnique(new IndexedDBObservation( | |
584 object_store_id, type, key_range))); | |
585 } | |
586 recorded = true; | |
587 } | |
588 transaction->RecordObserverForLastObservation(observer->id(), | |
589 connection->id()); | |
590 } | |
591 } | |
592 } | |
593 } | |
594 | |
595 void IndexedDBDatabase::SendObservations( | |
596 std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> change_map) { | |
597 for (const auto& it : connections_) | |
598 it->callbacks()->OnDatabaseChange(it->id(), | |
599 std::move(change_map[it->id()])); | |
600 } | |
601 | |
564 void IndexedDBDatabase::GetAll(int64_t transaction_id, | 602 void IndexedDBDatabase::GetAll(int64_t transaction_id, |
565 int64_t object_store_id, | 603 int64_t object_store_id, |
566 int64_t index_id, | 604 int64_t index_id, |
567 std::unique_ptr<IndexedDBKeyRange> key_range, | 605 std::unique_ptr<IndexedDBKeyRange> key_range, |
568 bool key_only, | 606 bool key_only, |
569 int64_t max_count, | 607 int64_t max_count, |
570 scoped_refptr<IndexedDBCallbacks> callbacks) { | 608 scoped_refptr<IndexedDBCallbacks> callbacks) { |
571 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); | 609 IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |
572 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 610 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
573 if (!transaction) | 611 if (!transaction) |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 if (s.IsCorruption()) | 1146 if (s.IsCorruption()) |
1109 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1147 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1110 return; | 1148 return; |
1111 } | 1149 } |
1112 } | 1150 } |
1113 { | 1151 { |
1114 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", | 1152 IDB_TRACE1("IndexedDBDatabase::PutOperation.Callbacks", "txn.id", |
1115 transaction->id()); | 1153 transaction->id()); |
1116 params->callbacks->OnSuccess(*key); | 1154 params->callbacks->OnSuccess(*key); |
1117 } | 1155 } |
1156 FilterObservation(transaction, params->object_store_id, | |
1157 params->put_mode == blink::WebIDBPutModeAddOnly | |
1158 ? blink::WebIDBAdd | |
1159 : blink::WebIDBPut, | |
1160 IndexedDBKeyRange(*key)); | |
1118 } | 1161 } |
1119 | 1162 |
1120 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, | 1163 void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, |
1121 int64_t object_store_id, | 1164 int64_t object_store_id, |
1122 std::unique_ptr<IndexedDBKey> primary_key, | 1165 std::unique_ptr<IndexedDBKey> primary_key, |
1123 const std::vector<IndexKeys>& index_keys) { | 1166 const std::vector<IndexKeys>& index_keys) { |
1124 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); | 1167 IDB_TRACE1("IndexedDBDatabase::SetIndexKeys", "txn.id", transaction_id); |
1125 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1168 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1126 if (!transaction) | 1169 if (!transaction) |
1127 return; | 1170 return; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 if (s.IsCorruption()) { | 1494 if (s.IsCorruption()) { |
1452 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1495 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1453 } | 1496 } |
1454 return; | 1497 return; |
1455 } | 1498 } |
1456 if (experimental_web_platform_features_enabled_) { | 1499 if (experimental_web_platform_features_enabled_) { |
1457 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); | 1500 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); |
1458 } else { | 1501 } else { |
1459 callbacks->OnSuccess(); | 1502 callbacks->OnSuccess(); |
1460 } | 1503 } |
1504 FilterObservation(transaction, object_store_id, blink::WebIDBDelete, | |
1505 *key_range); | |
1461 } | 1506 } |
1462 | 1507 |
1463 void IndexedDBDatabase::Clear(int64_t transaction_id, | 1508 void IndexedDBDatabase::Clear(int64_t transaction_id, |
1464 int64_t object_store_id, | 1509 int64_t object_store_id, |
1465 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1510 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1466 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); | 1511 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |
1467 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1512 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1468 if (!transaction) | 1513 if (!transaction) |
1469 return; | 1514 return; |
1470 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1515 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
(...skipping 15 matching lines...) Expand all Loading... | |
1486 if (!s.ok()) { | 1531 if (!s.ok()) { |
1487 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1532 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1488 "Internal error clearing object store"); | 1533 "Internal error clearing object store"); |
1489 callbacks->OnError(error); | 1534 callbacks->OnError(error); |
1490 if (s.IsCorruption()) { | 1535 if (s.IsCorruption()) { |
1491 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1536 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1492 } | 1537 } |
1493 return; | 1538 return; |
1494 } | 1539 } |
1495 callbacks->OnSuccess(); | 1540 callbacks->OnSuccess(); |
1541 | |
1542 FilterObservation(transaction, object_store_id, blink::WebIDBClear, | |
1543 IndexedDBKeyRange()); | |
1496 } | 1544 } |
1497 | 1545 |
1498 void IndexedDBDatabase::DeleteObjectStoreOperation( | 1546 void IndexedDBDatabase::DeleteObjectStoreOperation( |
1499 int64_t object_store_id, | 1547 int64_t object_store_id, |
1500 IndexedDBTransaction* transaction) { | 1548 IndexedDBTransaction* transaction) { |
1501 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", | 1549 IDB_TRACE1("IndexedDBDatabase::DeleteObjectStoreOperation", |
1502 "txn.id", | 1550 "txn.id", |
1503 transaction->id()); | 1551 transaction->id()); |
1504 | 1552 |
1505 const IndexedDBObjectStoreMetadata object_store_metadata = | 1553 const IndexedDBObjectStoreMetadata object_store_metadata = |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1970 | 2018 |
1971 void IndexedDBDatabase::VersionChangeAbortOperation( | 2019 void IndexedDBDatabase::VersionChangeAbortOperation( |
1972 int64_t previous_version, | 2020 int64_t previous_version, |
1973 IndexedDBTransaction* transaction) { | 2021 IndexedDBTransaction* transaction) { |
1974 DCHECK(!transaction); | 2022 DCHECK(!transaction); |
1975 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 2023 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1976 metadata_.version = previous_version; | 2024 metadata_.version = previous_version; |
1977 } | 2025 } |
1978 | 2026 |
1979 } // namespace content | 2027 } // namespace content |
OLD | NEW |