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

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

Issue 2160163002: [IndexedDB] Propogating Changes to Observer : Browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Browser changes 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 6d104a56d42d256a631fe1c1834c64bd176c1f5d..dd8185031dba23592dedeef50eba2f38def8baf4 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"
@@ -541,6 +543,66 @@ void IndexedDBDatabase::Abort(int64_t transaction_id,
transaction->Abort(error);
}
+void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id,
+ int32_t observer_id,
+ IndexedDBObserver::Options options) {
+ IndexedDBTransaction* transaction = GetTransaction(transaction_id);
+ if (!transaction)
+ return;
+ transaction->AddPendingObserver(observer_id, options);
+}
+
+void IndexedDBDatabase::RemovePendingObservers(
+ IndexedDBConnection* connection,
+ const std::vector<int32_t>& pending_observer_ids) {
+ TransactionMap::iterator it;
+ for (it = transactions_.begin(); it != transactions_.end(); it++) {
+ // Avoid call to RemovePendingObservers for transactions on other
+ // connections.
+ if (it->second->connection() == connection)
+ it->second->RemovePendingObservers(pending_observer_ids);
+ }
+}
+
+// TODO(palakj): Augment the function with IDBValue later. Issue
+// crbug.com/609934.
+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,
@@ -1095,6 +1157,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,
@@ -1438,6 +1505,8 @@ void IndexedDBDatabase::DeleteRangeOperation(
} else {
callbacks->OnSuccess();
}
+ FilterObservation(transaction, object_store_id, blink::WebIDBDelete,
+ *key_range);
}
void IndexedDBDatabase::Clear(int64_t transaction_id,
@@ -1473,6 +1542,9 @@ void IndexedDBDatabase::ClearOperation(
return;
}
callbacks->OnSuccess();
+
+ FilterObservation(transaction, object_store_id, blink::WebIDBClear,
+ IndexedDBKeyRange());
}
void IndexedDBDatabase::DeleteObjectStoreOperation(
@@ -1665,9 +1737,9 @@ void IndexedDBDatabase::CreateTransaction(
// The transaction will add itself to this database's coordinator, which
// manages the lifetime of the object.
TransactionCreated(IndexedDBClassFactory::Get()->CreateIndexedDBTransaction(
- transaction_id, connection->callbacks(),
+ transaction_id, connection->GetWeakPtr(),
std::set<int64_t>(object_store_ids.begin(), object_store_ids.end()), mode,
- this, new IndexedDBBackingStore::Transaction(backing_store_.get())));
+ new IndexedDBBackingStore::Transaction(backing_store_.get())));
}
void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) {
@@ -1905,7 +1977,7 @@ void IndexedDBDatabase::Close(IndexedDBConnection* connection, bool forced) {
{
TransactionMap transactions(transactions_);
for (const auto& it : transactions) {
- if (it.second->connection() == connection->callbacks())
+ if (it.second->callbacks() == connection->callbacks())
it.second->Abort(
IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError,
"Connection is closing."));

Powered by Google App Engine
This is Rietveld 408576698