Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: content/browser/indexed_db/indexed_db_database.cc

Issue 2125213002: [IndexedDB] Propogating changes to observers : Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lifetime
Patch Set: IDBDatabase weakptr introduced on IDBObserver Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..928ee5281d55d954bd0f769c253b6a26cca3a5fb 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"
@@ -561,6 +563,45 @@ 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(observer->id(),
+ connection->id());
+ }
+ }
+}
+
+void IndexedDBDatabase::SendObservations(
+ std::map<int32_t, std::unique_ptr<IndexedDBObserverChanges>> change_map) {
+ for (const auto& it : connections_) {
+ std::unique_ptr<IndexedDBObserverChanges> change =
+ std::move(change_map[it->id()]);
Marijn Kruisselbrink 2016/07/11 23:10:39 Rather than using operator[] to look up the connec
palakj1 2016/07/13 00:43:50 I see your point. Done.
+ if (change)
+ it->callbacks()->OnDatabaseChange(it->id(), std::move(change));
+ }
+}
+
void IndexedDBDatabase::GetAll(int64_t transaction_id,
int64_t object_store_id,
int64_t index_id,
@@ -1115,6 +1156,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 +1504,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 +1541,9 @@ void IndexedDBDatabase::ClearOperation(
return;
}
callbacks->OnSuccess();
+
+ FilterObservation(transaction, object_store_id, blink::WebIDBClear,
+ IndexedDBKeyRange());
}
void IndexedDBDatabase::DeleteObjectStoreOperation(

Powered by Google App Engine
This is Rietveld 408576698