Index: content/browser/indexed_db/indexed_db_database_back.cc |
diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database_back.cc |
similarity index 95% |
copy from content/browser/indexed_db/indexed_db_database.cc |
copy to content/browser/indexed_db/indexed_db_database_back.cc |
index 86ed058e8e5a6bec3beb6f7514f66e6b4b0adb90..1ec75d47de1461f58ffb71753f0440c74d653f4e 100644 |
--- a/content/browser/indexed_db/indexed_db_database.cc |
+++ b/content/browser/indexed_db/indexed_db_database_back.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" |
@@ -761,11 +763,12 @@ void IndexedDBDatabase::Abort(int64_t transaction_id, |
} |
void IndexedDBDatabase::AddPendingObserver(int64_t transaction_id, |
- int32_t observer_id) { |
+ int32_t observer_id, |
+ IndexedDBObserver::Options options) { |
IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
if (!transaction) |
return; |
- transaction->AddPendingObserver(observer_id); |
+ transaction->AddPendingObserver(observer_id, options); |
} |
void IndexedDBDatabase::RemovePendingObservers( |
@@ -779,6 +782,45 @@ void IndexedDBDatabase::RemovePendingObservers( |
} |
} |
+// 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, |
@@ -1333,6 +1375,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, |
@@ -1676,6 +1723,8 @@ void IndexedDBDatabase::DeleteRangeOperation( |
} else { |
callbacks->OnSuccess(); |
} |
+ FilterObservation(transaction, object_store_id, blink::WebIDBDelete, |
+ *key_range); |
} |
void IndexedDBDatabase::Clear(int64_t transaction_id, |
@@ -1711,6 +1760,9 @@ void IndexedDBDatabase::ClearOperation( |
return; |
} |
callbacks->OnSuccess(); |
+ |
+ FilterObservation(transaction, object_store_id, blink::WebIDBClear, |
+ IndexedDBKeyRange()); |
} |
void IndexedDBDatabase::DeleteObjectStoreOperation( |
@@ -1748,6 +1800,7 @@ void IndexedDBDatabase::DeleteObjectStoreOperation( |
void IndexedDBDatabase::VersionChangeOperation( |
int64_t version, |
scoped_refptr<IndexedDBCallbacks> callbacks, |
+ std::unique_ptr<IndexedDBConnection> connection, |
IndexedDBTransaction* transaction) { |
IDB_TRACE1( |
"IndexedDBDatabase::VersionChangeOperation", "txn.id", transaction->id()); |
@@ -1822,16 +1875,17 @@ void IndexedDBDatabase::ProcessRequestQueue() { |
// blocked. |
if (processing_pending_requests_) |
return; |
+} |
- DCHECK(!active_request_); |
- DCHECK(!pending_requests_.empty()); |
+DCHECK(!active_request_); |
+DCHECK(!pending_requests_.empty()); |
- base::AutoReset<bool> processing(&processing_pending_requests_, true); |
- do { |
- active_request_ = std::move(pending_requests_.front()); |
- pending_requests_.pop(); |
- active_request_->Perform(); |
- // If the active request completed synchronously, keep going. |
+base::AutoReset<bool> processing(&processing_pending_requests_, true); |
+do { |
+ active_request_ = std::move(pending_requests_.front()); |
+ pending_requests_.pop(); |
+ active_request_->Perform(); |
+ // If the active request completed synchronously, keep going. |
} while (!active_request_ && !pending_requests_.empty()); |
} |
@@ -1865,6 +1919,12 @@ void IndexedDBDatabase::TransactionCreated(IndexedDBTransaction* transaction) { |
transactions_[transaction->id()] = transaction; |
} |
+bool IndexedDBDatabase::IsOpenConnectionBlocked() const { |
+ return !pending_delete_calls_.empty() || |
+ transaction_coordinator_.IsRunningVersionChangeTransaction() || |
+ pending_run_version_change_transaction_call_; |
+} |
+ |
void IndexedDBDatabase::OpenConnection( |
const IndexedDBPendingConnection& connection) { |
AppendRequest(base::MakeUnique<OpenRequest>(this, connection)); |