Make MessageHandler ctor explicitly require 'false'.

This is the next step towards making MessageHandler a pure virtual
interface. All dependencies that require automatic cleanup
should be depending on the MessageHandlerAutoCleanup class.

Next step will be to remove the ctor from MessageHandler and make
it a pure virtual interface.

Bug: webrtc:11908
Change-Id: I9321b6d9e57c167868f8b896a5345fbfe19af0e9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/183984
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32090}
diff --git a/rtc_base/message_handler.cc b/rtc_base/message_handler.cc
index 42b4c50..bccbc25 100644
--- a/rtc_base/message_handler.cc
+++ b/rtc_base/message_handler.cc
@@ -14,19 +14,24 @@
 
 namespace rtc {
 
-MessageHandler::~MessageHandler() {
-  if (auto_cleanup_) {
-    // Note that even though this clears currently pending messages for the
-    // message handler, it's still racy since it doesn't prevent threads that
-    // might be in the process of posting new messages with would-be dangling
-    // pointers.
-    // This is related to the design of Message having a raw pointer.
-    // We could consider whether it would be safer to require message handlers
-    // to be reference counted (as some are).
-    ThreadManager::Clear(this);
-  }
+MessageHandler::MessageHandler(bool auto_cleanup) {
+  RTC_DCHECK(!auto_cleanup) << "Use MessageHandlerAutoCleanup";
 }
 
-MessageHandlerAutoCleanup::~MessageHandlerAutoCleanup() {}
+MessageHandler::~MessageHandler() {}
+
+MessageHandlerAutoCleanup::MessageHandlerAutoCleanup()
+    : MessageHandler(false) {}
+
+MessageHandlerAutoCleanup::~MessageHandlerAutoCleanup() {
+  // Note that even though this clears currently pending messages for the
+  // message handler, it's still racy since it doesn't prevent threads that
+  // might be in the process of posting new messages with would-be dangling
+  // pointers.
+  // This is related to the design of Message having a raw pointer.
+  // We could consider whether it would be safer to require message handlers
+  // to be reference counted (as some are).
+  ThreadManager::Clear(this);
+}
 
 }  // namespace rtc
diff --git a/rtc_base/message_handler.h b/rtc_base/message_handler.h
index 7b6e682..9568bc8 100644
--- a/rtc_base/message_handler.h
+++ b/rtc_base/message_handler.h
@@ -37,14 +37,11 @@
   virtual void OnMessage(Message* msg) = 0;
 
  protected:
-  // TODO(bugs.webrtc.org/11908): The |auto_cleanup| parameter needs to have a
-  // backwards compatible default value while external code is being updated.
-  explicit MessageHandler(bool auto_cleanup = true)
-      : auto_cleanup_(auto_cleanup) {}
+  // TODO(bugs.webrtc.org/11908): Remove this ctor.
+  explicit MessageHandler(bool auto_cleanup);
 
  private:
   RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandler);
-  const bool auto_cleanup_;
 };
 
 class RTC_EXPORT MessageHandlerAutoCleanup : public MessageHandler {
@@ -52,7 +49,7 @@
   ~MessageHandlerAutoCleanup() override;
 
  protected:
-  MessageHandlerAutoCleanup() : MessageHandler(true) {}
+  MessageHandlerAutoCleanup();
 
  private:
   RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandlerAutoCleanup);