Chromium Code Reviews| 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..6780348ca90f23ca8652b8c2b4b8f6111c6a7e43 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()); |
|
Mike West
2014/09/30 11:54:14
This is a good change.
|
| } |
| // 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 . |
|
Mike West
2014/09/30 11:55:32
Nit: Kill the space before the '.'.
|
| + // (As Stop() calls a virtual method, it cannot be done handled by |
|
Mike West
2014/09/30 11:55:32
Nit: s/done //
sof
2014/09/30 12:03:40
Thanks for catching that, tidied. My comment proof
|
| + // ~PlatformEventObserver.) |
| + void StopIfObserving() { |
| + if (is_observing()) |
| + Stop(); |
| + } |
| + |
| bool is_observing() const { |
| return is_observing_; |
| } |