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..aaa1a190e31ef537d640a9bd9888a25d78fe1c3b 100644 |
--- a/content/browser/indexed_db/indexed_db_database.cc |
+++ b/content/browser/indexed_db/indexed_db_database.cc |
@@ -37,6 +37,7 @@ |
#include "content/common/indexed_db/indexed_db_constants.h" |
#include "content/common/indexed_db/indexed_db_key_path.h" |
#include "content/common/indexed_db/indexed_db_key_range.h" |
+#include "content/common/indexed_db/indexed_db_observation.h" |
#include "content/public/common/content_switches.h" |
#include "storage/browser/blob/blob_data_handle.h" |
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h" |
@@ -561,6 +562,47 @@ void IndexedDBDatabase::RemovePendingObservers( |
} |
} |
+// TODO(palakj): Augment the function with IDBValue later. |
+void IndexedDBDatabase::FilterObservation( |
+ IndexedDBTransaction* transaction, |
+ int64_t object_store_id, |
+ IndexedDBObservation::OperationType type, |
+ const IndexedDBKeyRange& key_range) { |
+ bool recorded = false; |
+ for (const auto* connection : connections_) { |
+ if (!connection) |
cmumford
2016/07/07 21:14:21
How would a NULL connection wind up in connections
palakj1
2016/07/08 17:37:55
Right, that's redundant.
|
+ continue; |
+ |
+ const std::vector<std::unique_ptr<IndexedDBObserver>>& observers = |
+ connection->active_observers(); |
+ for (const auto& observer : observers) { |
cmumford
2016/07/07 21:14:21
Just use:
for (const auto& observer : connectio
palakj1
2016/07/08 17:37:55
Done.
|
+ if (observer->IsRecordingType(type) && |
+ observer->IsRecordingObjectStore(object_store_id)) { |
+ if (!recorded) { |
+ if (type == IndexedDBObservation::OperationType::CLEAR) { |
+ transaction->AddObservation( |
+ connection->id(), |
+ base::WrapUnique(new IndexedDBObservation(type))); |
+ } else { |
+ transaction->AddObservation( |
+ connection->id(), |
+ base::WrapUnique(new IndexedDBObservation(type, key_range))); |
+ } |
+ recorded = true; |
+ } |
+ transaction->AddObservationIndex(observer->id(), connection->id()); |
+ } |
+ } |
+ } |
+} |
+ |
+void IndexedDBDatabase::SendObservations( |
+ std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> change_map) { |
+ for (const auto& it : connections_) { |
cmumford
2016/07/07 21:14:21
Nit: no need for braces for a single line.
palakj1
2016/07/08 17:37:55
Done.
|
+ it->callbacks()->OnDatabaseChange(std::move(change_map[it->id()])); |
+ } |
+} |
+ |
void IndexedDBDatabase::GetAll(int64_t transaction_id, |
int64_t object_store_id, |
int64_t index_id, |
@@ -1115,6 +1157,12 @@ 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 |
+ ? IndexedDBObservation::OperationType::ADD |
+ : IndexedDBObservation::OperationType::PUT, |
+ IndexedDBKeyRange(*key)); // std::move |
} |
void IndexedDBDatabase::SetIndexKeys(int64_t transaction_id, |
@@ -1458,6 +1506,8 @@ void IndexedDBDatabase::DeleteRangeOperation( |
} else { |
callbacks->OnSuccess(); |
} |
+ FilterObservation(transaction, object_store_id, |
+ IndexedDBObservation::OperationType::DELETE, *key_range); |
} |
void IndexedDBDatabase::Clear(int64_t transaction_id, |
@@ -1493,6 +1543,9 @@ void IndexedDBDatabase::ClearOperation( |
return; |
} |
callbacks->OnSuccess(); |
+ |
+ // FilterObservation(transaction, object_store_id, |
cmumford
2016/07/07 21:14:21
Why is this commented out?
palakj1
2016/07/08 17:37:55
Done.
|
+ // IndexedDBObservation::OperationType::CLEAR, ); |
} |
void IndexedDBDatabase::DeleteObjectStoreOperation( |