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}
This commit is contained in:
Tomas Gunnarsson 2020-09-11 23:48:54 +02:00 committed by Commit Bot
parent 5c8aa5cd05
commit 123594114f
2 changed files with 20 additions and 18 deletions

View File

@ -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

View File

@ -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);