diff --git a/rtc_base/message_handler.cc b/rtc_base/message_handler.cc index 42b4c50b8a..bccbc25bae 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 7b6e682e29..9568bc847b 100644 --- a/rtc_base/message_handler.h +++ b/rtc_base/message_handler.h @@ -37,14 +37,11 @@ class RTC_EXPORT MessageHandler { 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 @@ class RTC_EXPORT MessageHandlerAutoCleanup : public MessageHandler { ~MessageHandlerAutoCleanup() override; protected: - MessageHandlerAutoCleanup() : MessageHandler(true) {} + MessageHandlerAutoCleanup(); private: RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandlerAutoCleanup);