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

Unified Diff: content/browser/indexed_db/indexed_db_connection.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_connection.cc
diff --git a/content/browser/indexed_db/indexed_db_connection.cc b/content/browser/indexed_db/indexed_db_connection.cc
index f7133a69230da18b88b9deb75e84775823d9467e..45f3e81feed54d42f54c83f1ab12e4c43379f4db 100644
--- a/content/browser/indexed_db/indexed_db_connection.cc
+++ b/content/browser/indexed_db/indexed_db_connection.cc
@@ -4,6 +4,9 @@
#include "content/browser/indexed_db/indexed_db_connection.h"
+#include "base/logging.h"
+#include "base/stl_util.h"
+
namespace content {
IndexedDBConnection::IndexedDBConnection(
@@ -13,6 +16,11 @@ IndexedDBConnection::IndexedDBConnection(
IndexedDBConnection::~IndexedDBConnection() {}
+void IndexedDBConnection::set_id(int32_t id) {
+ DCHECK_EQ(id_, kInvalidId);
+ id_ = id;
+}
+
void IndexedDBConnection::Close() {
if (!callbacks_.get())
return;
@@ -21,6 +29,7 @@ void IndexedDBConnection::Close() {
if (this_obj) {
database_ = nullptr;
callbacks_ = nullptr;
+ active_observers_.clear();
}
}
@@ -35,6 +44,7 @@ void IndexedDBConnection::ForceClose() {
if (this_obj) {
database_ = nullptr;
callbacks_ = nullptr;
+ active_observers_.clear();
}
callbacks->OnForcedClose();
}
@@ -49,4 +59,31 @@ bool IndexedDBConnection::IsConnected() {
return database_.get() != NULL;
}
+// The observers begin listening to changes only once they are activated.
+void IndexedDBConnection::ActivatePendingObservers(
+ std::vector<std::unique_ptr<IndexedDBObserver>> pending_observers) {
+ for (auto& observer : pending_observers) {
+ active_observers_.push_back(std::move(observer));
+ }
+ pending_observers.clear();
+}
+
+void IndexedDBConnection::RemoveObservers(
+ const std::vector<int32_t>& observer_ids_to_remove) {
+ std::vector<int32_t> pending_observer_ids;
+ for (int32_t id_to_remove : observer_ids_to_remove) {
+ const auto& it = std::find_if(
+ active_observers_.begin(), active_observers_.end(),
+ [&id_to_remove](const std::unique_ptr<IndexedDBObserver>& o) {
+ return o->id() == id_to_remove;
+ });
+ if (it != active_observers_.end())
+ active_observers_.erase(it);
+ else
+ pending_observer_ids.push_back(id_to_remove);
+ }
+ if (!pending_observer_ids.empty())
+ database_->RemovePendingObservers(this, pending_observer_ids);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698