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

Unified Diff: content/public/renderer/platform_event_observer.h

Issue 613203002: Have PlatformEventObserver implementations orderly stop on destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up a comment. Created 6 years, 3 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
« no previous file with comments | « no previous file | content/renderer/battery_status/battery_status_dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/renderer/platform_event_observer.h
diff --git a/content/public/renderer/platform_event_observer.h b/content/public/renderer/platform_event_observer.h
index a67cbec1a060e50220585be2cef13d9fae78552b..e14263ecbd2a6df9f13e6c5a8edc6bbc482f87d1 100644
--- a/content/public/renderer/platform_event_observer.h
+++ b/content/public/renderer/platform_event_observer.h
@@ -60,11 +60,13 @@ class PlatformEventObserver : public PlatformEventObserverBase,
thread->AddObserver(this);
}
- // The observer will automatically stop observing when destroyed in case it
- // did not stop before.
+ // The observer must automatically stop observing when destroyed in case it
+ // did not stop before. Implementations of PlatformEventObserver must do
+ // so by calling StopIfObserving() from their destructors.
virtual ~PlatformEventObserver() {
- if (is_observing())
- Stop();
+ // If this assert fails, the derived destructor failed to invoke
+ // StopIfObserving().
+ DCHECK(!is_observing());
}
// Called when a new IPC message is received. Must be used to listen to the
@@ -105,6 +107,15 @@ class PlatformEventObserver : public PlatformEventObserverBase,
// It is expected for subclasses to override it.
virtual void SendStopMessage() = 0;
+ // Implementations of PlatformEventObserver must call StopIfObserving()
+ // from their destructor to shutdown in an orderly manner.
+ // (As Stop() calls a virtual method, it cannot be handled by
+ // ~PlatformEventObserver.)
+ void StopIfObserving() {
+ if (is_observing())
+ Stop();
+ }
+
bool is_observing() const {
return is_observing_;
}
« no previous file with comments | « no previous file | content/renderer/battery_status/battery_status_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698