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

Unified Diff: chrome/browser/lifetime/keep_alive_registry.cc

Issue 1803143002: Replace BrowserProces::AddRefModule/RemoveModule by ScopedKeepAlive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 9 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: chrome/browser/lifetime/keep_alive_registry.cc
diff --git a/chrome/browser/lifetime/keep_alive_registry.cc b/chrome/browser/lifetime/keep_alive_registry.cc
index e98006163fa60231d934be3a3c624f78dbe4fff7..31160b8041f02f90dd662d0fc24b51a5cd57b39a 100644
--- a/chrome/browser/lifetime/keep_alive_registry.cc
+++ b/chrome/browser/lifetime/keep_alive_registry.cc
@@ -25,6 +25,10 @@ bool KeepAliveRegistry::IsRestartAllowed() const {
return registered_count_ == restart_allowed_count_;
}
+bool KeepAliveRegistry::IsOriginRegistered(KeepAliveOrigin origin) const {
+ return registered_keep_alives_.find(origin) != registered_keep_alives_.end();
+}
+
void KeepAliveRegistry::AddObserver(KeepAliveStateObserver* observer) {
observers_.AddObserver(observer);
}
@@ -59,7 +63,7 @@ void KeepAliveRegistry::Register(KeepAliveOrigin origin,
bool new_restart_allowed = IsRestartAllowed();
if (new_keeping_alive != old_keeping_alive)
- OnKeepingAliveChanged(new_keeping_alive);
+ OnKeepAliveStateChanged(new_keeping_alive);
if (new_restart_allowed != old_restart_allowed)
OnRestartAllowedChanged(new_restart_allowed);
@@ -90,25 +94,16 @@ void KeepAliveRegistry::Unregister(KeepAliveOrigin origin,
OnRestartAllowedChanged(new_restart_allowed);
if (new_keeping_alive != old_keeping_alive)
- OnKeepingAliveChanged(new_keeping_alive);
+ OnKeepAliveStateChanged(new_keeping_alive);
DVLOG(1) << "New state of the KeepAliveRegistry: " << *this;
}
-void KeepAliveRegistry::OnKeepingAliveChanged(bool new_keeping_alive) {
- // Although we should have a browser process, if there is none,
- // there is nothing to do.
- if (!g_browser_process)
- return;
-
- if (new_keeping_alive) {
- DVLOG(1) << "KeepAliveRegistry is now keeping the browser alive.";
- g_browser_process->AddRefModule();
- } else {
- DVLOG(1) << "KeepAliveRegistry stopped keeping the browser alive.";
- g_browser_process->ReleaseModule();
- chrome::CloseAllBrowsersIfNeeded();
- }
+void KeepAliveRegistry::OnKeepAliveStateChanged(bool new_keeping_alive) {
+ DVLOG(1) << "Notifying KeepAliveStateObservers: KeepingAlive changed to: "
+ << new_keeping_alive;
+ FOR_EACH_OBSERVER(KeepAliveStateObserver, observers_,
+ OnKeepAliveStateChanged(new_keeping_alive));
}
void KeepAliveRegistry::OnRestartAllowedChanged(bool new_restart_allowed) {
« no previous file with comments | « chrome/browser/lifetime/keep_alive_registry.h ('k') | chrome/browser/lifetime/keep_alive_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698