Reland of Make the default ctor of rtc::Thread, protected
This is a partial re-land. The change doesn't make the default Thread ctor protected anymore but it does mark it as deprecated and updates all use of it in WebRTC.
Original issue's description:
Make the default ctor of rtc::Thread, protected.
The goal is to force use of Thread::Create or Thread::CreateWithSocketServer.
The default constructor constructs a 'default' socket server, which is usually a 'physical' socket server, but not always. Not every instance of Thread actually needs to have network support, so it's better to have this be explicit instead of unknowingly instantiate one.
BUG=none
Review-Url: https://codereview.webrtc.org/2977953002
Cr-Original-Commit-Position: refs/heads/master@{#19031}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: e7251599a37051f07d81cb8333823f550eae5b9c
diff --git a/rtc_base/thread_checker_unittest.cc b/rtc_base/thread_checker_unittest.cc
index 42e1fcc..d8ad830 100644
--- a/rtc_base/thread_checker_unittest.cc
+++ b/rtc_base/thread_checker_unittest.cc
@@ -14,6 +14,7 @@
#include "webrtc/rtc_base/checks.h"
#include "webrtc/rtc_base/constructormagic.h"
+#include "webrtc/rtc_base/nullsocketserver.h"
#include "webrtc/rtc_base/task_queue.h"
#include "webrtc/rtc_base/thread.h"
#include "webrtc/rtc_base/thread_checker.h"
@@ -52,7 +53,7 @@
class CallDoStuffOnThread : public Thread {
public:
explicit CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class)
- : Thread(),
+ : Thread(std::unique_ptr<SocketServer>(new rtc::NullSocketServer())),
thread_checker_class_(thread_checker_class) {
SetName("call_do_stuff_on_thread", nullptr);
}
@@ -75,9 +76,9 @@
class DeleteThreadCheckerClassOnThread : public Thread {
public:
explicit DeleteThreadCheckerClassOnThread(
- ThreadCheckerClass* thread_checker_class)
- : Thread(),
- thread_checker_class_(thread_checker_class) {
+ std::unique_ptr<ThreadCheckerClass> thread_checker_class)
+ : Thread(std::unique_ptr<SocketServer>(new rtc::NullSocketServer())),
+ thread_checker_class_(std::move(thread_checker_class)) {
SetName("delete_thread_checker_class_on_thread", nullptr);
}
@@ -89,6 +90,8 @@
Thread::Join();
}
+ bool has_been_deleted() const { return !thread_checker_class_; }
+
private:
std::unique_ptr<ThreadCheckerClass> thread_checker_class_;
@@ -115,10 +118,14 @@
// Verify that the destructor doesn't assert
// when called on a different thread.
DeleteThreadCheckerClassOnThread delete_on_thread(
- thread_checker_class.release());
+ std::move(thread_checker_class));
+
+ EXPECT_FALSE(delete_on_thread.has_been_deleted());
delete_on_thread.Start();
delete_on_thread.Join();
+
+ EXPECT_TRUE(delete_on_thread.has_been_deleted());
}
TEST(ThreadCheckerTest, DetachFromThread) {