Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / renderer / platform_event_observer.h
index a67cbec..6d56922 100644 (file)
@@ -60,16 +60,18 @@ 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
   // responses from the browser process if any expected.
-  virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE {
+  virtual bool OnControlMessageReceived(const IPC::Message& msg) override {
     return false;
   }
 
@@ -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_;
   }