Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_database.cc |
| diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc |
| index a73ba298ee5616a7fdbbe4925781907e33cae45f..432a4e22f958978407fec3b92c8a3e6836c95388 100644 |
| --- a/content/browser/indexed_db/indexed_db_database.cc |
| +++ b/content/browser/indexed_db/indexed_db_database.cc |
| @@ -29,6 +29,8 @@ |
| #include "content/browser/indexed_db/indexed_db_cursor.h" |
| #include "content/browser/indexed_db/indexed_db_factory.h" |
| #include "content/browser/indexed_db/indexed_db_index_writer.h" |
| +#include "content/browser/indexed_db/indexed_db_observation.h" |
| +#include "content/browser/indexed_db/indexed_db_observer_changes.h" |
| #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
| #include "content/browser/indexed_db/indexed_db_return_value.h" |
| #include "content/browser/indexed_db/indexed_db_tracing.h" |
| @@ -542,11 +544,15 @@ void IndexedDBDatabase::Abort(int64_t transaction_id, |
| } |
| void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id, |
| - int32_t observer_id) { |
| + int32_t observer_id, |
| + 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.
|
| + bool noRecords, |
|
cmumford
2016/07/14 21:11:35
+1 to jsbell's suggestion. Also naming convention
|
| + bool values) { |
| IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| if (!transaction) |
| return; |
| - transaction->AddPendingObserver(observer_id); |
| + transaction->AddPendingObserver(observer_id, includeTransaction, noRecords, |
| + values); |
| } |
| void IndexedDBDatabase::RemovePendingObservers( |
| @@ -561,6 +567,44 @@ void IndexedDBDatabase::RemovePendingObservers( |
| } |
| } |
| +// TODO(palakj): Augment the function with IDBValue later. |
| +void IndexedDBDatabase::FilterObservation(IndexedDBTransaction* transaction, |
| + int64_t object_store_id, |
| + blink::WebIDBOperationType type, |
| + const IndexedDBKeyRange& key_range) { |
| + for (const auto* connection : connections_) { |
| + bool recorded = false; |
| + for (const auto& observer : connection->active_observers()) { |
| + if (!observer->IsRecordingType(type) || |
| + !observer->IsRecordingObjectStore(object_store_id)) |
| + continue; |
| + if (!recorded) { |
| + if (type == blink::WebIDBClear) { |
| + transaction->AddObservation(connection->id(), |
| + base::WrapUnique(new IndexedDBObservation( |
| + object_store_id, type))); |
| + } else { |
| + transaction->AddObservation(connection->id(), |
| + base::WrapUnique(new IndexedDBObservation( |
| + object_store_id, type, key_range))); |
| + } |
| + recorded = true; |
| + } |
| + transaction->RecordObserverForLastObservation(connection->id(), |
| + observer->id()); |
| + } |
| + } |
| +} |
| + |
| +void IndexedDBDatabase::SendObservations( |
| + std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> changes_map) { |
| + for (const auto& conn : connections_) { |
| + auto it = changes_map.find(conn->id()); |
| + if (it != changes_map.end()) |
| + conn->callbacks()->OnDatabaseChange(it->first, std::move(it->second)); |
| + } |
| +} |
| + |
| void IndexedDBDatabase::GetAll(int64_t transaction_id, |
| int64_t object_store_id, |
| int64_t index_id, |
| @@ -1115,6 +1159,11 @@ void IndexedDBDatabase::PutOperation(std::unique_ptr<PutOperationParams> params, |
| transaction->id()); |
| params->callbacks->OnSuccess(*key); |
| } |
| + FilterObservation(transaction, params->object_store_id, |
| + params->put_mode == blink::WebIDBPutModeAddOnly |
| + ? blink::WebIDBAdd |
| + : blink::WebIDBPut, |
| + IndexedDBKeyRange(*key)); |
| } |
| void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, |
| @@ -1458,6 +1507,8 @@ void IndexedDBDatabase::DeleteRangeOperation( |
| } else { |
| callbacks->OnSuccess(); |
| } |
| + FilterObservation(transaction, object_store_id, blink::WebIDBDelete, |
| + *key_range); |
| } |
| void IndexedDBDatabase::Clear(int64_t transaction_id, |
| @@ -1493,6 +1544,9 @@ void IndexedDBDatabase::ClearOperation( |
| return; |
| } |
| callbacks->OnSuccess(); |
| + |
| + FilterObservation(transaction, object_store_id, blink::WebIDBClear, |
| + IndexedDBKeyRange()); |
| } |
| void IndexedDBDatabase::DeleteObjectStoreOperation( |