Move ThreadWrapper to ProcessThread in base.

Also removes all virtual methods. Permits using a thread from
rtc_base_approved (namely event tracing).

BUG=webrtc:5158
R=tommi@webrtc.org

Review URL: https://codereview.webrtc.org/1469013002

Cr-Commit-Position: refs/heads/master@{#10760}
diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn
index 540058b..956cb18 100644
--- a/webrtc/base/BUILD.gn
+++ b/webrtc/base/BUILD.gn
@@ -124,6 +124,7 @@
     "platform_file.h",
     "platform_thread.cc",
     "platform_thread.h",
+    "platform_thread_types.h",
     "safe_conversions.h",
     "safe_conversions_impl.h",
     "scoped_ptr.h",
diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp
index c15c1db..59f9637 100644
--- a/webrtc/base/base.gyp
+++ b/webrtc/base/base.gyp
@@ -62,6 +62,7 @@
         'platform_file.h',
         'platform_thread.cc',
         'platform_thread.h',
+        'platform_thread_types.h',
         'ratetracker.cc',
         'ratetracker.h',
         'safe_conversions.h',
diff --git a/webrtc/base/base_tests.gyp b/webrtc/base/base_tests.gyp
index a6dd3d1..23b1f9a 100644
--- a/webrtc/base/base_tests.gyp
+++ b/webrtc/base/base_tests.gyp
@@ -80,6 +80,7 @@
           'optional_unittest.cc',
           'optionsfile_unittest.cc',
           'pathutils_unittest.cc',
+          'platform_thread_unittest.cc',
           'profiler_unittest.cc',
           'proxy_unittest.cc',
           'proxydetect_unittest.cc',
diff --git a/webrtc/base/platform_thread.cc b/webrtc/base/platform_thread.cc
index 4167392..d32311b 100644
--- a/webrtc/base/platform_thread.cc
+++ b/webrtc/base/platform_thread.cc
@@ -10,8 +10,6 @@
 
 #include "webrtc/base/platform_thread.h"
 
-#include <string.h>
-
 #include "webrtc/base/checks.h"
 
 #if defined(WEBRTC_LINUX)
@@ -58,7 +56,6 @@
 }
 
 void SetCurrentThreadName(const char* name) {
-  RTC_DCHECK(strlen(name) < 64);
 #if defined(WEBRTC_WIN)
   struct {
     DWORD dwType;
@@ -80,3 +77,189 @@
 }
 
 }  // namespace rtc
+
+namespace webrtc {
+
+rtc::scoped_ptr<PlatformThread> PlatformThread::CreateThread(
+    ThreadRunFunction func,
+    void* obj,
+    const char* thread_name) {
+  return rtc::scoped_ptr<PlatformThread>(
+      new PlatformThread(func, obj, thread_name));
+}
+
+namespace {
+#if defined(WEBRTC_WIN)
+void CALLBACK RaiseFlag(ULONG_PTR param) {
+  *reinterpret_cast<bool*>(param) = true;
+}
+#else
+struct ThreadAttributes {
+  ThreadAttributes() { pthread_attr_init(&attr); }
+  ~ThreadAttributes() { pthread_attr_destroy(&attr); }
+  pthread_attr_t* operator&() { return &attr; }
+  pthread_attr_t attr;
+};
+
+int ConvertToSystemPriority(ThreadPriority priority,
+                            int min_prio,
+                            int max_prio) {
+  RTC_DCHECK(max_prio - min_prio > 2);
+  const int top_prio = max_prio - 1;
+  const int low_prio = min_prio + 1;
+
+  switch (priority) {
+    case kLowPriority:
+      return low_prio;
+    case kNormalPriority:
+      // The -1 ensures that the kHighPriority is always greater or equal to
+      // kNormalPriority.
+      return (low_prio + top_prio - 1) / 2;
+    case kHighPriority:
+      return std::max(top_prio - 2, low_prio);
+    case kHighestPriority:
+      return std::max(top_prio - 1, low_prio);
+    case kRealtimePriority:
+      return top_prio;
+  }
+  RTC_DCHECK(false);
+  return low_prio;
+}
+#endif  // defined(WEBRTC_WIN)
+}
+
+PlatformThread::PlatformThread(ThreadRunFunction func,
+                               void* obj,
+                               const char* thread_name)
+    : run_function_(func),
+      obj_(obj),
+      name_(thread_name ? thread_name : "webrtc"),
+#if defined(WEBRTC_WIN)
+      stop_(false),
+      thread_(NULL) {
+#else
+      stop_event_(false, false),
+      thread_(0) {
+#endif  // defined(WEBRTC_WIN)
+  RTC_DCHECK(func);
+  RTC_DCHECK(name_.length() < 64);
+}
+
+PlatformThread::~PlatformThread() {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+#if defined(WEBRTC_WIN)
+  RTC_DCHECK(!thread_);
+#endif  // defined(WEBRTC_WIN)
+}
+
+#if defined(WEBRTC_WIN)
+DWORD WINAPI PlatformThread::StartThread(void* param) {
+  static_cast<PlatformThread*>(param)->Run();
+  return 0;
+}
+#else
+void* PlatformThread::StartThread(void* param) {
+  static_cast<PlatformThread*>(param)->Run();
+  return 0;
+}
+#endif  // defined(WEBRTC_WIN)
+
+bool PlatformThread::Start() {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+  RTC_DCHECK(!thread_) << "Thread already started?";
+#if defined(WEBRTC_WIN)
+  stop_ = false;
+
+  // See bug 2902 for background on STACK_SIZE_PARAM_IS_A_RESERVATION.
+  // Set the reserved stack stack size to 1M, which is the default on Windows
+  // and Linux.
+  DWORD thread_id;
+  thread_ = ::CreateThread(NULL, 1024 * 1024, &StartThread, this,
+                           STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_id);
+  RTC_CHECK(thread_) << "CreateThread failed";
+#else
+  ThreadAttributes attr;
+  // Set the stack stack size to 1M.
+  pthread_attr_setstacksize(&attr, 1024 * 1024);
+  RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
+#endif  // defined(WEBRTC_WIN)
+  return true;
+}
+
+bool PlatformThread::Stop() {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+#if defined(WEBRTC_WIN)
+  if (thread_) {
+    // Set stop_ to |true| on the worker thread.
+    QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_));
+    WaitForSingleObject(thread_, INFINITE);
+    CloseHandle(thread_);
+    thread_ = nullptr;
+  }
+#else
+  if (!thread_)
+    return true;
+
+  stop_event_.Set();
+  RTC_CHECK_EQ(0, pthread_join(thread_, nullptr));
+  thread_ = 0;
+#endif  // defined(WEBRTC_WIN)
+  return true;
+}
+
+void PlatformThread::Run() {
+  if (!name_.empty())
+    rtc::SetCurrentThreadName(name_.c_str());
+  do {
+    // The interface contract of Start/Stop is that for a successfull call to
+    // Start, there should be at least one call to the run function.  So we
+    // call the function before checking |stop_|.
+    if (!run_function_(obj_))
+      break;
+#if defined(WEBRTC_WIN)
+    // Alertable sleep to permit RaiseFlag to run and update |stop_|.
+    SleepEx(0, true);
+  } while (!stop_);
+#else
+  } while (!stop_event_.Wait(0));
+#endif  // defined(WEBRTC_WIN)
+}
+
+bool PlatformThread::SetPriority(ThreadPriority priority) {
+  RTC_DCHECK(thread_checker_.CalledOnValidThread());
+#if defined(WEBRTC_WIN)
+  return thread_ && SetThreadPriority(thread_, priority);
+#else
+  if (!thread_)
+    return false;
+#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
+  // TODO(tommi): Switch to the same mechanism as Chromium uses for
+  // changing thread priorities.
+  return true;
+#else
+#ifdef WEBRTC_THREAD_RR
+  const int policy = SCHED_RR;
+#else
+  const int policy = SCHED_FIFO;
+#endif
+  const int min_prio = sched_get_priority_min(policy);
+  const int max_prio = sched_get_priority_max(policy);
+  if (min_prio == -1 || max_prio == -1) {
+    return false;
+  }
+
+  if (max_prio - min_prio <= 2)
+    return false;
+
+  sched_param param;
+  param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio);
+  if (pthread_setschedparam(thread_, policy, &param) != 0) {
+    return false;
+  }
+
+  return true;
+#endif  // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
+#endif  // defined(WEBRTC_WIN)
+}
+
+}  // namespace webrtc
diff --git a/webrtc/base/platform_thread.h b/webrtc/base/platform_thread.h
index 50033b3..e2d9b33 100644
--- a/webrtc/base/platform_thread.h
+++ b/webrtc/base/platform_thread.h
@@ -11,24 +11,16 @@
 #ifndef WEBRTC_BASE_PLATFORM_THREAD_H_
 #define WEBRTC_BASE_PLATFORM_THREAD_H_
 
-#if defined(WEBRTC_WIN)
-#include <winsock2.h>
-#include <windows.h>
-#elif defined(WEBRTC_POSIX)
-#include <pthread.h>
-#include <unistd.h>
-#endif
+#include <string>
+
+#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/event.h"
+#include "webrtc/base/platform_thread_types.h"
+#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/thread_checker.h"
 
 namespace rtc {
 
-#if defined(WEBRTC_WIN)
-typedef DWORD PlatformThreadId;
-typedef DWORD PlatformThreadRef;
-#elif defined(WEBRTC_POSIX)
-typedef pid_t PlatformThreadId;
-typedef pthread_t PlatformThreadRef;
-#endif
-
 PlatformThreadId CurrentThreadId();
 PlatformThreadRef CurrentThreadRef();
 
@@ -40,4 +32,96 @@
 
 }  // namespace rtc
 
+// TODO(pbos): Merge with namespace rtc.
+namespace webrtc {
+
+// Callback function that the spawned thread will enter once spawned.
+// A return value of false is interpreted as that the function has no
+// more work to do and that the thread can be released.
+typedef bool (*ThreadRunFunction)(void*);
+
+enum ThreadPriority {
+#ifdef WEBRTC_WIN
+  kLowPriority = THREAD_PRIORITY_BELOW_NORMAL,
+  kNormalPriority = THREAD_PRIORITY_NORMAL,
+  kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL,
+  kHighestPriority = THREAD_PRIORITY_HIGHEST,
+  kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL
+#else
+  kLowPriority = 1,
+  kNormalPriority = 2,
+  kHighPriority = 3,
+  kHighestPriority = 4,
+  kRealtimePriority = 5
+#endif
+};
+
+// Represents a simple worker thread.  The implementation must be assumed
+// to be single threaded, meaning that all methods of the class, must be
+// called from the same thread, including instantiation.
+// TODO(tommi): There's no need for this to be a virtual interface since there's
+// only ever a single implementation of it.
+class PlatformThread {
+ public:
+  PlatformThread(ThreadRunFunction func, void* obj, const char* thread_name);
+  virtual ~PlatformThread();
+
+  // Factory method. Constructor disabled.
+  //
+  // func        Pointer to a, by user, specified callback function.
+  // obj         Object associated with the thread. Passed in the callback
+  //             function.
+  // prio        Thread priority. May require root/admin rights.
+  // thread_name  NULL terminated thread name, will be visable in the Windows
+  //             debugger.
+  // TODO(pbos): Move users onto explicit initialization/member ownership
+  // instead of additional heap allocation due to CreateThread.
+  static rtc::scoped_ptr<PlatformThread> CreateThread(ThreadRunFunction func,
+                                                      void* obj,
+                                                      const char* thread_name);
+
+  // Tries to spawns a thread and returns true if that was successful.
+  // Additionally, it tries to set thread priority according to the priority
+  // from when CreateThread was called. However, failure to set priority will
+  // not result in a false return value.
+  // TODO(pbos): Make void not war.
+  bool Start();
+
+  // Stops the spawned thread and waits for it to be reclaimed with a timeout
+  // of two seconds. Will return false if the thread was not reclaimed.
+  // Multiple tries to Stop are allowed (e.g. to wait longer than 2 seconds).
+  // It's ok to call Stop() even if the spawned thread has been reclaimed.
+  // TODO(pbos): Make void not war.
+  bool Stop();
+
+  // Set the priority of the worker thread.  Must be called when thread
+  // is running.
+  bool SetPriority(ThreadPriority priority);
+
+ private:
+  void Run();
+
+  ThreadRunFunction const run_function_;
+  void* const obj_;
+  // TODO(pbos): Make sure call sites use string literals and update to a const
+  // char* instead of a std::string.
+  const std::string name_;
+  rtc::ThreadChecker thread_checker_;
+#if defined(WEBRTC_WIN)
+  static DWORD WINAPI StartThread(void* param);
+
+  bool stop_;
+  HANDLE thread_;
+#else
+  static void* StartThread(void* param);
+
+  rtc::Event stop_event_;
+
+  pthread_t thread_;
+#endif  // defined(WEBRTC_WIN)
+  RTC_DISALLOW_COPY_AND_ASSIGN(PlatformThread);
+};
+
+}  // namespace webrtc
+
 #endif  // WEBRTC_BASE_PLATFORM_THREAD_H_
diff --git a/webrtc/base/platform_thread_types.h b/webrtc/base/platform_thread_types.h
new file mode 100644
index 0000000..546fffd
--- /dev/null
+++ b/webrtc/base/platform_thread_types.h
@@ -0,0 +1,32 @@
+/*
+ *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_
+#define WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_
+
+#if defined(WEBRTC_WIN)
+#include <winsock2.h>
+#include <windows.h>
+#elif defined(WEBRTC_POSIX)
+#include <pthread.h>
+#include <unistd.h>
+#endif
+
+namespace rtc {
+#if defined(WEBRTC_WIN)
+typedef DWORD PlatformThreadId;
+typedef DWORD PlatformThreadRef;
+#elif defined(WEBRTC_POSIX)
+typedef pid_t PlatformThreadId;
+typedef pthread_t PlatformThreadRef;
+#endif
+}  // namespace rtc
+
+#endif  // WEBRTC_BASE_PLATFORM_THREAD_TYPES_H_
diff --git a/webrtc/system_wrappers/source/thread_unittest.cc b/webrtc/base/platform_thread_unittest.cc
similarity index 79%
rename from webrtc/system_wrappers/source/thread_unittest.cc
rename to webrtc/base/platform_thread_unittest.cc
index c8e180b..ffb60b5 100644
--- a/webrtc/system_wrappers/source/thread_unittest.cc
+++ b/webrtc/base/platform_thread_unittest.cc
@@ -8,7 +8,7 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/base/scoped_ptr.h"
@@ -22,9 +22,9 @@
   return true;
 }
 
-TEST(ThreadTest, StartStop) {
-  rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread(
-      &NullRunFunction, nullptr, "ThreadTest");
+TEST(PlatformThreadTest, StartStop) {
+  rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread(
+      &NullRunFunction, nullptr, "PlatformThreadTest");
   ASSERT_TRUE(thread->Start());
   EXPECT_TRUE(thread->Stop());
 }
@@ -37,9 +37,9 @@
   return true;
 }
 
-TEST(ThreadTest, RunFunctionIsCalled) {
+TEST(PlatformThreadTest, RunFunctionIsCalled) {
   bool flag = false;
-  rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread(
+  rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread(
       &SetFlagRunFunction, &flag, "RunFunctionIsCalled");
   ASSERT_TRUE(thread->Start());
 
diff --git a/webrtc/base/thread_checker_impl.cc b/webrtc/base/thread_checker_impl.cc
index ea88308..79be606 100644
--- a/webrtc/base/thread_checker_impl.cc
+++ b/webrtc/base/thread_checker_impl.cc
@@ -12,6 +12,8 @@
 
 #include "webrtc/base/thread_checker_impl.h"
 
+#include "webrtc/base/platform_thread.h"
+
 namespace rtc {
 
 ThreadCheckerImpl::ThreadCheckerImpl() : valid_thread_(CurrentThreadRef()) {
diff --git a/webrtc/base/thread_checker_impl.h b/webrtc/base/thread_checker_impl.h
index 7b39ada..0455835 100644
--- a/webrtc/base/thread_checker_impl.h
+++ b/webrtc/base/thread_checker_impl.h
@@ -14,7 +14,7 @@
 #define WEBRTC_BASE_THREAD_CHECKER_IMPL_H_
 
 #include "webrtc/base/criticalsection.h"
-#include "webrtc/base/platform_thread.h"
+#include "webrtc/base/platform_thread_types.h"
 
 namespace rtc {
 
diff --git a/webrtc/common_video/include/incoming_video_stream.h b/webrtc/common_video/include/incoming_video_stream.h
index cd0d653..93bc1ba 100644
--- a/webrtc/common_video/include/incoming_video_stream.h
+++ b/webrtc/common_video/include/incoming_video_stream.h
@@ -18,7 +18,7 @@
 namespace webrtc {
 class CriticalSectionWrapper;
 class EventTimerWrapper;
-class ThreadWrapper;
+class PlatformThread;
 
 class VideoRenderCallback {
  public:
@@ -77,7 +77,7 @@
   const rtc::scoped_ptr<CriticalSectionWrapper> stream_critsect_;
   const rtc::scoped_ptr<CriticalSectionWrapper> thread_critsect_;
   const rtc::scoped_ptr<CriticalSectionWrapper> buffer_critsect_;
-  rtc::scoped_ptr<ThreadWrapper> incoming_render_thread_
+  rtc::scoped_ptr<PlatformThread> incoming_render_thread_
       GUARDED_BY(thread_critsect_);
   rtc::scoped_ptr<EventTimerWrapper> deliver_buffer_event_;
 
diff --git a/webrtc/common_video/incoming_video_stream.cc b/webrtc/common_video/incoming_video_stream.cc
index a4b25fc..78fc386 100644
--- a/webrtc/common_video/incoming_video_stream.cc
+++ b/webrtc/common_video/incoming_video_stream.cc
@@ -21,11 +21,11 @@
 #include <sys/time.h>
 #endif
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 #include "webrtc/common_video/video_render_frames.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/tick_util.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
@@ -131,7 +131,7 @@
   CriticalSectionScoped csT(thread_critsect_.get());
   assert(incoming_render_thread_ == NULL);
 
-  incoming_render_thread_ = ThreadWrapper::CreateThread(
+  incoming_render_thread_ = PlatformThread::CreateThread(
       IncomingVideoStreamThreadFun, this, "IncomingVideoStreamThread");
   if (!incoming_render_thread_) {
     return -1;
@@ -155,7 +155,7 @@
     return 0;
   }
 
-  ThreadWrapper* thread = NULL;
+  PlatformThread* thread = NULL;
   {
     CriticalSectionScoped cs_thread(thread_critsect_.get());
     if (incoming_render_thread_) {
diff --git a/webrtc/common_video/interface/incoming_video_stream.h b/webrtc/common_video/interface/incoming_video_stream.h
index 886dae5..00519ec 100644
--- a/webrtc/common_video/interface/incoming_video_stream.h
+++ b/webrtc/common_video/interface/incoming_video_stream.h
@@ -20,7 +20,7 @@
 namespace webrtc {
 class CriticalSectionWrapper;
 class EventTimerWrapper;
-class ThreadWrapper;
+class PlatformThread;
 
 class VideoRenderCallback {
  public:
@@ -79,7 +79,7 @@
   const rtc::scoped_ptr<CriticalSectionWrapper> stream_critsect_;
   const rtc::scoped_ptr<CriticalSectionWrapper> thread_critsect_;
   const rtc::scoped_ptr<CriticalSectionWrapper> buffer_critsect_;
-  rtc::scoped_ptr<ThreadWrapper> incoming_render_thread_
+  rtc::scoped_ptr<PlatformThread> incoming_render_thread_
       GUARDED_BY(thread_critsect_);
   rtc::scoped_ptr<EventTimerWrapper> deliver_buffer_event_;
 
diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc
index 06cc432..f14dcf3 100644
--- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc
+++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_unittest_oldapi.cc
@@ -13,6 +13,7 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/base/md5digest.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
@@ -38,7 +39,6 @@
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/testsupport/fileutils.h"
 #include "webrtc/test/testsupport/gtest_disable.h"
 
@@ -457,11 +457,13 @@
 
   AudioCodingModuleMtTestOldApi()
       : AudioCodingModuleTestOldApi(),
-        send_thread_(ThreadWrapper::CreateThread(CbSendThread, this, "send")),
-        insert_packet_thread_(ThreadWrapper::CreateThread(
-            CbInsertPacketThread, this, "insert_packet")),
-        pull_audio_thread_(ThreadWrapper::CreateThread(
-            CbPullAudioThread, this, "pull_audio")),
+        send_thread_(PlatformThread::CreateThread(CbSendThread, this, "send")),
+        insert_packet_thread_(PlatformThread::CreateThread(CbInsertPacketThread,
+                                                           this,
+                                                           "insert_packet")),
+        pull_audio_thread_(PlatformThread::CreateThread(CbPullAudioThread,
+                                                        this,
+                                                        "pull_audio")),
         test_complete_(EventWrapper::Create()),
         send_count_(0),
         insert_packet_count_(0),
@@ -571,9 +573,9 @@
     return true;
   }
 
-  rtc::scoped_ptr<ThreadWrapper> send_thread_;
-  rtc::scoped_ptr<ThreadWrapper> insert_packet_thread_;
-  rtc::scoped_ptr<ThreadWrapper> pull_audio_thread_;
+  rtc::scoped_ptr<PlatformThread> send_thread_;
+  rtc::scoped_ptr<PlatformThread> insert_packet_thread_;
+  rtc::scoped_ptr<PlatformThread> pull_audio_thread_;
   const rtc::scoped_ptr<EventWrapper> test_complete_;
   int send_count_;
   int insert_packet_count_;
@@ -701,11 +703,11 @@
   AcmReRegisterIsacMtTestOldApi()
       : AudioCodingModuleTestOldApi(),
         receive_thread_(
-            ThreadWrapper::CreateThread(CbReceiveThread, this, "receive")),
+            PlatformThread::CreateThread(CbReceiveThread, this, "receive")),
         codec_registration_thread_(
-            ThreadWrapper::CreateThread(CbCodecRegistrationThread,
-                                        this,
-                                        "codec_registration")),
+            PlatformThread::CreateThread(CbCodecRegistrationThread,
+                                         this,
+                                         "codec_registration")),
         test_complete_(EventWrapper::Create()),
         crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
         codec_registered_(false),
@@ -829,8 +831,8 @@
     return true;
   }
 
-  rtc::scoped_ptr<ThreadWrapper> receive_thread_;
-  rtc::scoped_ptr<ThreadWrapper> codec_registration_thread_;
+  rtc::scoped_ptr<PlatformThread> receive_thread_;
+  rtc::scoped_ptr<PlatformThread> codec_registration_thread_;
   const rtc::scoped_ptr<EventWrapper> test_complete_;
   const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
   bool codec_registered_ GUARDED_BY(crit_sect_);
diff --git a/webrtc/modules/audio_coding/main/test/APITest.cc b/webrtc/modules/audio_coding/main/test/APITest.cc
index dec1473..88ad7e2 100644
--- a/webrtc/modules/audio_coding/main/test/APITest.cc
+++ b/webrtc/modules/audio_coding/main/test/APITest.cc
@@ -20,13 +20,13 @@
 #include <string>
 
 #include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common.h"
 #include "webrtc/common_types.h"
 #include "webrtc/engine_configurations.h"
 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
 #include "webrtc/modules/audio_coding/main/test/utility.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/tick_util.h"
 #include "webrtc/system_wrappers/include/trace.h"
 #include "webrtc/test/testsupport/fileutils.h"
@@ -522,37 +522,37 @@
   //--- THREADS
   // A
   // PUSH
-  rtc::scoped_ptr<ThreadWrapper> myPushAudioThreadA =
-      ThreadWrapper::CreateThread(PushAudioThreadA, this, "PushAudioThreadA");
+  rtc::scoped_ptr<PlatformThread> myPushAudioThreadA =
+      PlatformThread::CreateThread(PushAudioThreadA, this, "PushAudioThreadA");
   CHECK_THREAD_NULLITY(myPushAudioThreadA, "Unable to start A::PUSH thread");
   // PULL
-  rtc::scoped_ptr<ThreadWrapper> myPullAudioThreadA =
-      ThreadWrapper::CreateThread(PullAudioThreadA, this, "PullAudioThreadA");
+  rtc::scoped_ptr<PlatformThread> myPullAudioThreadA =
+      PlatformThread::CreateThread(PullAudioThreadA, this, "PullAudioThreadA");
   CHECK_THREAD_NULLITY(myPullAudioThreadA, "Unable to start A::PULL thread");
   // Process
-  rtc::scoped_ptr<ThreadWrapper> myProcessThreadA = ThreadWrapper::CreateThread(
-      ProcessThreadA, this, "ProcessThreadA");
+  rtc::scoped_ptr<PlatformThread> myProcessThreadA =
+      PlatformThread::CreateThread(ProcessThreadA, this, "ProcessThreadA");
   CHECK_THREAD_NULLITY(myProcessThreadA, "Unable to start A::Process thread");
   // API
-  rtc::scoped_ptr<ThreadWrapper> myAPIThreadA = ThreadWrapper::CreateThread(
-      APIThreadA, this, "APIThreadA");
+  rtc::scoped_ptr<PlatformThread> myAPIThreadA =
+      PlatformThread::CreateThread(APIThreadA, this, "APIThreadA");
   CHECK_THREAD_NULLITY(myAPIThreadA, "Unable to start A::API thread");
   // B
   // PUSH
-  rtc::scoped_ptr<ThreadWrapper> myPushAudioThreadB =
-      ThreadWrapper::CreateThread(PushAudioThreadB, this, "PushAudioThreadB");
+  rtc::scoped_ptr<PlatformThread> myPushAudioThreadB =
+      PlatformThread::CreateThread(PushAudioThreadB, this, "PushAudioThreadB");
   CHECK_THREAD_NULLITY(myPushAudioThreadB, "Unable to start B::PUSH thread");
   // PULL
-  rtc::scoped_ptr<ThreadWrapper> myPullAudioThreadB =
-      ThreadWrapper::CreateThread(PullAudioThreadB, this, "PullAudioThreadB");
+  rtc::scoped_ptr<PlatformThread> myPullAudioThreadB =
+      PlatformThread::CreateThread(PullAudioThreadB, this, "PullAudioThreadB");
   CHECK_THREAD_NULLITY(myPullAudioThreadB, "Unable to start B::PULL thread");
   // Process
-  rtc::scoped_ptr<ThreadWrapper> myProcessThreadB = ThreadWrapper::CreateThread(
-      ProcessThreadB, this, "ProcessThreadB");
+  rtc::scoped_ptr<PlatformThread> myProcessThreadB =
+      PlatformThread::CreateThread(ProcessThreadB, this, "ProcessThreadB");
   CHECK_THREAD_NULLITY(myProcessThreadB, "Unable to start B::Process thread");
   // API
-  rtc::scoped_ptr<ThreadWrapper> myAPIThreadB = ThreadWrapper::CreateThread(
-      APIThreadB, this, "APIThreadB");
+  rtc::scoped_ptr<PlatformThread> myAPIThreadB =
+      PlatformThread::CreateThread(APIThreadB, this, "APIThreadB");
   CHECK_THREAD_NULLITY(myAPIThreadB, "Unable to start B::API thread");
 
   //_apiEventA->StartTimer(true, 5000);
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.cc b/webrtc/modules/audio_device/dummy/file_audio_device.cc
index eb3d042..d59eae2 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device.cc
+++ b/webrtc/modules/audio_device/dummy/file_audio_device.cc
@@ -7,9 +7,9 @@
  *  in the file PATENTS.  All contributing project authors may
  *  be found in the AUTHORS file in the root of the source tree.
  */
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/audio_device/dummy/file_audio_device.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 namespace webrtc {
 
@@ -214,8 +214,8 @@
   }
 
   const char* threadName = "webrtc_audio_module_play_thread";
-  _ptrThreadPlay = ThreadWrapper::CreateThread(PlayThreadFunc, this,
-                                               threadName);
+  _ptrThreadPlay =
+      PlatformThread::CreateThread(PlayThreadFunc, this, threadName);
   if (!_ptrThreadPlay->Start()) {
       _ptrThreadPlay.reset();
       _playing = false;
@@ -277,7 +277,7 @@
   }
 
   const char* threadName = "webrtc_audio_module_capture_thread";
-  _ptrThreadRec = ThreadWrapper::CreateThread(RecThreadFunc, this, threadName);
+  _ptrThreadRec = PlatformThread::CreateThread(RecThreadFunc, this, threadName);
 
   if (!_ptrThreadRec->Start()) {
       _ptrThreadRec.reset();
diff --git a/webrtc/modules/audio_device/dummy/file_audio_device.h b/webrtc/modules/audio_device/dummy/file_audio_device.h
index 0e1665e..a8a71ca 100644
--- a/webrtc/modules/audio_device/dummy/file_audio_device.h
+++ b/webrtc/modules/audio_device/dummy/file_audio_device.h
@@ -22,7 +22,7 @@
 
 namespace webrtc {
 class EventWrapper;
-class ThreadWrapper;
+class PlatformThread;
 
 // This is a fake audio device which plays audio from a file as its microphone
 // and plays out into a file.
@@ -178,8 +178,8 @@
   size_t _recordingFramesIn10MS;
   size_t _playoutFramesIn10MS;
 
-  rtc::scoped_ptr<ThreadWrapper> _ptrThreadRec;
-  rtc::scoped_ptr<ThreadWrapper> _ptrThreadPlay;
+  rtc::scoped_ptr<PlatformThread> _ptrThreadRec;
+  rtc::scoped_ptr<PlatformThread> _ptrThreadPlay;
 
   bool _playing;
   bool _recording;
diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
index 8fa4fdf..b8c19a2 100644
--- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
+++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
@@ -207,7 +207,7 @@
     // RECORDING
     if (_ptrThreadRec)
     {
-        ThreadWrapper* tmpThread = _ptrThreadRec.release();
+        PlatformThread* tmpThread = _ptrThreadRec.release();
         _critSect.Leave();
 
         tmpThread->Stop();
@@ -219,7 +219,7 @@
     // PLAYOUT
     if (_ptrThreadPlay)
     {
-        ThreadWrapper* tmpThread = _ptrThreadPlay.release();
+        PlatformThread* tmpThread = _ptrThreadPlay.release();
         _critSect.Leave();
 
         tmpThread->Stop();
@@ -1364,8 +1364,8 @@
     }
     // RECORDING
     const char* threadName = "webrtc_audio_module_capture_thread";
-    _ptrThreadRec = ThreadWrapper::CreateThread(
-        RecThreadFunc, this, threadName);
+    _ptrThreadRec =
+        PlatformThread::CreateThread(RecThreadFunc, this, threadName);
 
     if (!_ptrThreadRec->Start())
     {
@@ -1518,8 +1518,8 @@
 
     // PLAYOUT
     const char* threadName = "webrtc_audio_module_play_thread";
-    _ptrThreadPlay =  ThreadWrapper::CreateThread(PlayThreadFunc, this,
-                                                  threadName);
+    _ptrThreadPlay =
+        PlatformThread::CreateThread(PlayThreadFunc, this, threadName);
     if (!_ptrThreadPlay->Start())
     {
         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id,
diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h
index e2391a0..c61dc86 100644
--- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h
+++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.h
@@ -11,10 +11,10 @@
 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H
 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/audio_device/audio_device_generic.h"
 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 #if defined(USE_X11)
 #include <X11/Xlib.h>
@@ -185,8 +185,8 @@
 
     CriticalSectionWrapper& _critSect;
 
-    rtc::scoped_ptr<ThreadWrapper> _ptrThreadRec;
-    rtc::scoped_ptr<ThreadWrapper> _ptrThreadPlay;
+    rtc::scoped_ptr<PlatformThread> _ptrThreadRec;
+    rtc::scoped_ptr<PlatformThread> _ptrThreadPlay;
 
     int32_t _id;
 
diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc
index 929a758..7970ef7 100644
--- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc
+++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.cc
@@ -201,8 +201,8 @@
 
     // RECORDING
     const char* threadName = "webrtc_audio_module_rec_thread";
-    _ptrThreadRec = ThreadWrapper::CreateThread(RecThreadFunc, this,
-                                                threadName);
+    _ptrThreadRec =
+        PlatformThread::CreateThread(RecThreadFunc, this, threadName);
     if (!_ptrThreadRec->Start())
     {
         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id,
@@ -216,8 +216,8 @@
 
     // PLAYOUT
     threadName = "webrtc_audio_module_play_thread";
-    _ptrThreadPlay = ThreadWrapper::CreateThread(PlayThreadFunc, this,
-                                                 threadName);
+    _ptrThreadPlay =
+        PlatformThread::CreateThread(PlayThreadFunc, this, threadName);
     if (!_ptrThreadPlay->Start())
     {
         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id,
@@ -246,7 +246,7 @@
     // RECORDING
     if (_ptrThreadRec)
     {
-        ThreadWrapper* tmpThread = _ptrThreadRec.release();
+        PlatformThread* tmpThread = _ptrThreadRec.release();
 
         _timeEventRec.Set();
         tmpThread->Stop();
@@ -256,7 +256,7 @@
     // PLAYOUT
     if (_ptrThreadPlay)
     {
-        ThreadWrapper* tmpThread = _ptrThreadPlay.release();
+        PlatformThread* tmpThread = _ptrThreadPlay.release();
 
         _timeEventPlay.Set();
         tmpThread->Stop();
diff --git a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h
index 7183311..263d42d 100644
--- a/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h
+++ b/webrtc/modules/audio_device/linux/audio_device_pulse_linux.h
@@ -11,11 +11,11 @@
 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H
 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_PULSE_LINUX_H
 
+#include "webrtc/base/platform_thread.h"
+#include "webrtc/base/thread_checker.h"
 #include "webrtc/modules/audio_device/audio_device_generic.h"
 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_pulse_linux.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
-#include "webrtc/base/thread_checker.h"
 
 #include <X11/Xlib.h>
 #include <pulse/pulseaudio.h>
@@ -284,8 +284,8 @@
     EventWrapper& _recStartEvent;
     EventWrapper& _playStartEvent;
 
-    rtc::scoped_ptr<ThreadWrapper> _ptrThreadPlay;
-    rtc::scoped_ptr<ThreadWrapper> _ptrThreadRec;
+    rtc::scoped_ptr<PlatformThread> _ptrThreadPlay;
+    rtc::scoped_ptr<PlatformThread> _ptrThreadRec;
     int32_t _id;
 
     AudioMixerManagerLinuxPulse _mixerManager;
diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.cc b/webrtc/modules/audio_device/mac/audio_device_mac.cc
index db98675..14e6bbd 100644
--- a/webrtc/modules/audio_device/mac/audio_device_mac.cc
+++ b/webrtc/modules/audio_device/mac/audio_device_mac.cc
@@ -10,11 +10,11 @@
 
 #include "webrtc/base/arraysize.h"
 #include "webrtc/base/checks.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/audio_device/audio_device_config.h"
 #include "webrtc/modules/audio_device/mac/audio_device_mac.h"
 #include "webrtc/modules/audio_device/mac/portaudio/pa_ringbuffer.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 #include <ApplicationServices/ApplicationServices.h>
@@ -1666,7 +1666,7 @@
 
     RTC_DCHECK(!capture_worker_thread_.get());
     capture_worker_thread_ =
-        ThreadWrapper::CreateThread(RunCapture, this, "CaptureWorkerThread");
+        PlatformThread::CreateThread(RunCapture, this, "CaptureWorkerThread");
     RTC_DCHECK(capture_worker_thread_.get());
     capture_worker_thread_->Start();
     capture_worker_thread_->SetPriority(kRealtimePriority);
@@ -1821,7 +1821,7 @@
 
     RTC_DCHECK(!render_worker_thread_.get());
     render_worker_thread_ =
-        ThreadWrapper::CreateThread(RunRender, this, "RenderWorkerThread");
+        PlatformThread::CreateThread(RunRender, this, "RenderWorkerThread");
     render_worker_thread_->Start();
     render_worker_thread_->SetPriority(kRealtimePriority);
 
diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.h b/webrtc/modules/audio_device/mac/audio_device_mac.h
index f2b66b4..d908fc5 100644
--- a/webrtc/modules/audio_device/mac/audio_device_mac.h
+++ b/webrtc/modules/audio_device/mac/audio_device_mac.h
@@ -26,7 +26,7 @@
 namespace webrtc
 {
 class EventWrapper;
-class ThreadWrapper;
+class PlatformThread;
 
 const uint32_t N_REC_SAMPLES_PER_SEC = 48000;
 const uint32_t N_PLAY_SAMPLES_PER_SEC = 48000;
@@ -283,10 +283,10 @@
     EventWrapper& _stopEvent;
 
     // Only valid/running between calls to StartRecording and StopRecording.
-    rtc::scoped_ptr<ThreadWrapper> capture_worker_thread_;
+    rtc::scoped_ptr<PlatformThread> capture_worker_thread_;
 
     // Only valid/running between calls to StartPlayout and StopPlayout.
-    rtc::scoped_ptr<ThreadWrapper> render_worker_thread_;
+    rtc::scoped_ptr<PlatformThread> render_worker_thread_;
 
     int32_t _id;
 
diff --git a/webrtc/modules/audio_device/test/func_test_manager.cc b/webrtc/modules/audio_device/test/func_test_manager.cc
index 0ebfc83..241c072 100644
--- a/webrtc/modules/audio_device/test/func_test_manager.cc
+++ b/webrtc/modules/audio_device/test/func_test_manager.cc
@@ -686,7 +686,7 @@
         _audioDevice = NULL;
     }
 
-    // return the ThreadWrapper (singleton)
+    // return the PlatformThread (singleton)
     Trace::ReturnTrace();
 
     // PRINT_TEST_RESULTS;
diff --git a/webrtc/modules/audio_device/win/audio_device_wave_win.cc b/webrtc/modules/audio_device/win/audio_device_wave_win.cc
index 96bee74..dec5401 100644
--- a/webrtc/modules/audio_device/win/audio_device_wave_win.cc
+++ b/webrtc/modules/audio_device/win/audio_device_wave_win.cc
@@ -228,7 +228,7 @@
     }
 
     const char* threadName = "webrtc_audio_module_thread";
-    _ptrThread = ThreadWrapper::CreateThread(ThreadFunc, this, threadName);
+    _ptrThread = PlatformThread::CreateThread(ThreadFunc, this, threadName);
     if (!_ptrThread->Start())
     {
         WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id,
@@ -250,12 +250,8 @@
     WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
                  "periodic timer (dT=%d) is now active", TIMER_PERIOD_MS);
 
-    _hGetCaptureVolumeThread = CreateThread(NULL,
-                                            0,
-                                            GetCaptureVolumeThread,
-                                            this,
-                                            0,
-                                            NULL);
+    _hGetCaptureVolumeThread =
+        CreateThread(NULL, 0, GetCaptureVolumeThread, this, 0, NULL);
     if (_hGetCaptureVolumeThread == NULL)
     {
         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
@@ -265,12 +261,8 @@
 
     SetThreadPriority(_hGetCaptureVolumeThread, THREAD_PRIORITY_NORMAL);
 
-    _hSetCaptureVolumeThread = CreateThread(NULL,
-                                            0,
-                                            SetCaptureVolumeThread,
-                                            this,
-                                            0,
-                                            NULL);
+    _hSetCaptureVolumeThread =
+        CreateThread(NULL, 0, SetCaptureVolumeThread, this, 0, NULL);
     if (_hSetCaptureVolumeThread == NULL)
     {
         WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
@@ -303,7 +295,7 @@
 
     if (_ptrThread)
     {
-        ThreadWrapper* tmpThread = _ptrThread.release();
+        PlatformThread* tmpThread = _ptrThread.release();
         _critSect.Leave();
 
         _timeEvent.Set();
diff --git a/webrtc/modules/audio_device/win/audio_device_wave_win.h b/webrtc/modules/audio_device/win/audio_device_wave_win.h
index c99185c..6e29014 100644
--- a/webrtc/modules/audio_device/win/audio_device_wave_win.h
+++ b/webrtc/modules/audio_device/win/audio_device_wave_win.h
@@ -11,9 +11,9 @@
 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H
 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_WAVE_WIN_H
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/audio_device/audio_device_generic.h"
 #include "webrtc/modules/audio_device/win/audio_mixer_manager_win.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 #pragma comment( lib, "winmm.lib" )
 
@@ -222,7 +222,7 @@
     HANDLE                                  _hShutdownSetVolumeEvent;
     HANDLE                                  _hSetCaptureVolumeEvent;
 
-    rtc::scoped_ptr<ThreadWrapper>          _ptrThread;
+    rtc::scoped_ptr<PlatformThread>          _ptrThread;
 
     CriticalSectionWrapper&                 _critSectCb;
 
diff --git a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc
index d1dabee..bccccf4 100644
--- a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc
+++ b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc
@@ -16,12 +16,12 @@
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/base/array_view.h"
 #include "webrtc/base/criticalsection.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/config.h"
 #include "webrtc/modules/audio_processing/test/test_utils.h"
 #include "webrtc/modules/include/module_common_types.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/random.h"
 
 namespace webrtc {
@@ -456,9 +456,9 @@
   const rtc::scoped_ptr<EventWrapper> test_complete_;
 
   // Thread related variables.
-  rtc::scoped_ptr<ThreadWrapper> render_thread_;
-  rtc::scoped_ptr<ThreadWrapper> capture_thread_;
-  rtc::scoped_ptr<ThreadWrapper> stats_thread_;
+  rtc::scoped_ptr<PlatformThread> render_thread_;
+  rtc::scoped_ptr<PlatformThread> capture_thread_;
+  rtc::scoped_ptr<PlatformThread> stats_thread_;
   mutable test::Random rand_gen_;
 
   rtc::scoped_ptr<AudioProcessing> apm_;
@@ -472,14 +472,15 @@
 
 AudioProcessingImplLockTest::AudioProcessingImplLockTest()
     : test_complete_(EventWrapper::Create()),
-      render_thread_(ThreadWrapper::CreateThread(RenderProcessorThreadFunc,
-                                                 this,
-                                                 "render")),
-      capture_thread_(ThreadWrapper::CreateThread(CaptureProcessorThreadFunc,
+      render_thread_(PlatformThread::CreateThread(RenderProcessorThreadFunc,
                                                   this,
-                                                  "capture")),
-      stats_thread_(
-          ThreadWrapper::CreateThread(StatsProcessorThreadFunc, this, "stats")),
+                                                  "render")),
+      capture_thread_(PlatformThread::CreateThread(CaptureProcessorThreadFunc,
+                                                   this,
+                                                   "capture")),
+      stats_thread_(PlatformThread::CreateThread(StatsProcessorThreadFunc,
+                                                 this,
+                                                 "stats")),
       rand_gen_(42U),
       apm_(AudioProcessingImpl::Create()),
       render_thread_state_(kMaxFrameSize,
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc
index fe54d67..72f75f3 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc
@@ -895,8 +895,8 @@
 {
     _eventPtr = EventWrapper::Create();
 
-    _plotThread = ThreadWrapper::CreateThread(MatlabEngine::PlotThread, this,
-                                              kLowPriority, "MatlabPlot");
+    _plotThread = PlatformThread::CreateThread(MatlabEngine::PlotThread, this,
+                                               kLowPriority, "MatlabPlot");
     _running = true;
     _plotThread->Start();
 }
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h
index 3ed89f8..549e5cc 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h
@@ -15,8 +15,8 @@
 #include <string>
 #include <vector>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/typedefs.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 namespace webrtc {
 class CriticalSectionWrapper;
@@ -160,7 +160,7 @@
     std::vector<MatlabPlot *> _plots;
     webrtc::CriticalSectionWrapper *_critSect;
     webrtc::EventWrapper *_eventPtr;
-    rtc::scoped_ptr<webrtc::ThreadWrapper> _plotThread;
+    rtc::scoped_ptr<webrtc::PlatformThread> _plotThread;
     bool _running;
     int _numPlots;
 };
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
index 0e3e879..236ceae 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc
@@ -76,8 +76,8 @@
 
     _eventPtr = EventWrapper::Create();
 
-    _genThread = ThreadWrapper::CreateThread(SenderThreadFunction, this,
-                                             threadName);
+    _genThread =
+        PlatformThread::CreateThread(SenderThreadFunction, this, threadName);
     _running = true;
 
     _genThread->Start();
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
index 59742b2..23f61b2 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h
@@ -13,8 +13,8 @@
 
 #include <stdlib.h>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/include/module_common_types.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/typedefs.h"
 
 class TestSenderReceiver;
@@ -44,7 +44,7 @@
 
     webrtc::CriticalSectionWrapper* _critSect;
     webrtc::EventWrapper *_eventPtr;
-    rtc::scoped_ptr<webrtc::ThreadWrapper> _genThread;
+    rtc::scoped_ptr<webrtc::PlatformThread> _genThread;
     int32_t _bitrateKbps;
     TestSenderReceiver *_sender;
     bool _running;
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
index c1d91cd..99a41ee 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc
@@ -162,8 +162,8 @@
         exit(1);
     }
 
-    _procThread = ThreadWrapper::CreateThread(ProcThreadFunction, this,
-                                              "TestSenderReceiver");
+    _procThread = PlatformThread::CreateThread(ProcThreadFunction, this,
+                                               "TestSenderReceiver");
 
     _running = true;
 
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
index 02fbe0a..77b02d0 100644
--- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
+++ b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h
@@ -11,9 +11,9 @@
 #ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_
 #define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/channel_transport/udp_transport.h"
 #include "webrtc/typedefs.h"
 
@@ -138,7 +138,7 @@
     UdpTransport* _transport;
     webrtc::CriticalSectionWrapper* _critSect;
     webrtc::EventWrapper *_eventPtr;
-    rtc::scoped_ptr<webrtc::ThreadWrapper> _procThread;
+    rtc::scoped_ptr<webrtc::PlatformThread> _procThread;
     bool _running;
     int8_t _payloadType;
     TestLoadGenerator* _loadGenerator;
diff --git a/webrtc/modules/utility/source/file_recorder_impl.h b/webrtc/modules/utility/source/file_recorder_impl.h
index e3f06c4..697d759 100644
--- a/webrtc/modules/utility/source/file_recorder_impl.h
+++ b/webrtc/modules/utility/source/file_recorder_impl.h
@@ -17,6 +17,7 @@
 
 #include <list>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common_audio/resampler/include/resampler.h"
 #include "webrtc/common_types.h"
 #include "webrtc/engine_configurations.h"
@@ -26,7 +27,6 @@
 #include "webrtc/modules/utility/include/file_recorder.h"
 #include "webrtc/modules/utility/source/coder.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/tick_util.h"
 #include "webrtc/typedefs.h"
 
diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc
index 9c739de..63e77d9 100644
--- a/webrtc/modules/utility/source/process_thread_impl.cc
+++ b/webrtc/modules/utility/source/process_thread_impl.cc
@@ -76,8 +76,8 @@
       m.module->ProcessThreadAttached(this);
   }
 
-  thread_ = ThreadWrapper::CreateThread(&ProcessThreadImpl::Run, this,
-                                        thread_name_);
+  thread_ =
+      PlatformThread::CreateThread(&ProcessThreadImpl::Run, this, thread_name_);
   RTC_CHECK(thread_->Start());
 }
 
diff --git a/webrtc/modules/utility/source/process_thread_impl.h b/webrtc/modules/utility/source/process_thread_impl.h
index 0a95665..8f58932 100644
--- a/webrtc/modules/utility/source/process_thread_impl.h
+++ b/webrtc/modules/utility/source/process_thread_impl.h
@@ -15,10 +15,10 @@
 #include <queue>
 
 #include "webrtc/base/criticalsection.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/thread_checker.h"
 #include "webrtc/modules/utility/include/process_thread.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -70,7 +70,7 @@
 
   rtc::ThreadChecker thread_checker_;
   const rtc::scoped_ptr<EventWrapper> wake_up_;
-  rtc::scoped_ptr<ThreadWrapper> thread_;
+  rtc::scoped_ptr<PlatformThread> thread_;
 
   ModuleList modules_;
   // TODO(tommi): Support delayed tasks.
diff --git a/webrtc/modules/video_capture/linux/video_capture_linux.cc b/webrtc/modules/video_capture/linux/video_capture_linux.cc
index fe99c71..b8e3f62 100644
--- a/webrtc/modules/video_capture/linux/video_capture_linux.cc
+++ b/webrtc/modules/video_capture/linux/video_capture_linux.cc
@@ -280,7 +280,7 @@
     //start capture thread;
     if (!_captureThread)
     {
-        _captureThread = ThreadWrapper::CreateThread(
+        _captureThread = PlatformThread::CreateThread(
             VideoCaptureModuleV4L2::CaptureThread, this, "CaptureThread");
         _captureThread->Start();
         _captureThread->SetPriority(kHighPriority);
diff --git a/webrtc/modules/video_capture/linux/video_capture_linux.h b/webrtc/modules/video_capture/linux/video_capture_linux.h
index 996f8e1..f791607 100644
--- a/webrtc/modules/video_capture/linux/video_capture_linux.h
+++ b/webrtc/modules/video_capture/linux/video_capture_linux.h
@@ -11,9 +11,9 @@
 #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_
 #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_LINUX_VIDEO_CAPTURE_LINUX_H_
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/video_capture/video_capture_impl.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 namespace webrtc
 {
@@ -39,7 +39,7 @@
     bool AllocateVideoBuffers();
     bool DeAllocateVideoBuffers();
 
-    rtc::scoped_ptr<ThreadWrapper> _captureThread;
+    rtc::scoped_ptr<PlatformThread> _captureThread;
     CriticalSectionWrapper* _captureCritSect;
 
     int32_t _deviceId;
diff --git a/webrtc/modules/video_render/android/video_render_android_impl.cc b/webrtc/modules/video_render/android/video_render_android_impl.cc
index c647501..63386e0 100644
--- a/webrtc/modules/video_render/android/video_render_android_impl.cc
+++ b/webrtc/modules/video_render/android/video_render_android_impl.cc
@@ -141,8 +141,8 @@
     return 0;
   }
 
-  _javaRenderThread = ThreadWrapper::CreateThread(JavaRenderThreadFun, this,
-                                                  "AndroidRenderThread");
+  _javaRenderThread = PlatformThread::CreateThread(JavaRenderThreadFun, this,
+                                                   "AndroidRenderThread");
 
   if (_javaRenderThread->Start())
     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id,
diff --git a/webrtc/modules/video_render/android/video_render_android_impl.h b/webrtc/modules/video_render/android/video_render_android_impl.h
index 34950db..c038980 100644
--- a/webrtc/modules/video_render/android/video_render_android_impl.h
+++ b/webrtc/modules/video_render/android/video_render_android_impl.h
@@ -15,8 +15,8 @@
 
 #include <map>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/video_render/i_video_render.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 
 namespace webrtc {
@@ -144,7 +144,7 @@
   EventWrapper& _javaRenderEvent;
   int64_t _lastJavaRenderEvent;
   JNIEnv* _javaRenderJniEnv; // JNIEnv for the java render thread.
-  rtc::scoped_ptr<ThreadWrapper> _javaRenderThread;
+  rtc::scoped_ptr<PlatformThread> _javaRenderThread;
 };
 
 }  // namespace webrtc
diff --git a/webrtc/modules/video_render/ios/video_render_ios_gles20.h b/webrtc/modules/video_render/ios/video_render_ios_gles20.h
index b6da12a..51a0137 100644
--- a/webrtc/modules/video_render/ios/video_render_ios_gles20.h
+++ b/webrtc/modules/video_render/ios/video_render_ios_gles20.h
@@ -14,10 +14,10 @@
 #include <list>
 #include <map>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/modules/video_render/ios/video_render_ios_channel.h"
 #include "webrtc/modules/video_render/ios/video_render_ios_view.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 namespace webrtc {
 
@@ -64,7 +64,7 @@
  private:
   rtc::scoped_ptr<CriticalSectionWrapper> gles_crit_sec_;
   EventTimerWrapper* screen_update_event_;
-  rtc::scoped_ptr<ThreadWrapper> screen_update_thread_;
+  rtc::scoped_ptr<PlatformThread> screen_update_thread_;
 
   VideoRenderIosView* view_;
   Rect window_rect_;
diff --git a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm
index 3a276d6..0b4cac1 100644
--- a/webrtc/modules/video_render/ios/video_render_ios_gles20.mm
+++ b/webrtc/modules/video_render/ios/video_render_ios_gles20.mm
@@ -32,7 +32,7 @@
       z_order_to_channel_(),
       gles_context_([view context]),
       is_rendering_(true) {
-  screen_update_thread_ = ThreadWrapper::CreateThread(
+  screen_update_thread_ = PlatformThread::CreateThread(
       ScreenUpdateThreadProc, this, "ScreenUpdateGles20");
   screen_update_event_ = EventTimerWrapper::Create();
   GetWindowRect(window_rect_);
@@ -40,7 +40,7 @@
 
 VideoRenderIosGles20::~VideoRenderIosGles20() {
   // Signal event to exit thread, then delete it
-  ThreadWrapper* thread_wrapper = screen_update_thread_.release();
+  PlatformThread* thread_wrapper = screen_update_thread_.release();
 
   if (thread_wrapper) {
     screen_update_event_->Set();
diff --git a/webrtc/modules/video_render/mac/video_render_agl.cc b/webrtc/modules/video_render/mac/video_render_agl.cc
index dc157d5..32fa607 100644
--- a/webrtc/modules/video_render/mac/video_render_agl.cc
+++ b/webrtc/modules/video_render/mac/video_render_agl.cc
@@ -395,8 +395,8 @@
 {
     //WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s");
 
-    _screenUpdateThread = ThreadWrapper::CreateThread(
-        ScreenUpdateThreadProc, this, "ScreenUpdate");
+    _screenUpdateThread = PlatformThread::CreateThread(ScreenUpdateThreadProc,
+                                                       this, "ScreenUpdate");
     _screenUpdateEvent = EventWrapper::Create();
 
     if(!IsValidWindowPtr(_windowRef))
@@ -512,7 +512,7 @@
     //WEBRTC_TRACE(kTraceDebug, "%s:%d Constructor", __FUNCTION__, __LINE__);
     //    _renderCritSec = CriticalSectionWrapper::CreateCriticalSection();
 
-    _screenUpdateThread = ThreadWrapper::CreateThread(
+    _screenUpdateThread = PlatformThread::CreateThread(
         ScreenUpdateThreadProc, this, "ScreenUpdateThread");
     _screenUpdateEvent = EventWrapper::Create();
 
@@ -677,7 +677,7 @@
 #endif
 
     // Signal event to exit thread, then delete it
-    ThreadWrapper* tmpPtr = _screenUpdateThread.release();
+    PlatformThread* tmpPtr = _screenUpdateThread.release();
 
     if (tmpPtr)
     {
@@ -856,7 +856,7 @@
 int VideoRenderAGL::StopThread()
 {
     CriticalSectionScoped cs(&_renderCritSec);
-    ThreadWrapper* tmpPtr = _screenUpdateThread.release();
+    PlatformThread* tmpPtr = _screenUpdateThread.release();
 
     if (tmpPtr)
     {
@@ -1891,8 +1891,8 @@
         return 0;
     }
 
-    _screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc,
-        this, "ScreenUpdate");
+    _screenUpdateThread = PlatformThread::CreateThread(ScreenUpdateThreadProc,
+                                                       this, "ScreenUpdate");
     _screenUpdateEvent = EventWrapper::Create();
 
     if (!_screenUpdateThread)
diff --git a/webrtc/modules/video_render/mac/video_render_agl.h b/webrtc/modules/video_render/mac/video_render_agl.h
index 11e9c3b..0508a3f 100644
--- a/webrtc/modules/video_render/mac/video_render_agl.h
+++ b/webrtc/modules/video_render/mac/video_render_agl.h
@@ -15,8 +15,8 @@
 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_
 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_MAC_VIDEO_RENDER_AGL_H_
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/video_render/video_render_defines.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 #define NEW_HIVIEW_PARENT_EVENT_HANDLER 1
 #define NEW_HIVIEW_EVENT_HANDLER 1
@@ -142,7 +142,7 @@
   bool _fullScreen;
   int _id;
   webrtc::CriticalSectionWrapper& _renderCritSec;
-  rtc::scoped_ptr<webrtc::ThreadWrapper> _screenUpdateThread;
+  rtc::scoped_ptr<webrtc::PlatformThread> _screenUpdateThread;
   webrtc::EventWrapper* _screenUpdateEvent;
   bool _isHIViewRef;
   AGLContext _aglContext;
diff --git a/webrtc/modules/video_render/mac/video_render_nsopengl.h b/webrtc/modules/video_render/mac/video_render_nsopengl.h
index 8bc769a..5993c08 100644
--- a/webrtc/modules/video_render/mac/video_render_nsopengl.h
+++ b/webrtc/modules/video_render/mac/video_render_nsopengl.h
@@ -32,7 +32,7 @@
 
 namespace webrtc {
 class EventTimerWrapper;
-class ThreadWrapper;
+class PlatformThread;
 class VideoRenderNSOpenGL;
 class CriticalSectionWrapper;
 
@@ -166,7 +166,7 @@
     bool _fullScreen;
     int _id;
     CriticalSectionWrapper& _nsglContextCritSec;
-    rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
+    rtc::scoped_ptr<PlatformThread> _screenUpdateThread;
     EventTimerWrapper* _screenUpdateEvent;
     NSOpenGLContext* _nsglContext;
     NSOpenGLContext* _nsglFullScreenContext;
diff --git a/webrtc/modules/video_render/mac/video_render_nsopengl.mm b/webrtc/modules/video_render/mac/video_render_nsopengl.mm
index b5150eb..7457095 100644
--- a/webrtc/modules/video_render/mac/video_render_nsopengl.mm
+++ b/webrtc/modules/video_render/mac/video_render_nsopengl.mm
@@ -11,11 +11,11 @@
 #include "webrtc/engine_configurations.h"
 #if defined(COCOA_RENDERING)
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 #include "webrtc/modules/video_render/mac/video_render_nsopengl.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 namespace webrtc {
@@ -378,8 +378,8 @@
 _windowRefSuperView(NULL),
 _windowRefSuperViewFrame(NSMakeRect(0,0,0,0))
 {
-    _screenUpdateThread = ThreadWrapper::CreateThread(ScreenUpdateThreadProc,
-            this, "ScreenUpdateNSOpenGL");
+  _screenUpdateThread = PlatformThread::CreateThread(
+      ScreenUpdateThreadProc, this, "ScreenUpdateNSOpenGL");
 }
 
 int VideoRenderNSOpenGL::ChangeWindow(CocoaRenderView* newWindowRef)
@@ -657,7 +657,7 @@
     }
 
     // Signal event to exit thread, then delete it
-    ThreadWrapper* tmpPtr = _screenUpdateThread.release();
+    PlatformThread* tmpPtr = _screenUpdateThread.release();
 
     if (tmpPtr)
     {
@@ -864,7 +864,7 @@
 int VideoRenderNSOpenGL::StopThread()
 {
 
-    ThreadWrapper* tmpPtr = _screenUpdateThread.release();
+    PlatformThread* tmpPtr = _screenUpdateThread.release();
     WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id,
                  "%s Stopping thread ", __FUNCTION__, tmpPtr);
 
diff --git a/webrtc/modules/video_render/windows/video_render_direct3d9.cc b/webrtc/modules/video_render/windows/video_render_direct3d9.cc
index 24dd0ef..5458c28 100644
--- a/webrtc/modules/video_render/windows/video_render_direct3d9.cc
+++ b/webrtc/modules/video_render/windows/video_render_direct3d9.cc
@@ -294,7 +294,7 @@
     _totalMemory(0),
     _availableMemory(0)
 {
-    _screenUpdateThread = ThreadWrapper::CreateThread(
+    _screenUpdateThread = PlatformThread::CreateThread(
         ScreenUpdateThreadProc, this, "ScreenUpdateThread");
     _screenUpdateEvent = EventTimerWrapper::Create();
     SetRect(&_originalHwndRect, 0, 0, 0, 0);
@@ -305,7 +305,7 @@
     //NOTE: we should not enter CriticalSection in here!
 
     // Signal event to exit thread, then delete it
-    ThreadWrapper* tmpPtr = _screenUpdateThread.release();
+    PlatformThread* tmpPtr = _screenUpdateThread.release();
     if (tmpPtr)
     {
         _screenUpdateEvent->Set();
diff --git a/webrtc/modules/video_render/windows/video_render_direct3d9.h b/webrtc/modules/video_render/windows/video_render_direct3d9.h
index 8b8509e..c98f08f 100644
--- a/webrtc/modules/video_render/windows/video_render_direct3d9.h
+++ b/webrtc/modules/video_render/windows/video_render_direct3d9.h
@@ -19,8 +19,8 @@
 #include <Map>
 
 // Added
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/video_render/video_render_defines.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 #pragma comment(lib, "d3d9.lib")       // located in DirectX SDK
 
@@ -203,7 +203,7 @@
 
     CriticalSectionWrapper& _refD3DCritsect;
     Trace* _trace;
-    rtc::scoped_ptr<ThreadWrapper> _screenUpdateThread;
+    rtc::scoped_ptr<PlatformThread> _screenUpdateThread;
     EventTimerWrapper* _screenUpdateEvent;
 
     HWND _hWnd;
diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn
index d0447e9..5e0e41e 100644
--- a/webrtc/system_wrappers/BUILD.gn
+++ b/webrtc/system_wrappers/BUILD.gn
@@ -37,7 +37,6 @@
     "include/static_instance.h",
     "include/stl_util.h",
     "include/stringize_macros.h",
-    "include/thread_wrapper.h",
     "include/tick_util.h",
     "include/timestamp_extrapolator.h",
     "include/trace.h",
@@ -79,11 +78,6 @@
     "source/rw_lock_win.h",
     "source/sleep.cc",
     "source/sort.cc",
-    "source/thread.cc",
-    "source/thread_posix.cc",
-    "source/thread_posix.h",
-    "source/thread_win.cc",
-    "source/thread_win.h",
     "source/tick_util.cc",
     "source/timestamp_extrapolator.cc",
     "source/trace_impl.cc",
@@ -193,9 +187,9 @@
   public_configs = [ "..:common_inherited_config" ]
 
   deps = [
-    ":system_wrappers",
     ":field_trial_default",
     ":metrics_default",
+    ":system_wrappers",
   ]
 }
 
diff --git a/webrtc/system_wrappers/include/data_log_impl.h b/webrtc/system_wrappers/include/data_log_impl.h
index 1932a34..723cca3 100644
--- a/webrtc/system_wrappers/include/data_log_impl.h
+++ b/webrtc/system_wrappers/include/data_log_impl.h
@@ -22,8 +22,8 @@
 #include <string>
 #include <vector>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/typedefs.h"
 
 namespace webrtc {
@@ -146,7 +146,7 @@
   int                       counter_;
   TableMap                  tables_;
   EventWrapper*             flush_event_;
-  rtc::scoped_ptr<ThreadWrapper> file_writer_thread_;
+  rtc::scoped_ptr<PlatformThread> file_writer_thread_;
   RWLockWrapper*            tables_lock_;
 };
 
diff --git a/webrtc/system_wrappers/include/thread_wrapper.h b/webrtc/system_wrappers/include/thread_wrapper.h
deleted file mode 100644
index dbd548d..0000000
--- a/webrtc/system_wrappers/include/thread_wrapper.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-// System independant wrapper for spawning threads
-// Note: the spawned thread will loop over the callback function until stopped.
-// Note: The callback function is expected to return every 2 seconds or more
-// often.
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_
-#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_
-
-#if defined(WEBRTC_WIN)
-#include <windows.h>
-#endif
-
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/common_types.h"
-#include "webrtc/typedefs.h"
-
-namespace webrtc {
-
-// Callback function that the spawned thread will enter once spawned.
-// A return value of false is interpreted as that the function has no
-// more work to do and that the thread can be released.
-typedef bool(*ThreadRunFunction)(void*);
-
-enum ThreadPriority {
-#ifdef WEBRTC_WIN
-  kLowPriority = THREAD_PRIORITY_BELOW_NORMAL,
-  kNormalPriority = THREAD_PRIORITY_NORMAL,
-  kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL,
-  kHighestPriority = THREAD_PRIORITY_HIGHEST,
-  kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL
-#else
-  kLowPriority = 1,
-  kNormalPriority = 2,
-  kHighPriority = 3,
-  kHighestPriority = 4,
-  kRealtimePriority = 5
-#endif
-};
-
-// Represents a simple worker thread.  The implementation must be assumed
-// to be single threaded, meaning that all methods of the class, must be
-// called from the same thread, including instantiation.
-// TODO(tommi): There's no need for this to be a virtual interface since there's
-// only ever a single implementation of it.
-class ThreadWrapper {
- public:
-  virtual ~ThreadWrapper() {}
-
-  // Factory method. Constructor disabled.
-  //
-  // func        Pointer to a, by user, specified callback function.
-  // obj         Object associated with the thread. Passed in the callback
-  //             function.
-  // prio        Thread priority. May require root/admin rights.
-  // thread_name  NULL terminated thread name, will be visable in the Windows
-  //             debugger.
-  static rtc::scoped_ptr<ThreadWrapper> CreateThread(ThreadRunFunction func,
-      void* obj, const char* thread_name);
-
-  // Tries to spawns a thread and returns true if that was successful.
-  // Additionally, it tries to set thread priority according to the priority
-  // from when CreateThread was called. However, failure to set priority will
-  // not result in a false return value.
-  virtual bool Start() = 0;
-
-  // Stops the spawned thread and waits for it to be reclaimed with a timeout
-  // of two seconds. Will return false if the thread was not reclaimed.
-  // Multiple tries to Stop are allowed (e.g. to wait longer than 2 seconds).
-  // It's ok to call Stop() even if the spawned thread has been reclaimed.
-  virtual bool Stop() = 0;
-
-  // Set the priority of the worker thread.  Must be called when thread
-  // is running.
-  virtual bool SetPriority(ThreadPriority priority) = 0;
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_THREAD_WRAPPER_H_
diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc
index ed845cc..aad55ac 100644
--- a/webrtc/system_wrappers/source/condition_variable_unittest.cc
+++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc
@@ -11,9 +11,9 @@
 #include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
 
 #include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/system_wrappers/include/tick_util.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
@@ -147,8 +147,8 @@
   CondVarTest() {}
 
   virtual void SetUp() {
-    thread_ = ThreadWrapper::CreateThread(&WaitingRunFunction,
-                                          &baton_, "CondVarTest");
+    thread_ = PlatformThread::CreateThread(&WaitingRunFunction, &baton_,
+                                           "CondVarTest");
     ASSERT_TRUE(thread_->Start());
   }
 
@@ -167,7 +167,7 @@
   Baton baton_;
 
  private:
-  rtc::scoped_ptr<ThreadWrapper> thread_;
+  rtc::scoped_ptr<PlatformThread> thread_;
 };
 
 // The SetUp and TearDown functions use condition variables.
diff --git a/webrtc/system_wrappers/source/critical_section_unittest.cc b/webrtc/system_wrappers/source/critical_section_unittest.cc
index 6848bdd..347cb55 100644
--- a/webrtc/system_wrappers/source/critical_section_unittest.cc
+++ b/webrtc/system_wrappers/source/critical_section_unittest.cc
@@ -12,7 +12,7 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 namespace webrtc {
@@ -78,7 +78,7 @@
   CriticalSectionWrapper* crit_sect =
       CriticalSectionWrapper::CreateCriticalSection();
   ProtectedCount count(crit_sect);
-  rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread(
+  rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread(
       &LockUnlockThenStopRunFunction, &count, "ThreadWakesOnce");
   crit_sect->Enter();
   ASSERT_TRUE(thread->Start());
@@ -105,7 +105,7 @@
   CriticalSectionWrapper* crit_sect =
       CriticalSectionWrapper::CreateCriticalSection();
   ProtectedCount count(crit_sect);
-  rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread(
+  rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread(
       &LockUnlockRunFunction, &count, "ThreadWakesTwice");
   crit_sect->Enter();  // Make sure counter stays 0 until we wait for it.
   ASSERT_TRUE(thread->Start());
diff --git a/webrtc/system_wrappers/source/data_log.cc b/webrtc/system_wrappers/source/data_log.cc
index dbc8ea1..c25971d 100644
--- a/webrtc/system_wrappers/source/data_log.cc
+++ b/webrtc/system_wrappers/source/data_log.cc
@@ -348,8 +348,8 @@
 }
 
 int DataLogImpl::Init() {
-  file_writer_thread_ = ThreadWrapper::CreateThread(
-      DataLogImpl::Run, instance_, "DataLog");
+  file_writer_thread_ =
+      PlatformThread::CreateThread(DataLogImpl::Run, instance_, "DataLog");
   bool success = file_writer_thread_->Start();
   if (!success)
     return -1;
diff --git a/webrtc/system_wrappers/source/event_timer_posix.cc b/webrtc/system_wrappers/source/event_timer_posix.cc
index 99eebcb..ff26e76 100644
--- a/webrtc/system_wrappers/source/event_timer_posix.cc
+++ b/webrtc/system_wrappers/source/event_timer_posix.cc
@@ -154,7 +154,7 @@
   // Start the timer thread
   timer_event_.reset(new EventTimerPosix());
   const char* thread_name = "WebRtc_event_timer_thread";
-  timer_thread_ = ThreadWrapper::CreateThread(Run, this, thread_name);
+  timer_thread_ = PlatformThread::CreateThread(Run, this, thread_name);
   periodic_ = periodic;
   time_ = time;
   bool started = timer_thread_->Start();
diff --git a/webrtc/system_wrappers/source/event_timer_posix.h b/webrtc/system_wrappers/source/event_timer_posix.h
index 21c4ac7..6e45b38 100644
--- a/webrtc/system_wrappers/source/event_timer_posix.h
+++ b/webrtc/system_wrappers/source/event_timer_posix.h
@@ -16,7 +16,7 @@
 #include <pthread.h>
 #include <time.h>
 
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 
 namespace webrtc {
 
@@ -46,7 +46,7 @@
   pthread_mutex_t mutex_;
   bool event_set_;
 
-  rtc::scoped_ptr<ThreadWrapper> timer_thread_;
+  rtc::scoped_ptr<PlatformThread> timer_thread_;
   rtc::scoped_ptr<EventTimerPosix> timer_event_;
   timespec       created_at_;
 
diff --git a/webrtc/system_wrappers/source/thread.cc b/webrtc/system_wrappers/source/thread.cc
deleted file mode 100644
index 7da1e3d..0000000
--- a/webrtc/system_wrappers/source/thread.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
-
-#if defined(_WIN32)
-#include "webrtc/system_wrappers/source/thread_win.h"
-#else
-#include "webrtc/system_wrappers/source/thread_posix.h"
-#endif
-
-namespace webrtc {
-
-#if defined(_WIN32)
-typedef ThreadWindows ThreadType;
-#else
-typedef ThreadPosix ThreadType;
-#endif
-
-rtc::scoped_ptr<ThreadWrapper> ThreadWrapper::CreateThread(
-    ThreadRunFunction func, void* obj, const char* thread_name) {
-  return rtc::scoped_ptr<ThreadWrapper>(
-      new ThreadType(func, obj, thread_name)).Pass();
-}
-
-}  // namespace webrtc
diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc
deleted file mode 100644
index 952a3cd..0000000
--- a/webrtc/system_wrappers/source/thread_posix.cc
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/source/thread_posix.h"
-
-#include <algorithm>
-
-#include <errno.h>
-#include <unistd.h>
-#ifdef WEBRTC_LINUX
-#include <linux/unistd.h>
-#include <sched.h>
-#include <sys/types.h>
-#endif
-
-#include "webrtc/base/checks.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/trace.h"
-
-namespace webrtc {
-namespace {
-struct ThreadAttributes {
-  ThreadAttributes() { pthread_attr_init(&attr); }
-  ~ThreadAttributes() { pthread_attr_destroy(&attr); }
-  pthread_attr_t* operator&() { return &attr; }
-  pthread_attr_t attr;
-};
-}  // namespace
-
-int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
-                            int max_prio) {
-  RTC_DCHECK(max_prio - min_prio > 2);
-  const int top_prio = max_prio - 1;
-  const int low_prio = min_prio + 1;
-
-  switch (priority) {
-    case kLowPriority:
-      return low_prio;
-    case kNormalPriority:
-      // The -1 ensures that the kHighPriority is always greater or equal to
-      // kNormalPriority.
-      return (low_prio + top_prio - 1) / 2;
-    case kHighPriority:
-      return std::max(top_prio - 2, low_prio);
-    case kHighestPriority:
-      return std::max(top_prio - 1, low_prio);
-    case kRealtimePriority:
-      return top_prio;
-  }
-  RTC_DCHECK(false);
-  return low_prio;
-}
-
-// static
-void* ThreadPosix::StartThread(void* param) {
-  static_cast<ThreadPosix*>(param)->Run();
-  return 0;
-}
-
-ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj,
-                         const char* thread_name)
-    : run_function_(func),
-      obj_(obj),
-      stop_event_(false, false),
-      name_(thread_name ? thread_name : "webrtc"),
-      thread_(0) {
-  RTC_DCHECK(name_.length() < 64);
-}
-
-ThreadPosix::~ThreadPosix() {
-  RTC_DCHECK(thread_checker_.CalledOnValidThread());
-}
-
-// TODO(pbos): Make Start void, calling code really doesn't support failures
-// here.
-bool ThreadPosix::Start() {
-  RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  RTC_DCHECK(!thread_) << "Thread already started?";
-
-  ThreadAttributes attr;
-  // Set the stack stack size to 1M.
-  pthread_attr_setstacksize(&attr, 1024 * 1024);
-  RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this));
-  return true;
-}
-
-bool ThreadPosix::Stop() {
-  RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  if (!thread_)
-    return true;
-
-  stop_event_.Set();
-  RTC_CHECK_EQ(0, pthread_join(thread_, nullptr));
-  thread_ = 0;
-
-  return true;
-}
-
-bool ThreadPosix::SetPriority(ThreadPriority priority) {
-  RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  if (!thread_)
-    return false;
-#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
-  // TODO(tommi): Switch to the same mechanism as Chromium uses for
-  // changing thread priorities.
-  return true;
-#else
-#ifdef WEBRTC_THREAD_RR
-  const int policy = SCHED_RR;
-#else
-  const int policy = SCHED_FIFO;
-#endif
-  const int min_prio = sched_get_priority_min(policy);
-  const int max_prio = sched_get_priority_max(policy);
-  if (min_prio == -1 || max_prio == -1) {
-    WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
-                 "unable to retreive min or max priority for threads");
-    return false;
-  }
-
-  if (max_prio - min_prio <= 2)
-    return false;
-
-  sched_param param;
-  param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio);
-  if (pthread_setschedparam(thread_, policy, &param) != 0) {
-    WEBRTC_TRACE(
-        kTraceError, kTraceUtility, -1, "unable to set thread priority");
-    return false;
-  }
-
-  return true;
-#endif  // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
-}
-
-void ThreadPosix::Run() {
-  if (!name_.empty()) {
-    // Setting the thread name may fail (harmlessly) if running inside a
-    // sandbox. Ignore failures if they happen.
-    rtc::SetCurrentThreadName(name_.substr(0, 63).c_str());
-  }
-
-  // It's a requirement that for successful thread creation that the run
-  // function be called at least once (see RunFunctionIsCalled unit test),
-  // so to fullfill that requirement, we use a |do| loop and not |while|.
-  do {
-    if (!run_function_(obj_))
-      break;
-  } while (!stop_event_.Wait(0));
-}
-
-}  // namespace webrtc
diff --git a/webrtc/system_wrappers/source/thread_posix.h b/webrtc/system_wrappers/source/thread_posix.h
deleted file mode 100644
index bcdd732..0000000
--- a/webrtc/system_wrappers/source/thread_posix.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
-#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
-
-#include "webrtc/base/event.h"
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/base/thread_checker.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
-
-#include <pthread.h>
-
-namespace webrtc {
-
-int ConvertToSystemPriority(ThreadPriority priority, int min_prio,
-                            int max_prio);
-
-class ThreadPosix : public ThreadWrapper {
- public:
-  ThreadPosix(ThreadRunFunction func, void* obj, const char* thread_name);
-  ~ThreadPosix() override;
-
-  // From ThreadWrapper.
-  bool Start() override;
-  bool Stop() override;
-
-  bool SetPriority(ThreadPriority priority) override;
-
- private:
-  static void* StartThread(void* param);
-
-  void Run();
-
-  rtc::ThreadChecker thread_checker_;
-  ThreadRunFunction const run_function_;
-  void* const obj_;
-  rtc::Event stop_event_;
-  const std::string name_;
-
-  pthread_t thread_;
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_
diff --git a/webrtc/system_wrappers/source/thread_posix_unittest.cc b/webrtc/system_wrappers/source/thread_posix_unittest.cc
deleted file mode 100644
index edfb145..0000000
--- a/webrtc/system_wrappers/source/thread_posix_unittest.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/source/thread_posix.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(ThreadTestPosix, PrioritySettings) {
-  // API assumes that max_prio - min_prio > 2. Test the extreme case.
-  const int kMinPrio = -1;
-  const int kMaxPrio = 2;
-
-  int last_priority = kMinPrio;
-  for (int priority = webrtc::kLowPriority;
-       priority <= webrtc::kRealtimePriority; ++priority) {
-    int system_priority = webrtc::ConvertToSystemPriority(
-        static_cast<webrtc::ThreadPriority>(priority), kMinPrio, kMaxPrio);
-    EXPECT_GT(system_priority, kMinPrio);
-    EXPECT_LT(system_priority, kMaxPrio);
-    EXPECT_GE(system_priority, last_priority);
-    last_priority = system_priority;
-  }
-}
diff --git a/webrtc/system_wrappers/source/thread_win.cc b/webrtc/system_wrappers/source/thread_win.cc
deleted file mode 100644
index b1c513c..0000000
--- a/webrtc/system_wrappers/source/thread_win.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/system_wrappers/source/thread_win.h"
-
-#include <process.h>
-#include <stdio.h>
-#include <windows.h>
-
-#include "webrtc/base/checks.h"
-#include "webrtc/system_wrappers/include/trace.h"
-
-namespace webrtc {
-namespace {
-void CALLBACK RaiseFlag(ULONG_PTR param) {
-  *reinterpret_cast<bool*>(param) = true;
-}
-}
-
-ThreadWindows::ThreadWindows(ThreadRunFunction func, void* obj,
-                             const char* thread_name)
-    : run_function_(func),
-      obj_(obj),
-      stop_(false),
-      thread_(NULL),
-      name_(thread_name ? thread_name : "webrtc") {
-  RTC_DCHECK(func);
-}
-
-ThreadWindows::~ThreadWindows() {
-  RTC_DCHECK(main_thread_.CalledOnValidThread());
-  RTC_DCHECK(!thread_);
-}
-
-// static
-DWORD WINAPI ThreadWindows::StartThread(void* param) {
-  static_cast<ThreadWindows*>(param)->Run();
-  return 0;
-}
-
-bool ThreadWindows::Start() {
-  RTC_DCHECK(main_thread_.CalledOnValidThread());
-  RTC_DCHECK(!thread_);
-
-  stop_ = false;
-
-  // See bug 2902 for background on STACK_SIZE_PARAM_IS_A_RESERVATION.
-  // Set the reserved stack stack size to 1M, which is the default on Windows
-  // and Linux.
-  DWORD thread_id;
-  thread_ = ::CreateThread(NULL, 1024 * 1024, &StartThread, this,
-      STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_id);
-  if (!thread_ ) {
-    RTC_DCHECK(false) << "CreateThread failed";
-    return false;
-  }
-
-  return true;
-}
-
-bool ThreadWindows::Stop() {
-  RTC_DCHECK(main_thread_.CalledOnValidThread());
-  if (thread_) {
-    // Set stop_ to |true| on the worker thread.
-    QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_));
-    WaitForSingleObject(thread_, INFINITE);
-    CloseHandle(thread_);
-    thread_ = nullptr;
-  }
-
-  return true;
-}
-
-bool ThreadWindows::SetPriority(ThreadPriority priority) {
-  RTC_DCHECK(main_thread_.CalledOnValidThread());
-  return thread_ && SetThreadPriority(thread_, priority);
-}
-
-void ThreadWindows::Run() {
-  if (!name_.empty())
-    rtc::SetCurrentThreadName(name_.c_str());
-
-  do {
-    // The interface contract of Start/Stop is that for a successfull call to
-    // Start, there should be at least one call to the run function.  So we
-    // call the function before checking |stop_|.
-    if (!run_function_(obj_))
-      break;
-    // Alertable sleep to permit RaiseFlag to run and update |stop_|.
-    SleepEx(0, true);
-  } while (!stop_);
-}
-
-}  // namespace webrtc
diff --git a/webrtc/system_wrappers/source/thread_win.h b/webrtc/system_wrappers/source/thread_win.h
deleted file mode 100644
index 34edd6d..0000000
--- a/webrtc/system_wrappers/source/thread_win.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a BSD-style license
- *  that can be found in the LICENSE file in the root of the source
- *  tree. An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
-#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
-
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
-
-#include <windows.h>
-
-#include "webrtc/base/thread_checker.h"
-
-namespace webrtc {
-
-class ThreadWindows : public ThreadWrapper {
- public:
-  ThreadWindows(ThreadRunFunction func, void* obj, const char* thread_name);
-  ~ThreadWindows() override;
-
-  bool Start() override;
-  bool Stop() override;
-
-  bool SetPriority(ThreadPriority priority) override;
-
- protected:
-  void Run();
-
- private:
-  static DWORD WINAPI StartThread(void* param);
-
-  ThreadRunFunction const run_function_;
-  void* const obj_;
-  bool stop_;
-  HANDLE thread_;
-  const std::string name_;
-  rtc::ThreadChecker main_thread_;
-};
-
-}  // namespace webrtc
-
-#endif  // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_
diff --git a/webrtc/system_wrappers/source/trace_impl.h b/webrtc/system_wrappers/source/trace_impl.h
index ed49d9d..c6d81d5 100644
--- a/webrtc/system_wrappers/source/trace_impl.h
+++ b/webrtc/system_wrappers/source/trace_impl.h
@@ -16,7 +16,7 @@
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/file_wrapper.h"
 #include "webrtc/system_wrappers/include/static_instance.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/system_wrappers/include/trace.h"
 
 namespace webrtc {
diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp
index 90ea79f..f5f2b2b 100644
--- a/webrtc/system_wrappers/system_wrappers.gyp
+++ b/webrtc/system_wrappers/system_wrappers.gyp
@@ -44,7 +44,6 @@
         'include/static_instance.h',
         'include/stl_util.h',
         'include/stringize_macros.h',
-        'include/thread_wrapper.h',
         'include/tick_util.h',
         'include/timestamp_extrapolator.h',
         'include/trace.h',
@@ -91,11 +90,6 @@
         'source/sleep.cc',
         'source/sort.cc',
         'source/tick_util.cc',
-        'source/thread.cc',
-        'source/thread_posix.cc',
-        'source/thread_posix.h',
-        'source/thread_win.cc',
-        'source/thread_win.h',
         'source/timestamp_extrapolator.cc',
         'source/trace_impl.cc',
         'source/trace_impl.h',
diff --git a/webrtc/system_wrappers/system_wrappers_tests.gyp b/webrtc/system_wrappers/system_wrappers_tests.gyp
index 02bf627..7f73533 100644
--- a/webrtc/system_wrappers/system_wrappers_tests.gyp
+++ b/webrtc/system_wrappers/system_wrappers_tests.gyp
@@ -33,8 +33,6 @@
         'source/scoped_vector_unittest.cc',
         'source/stringize_macros_unittest.cc',
         'source/stl_util_unittest.cc',
-        'source/thread_unittest.cc',
-        'source/thread_posix_unittest.cc',
       ],
       'conditions': [
         ['enable_data_logging==1', {
@@ -42,9 +40,6 @@
         }, {
           'sources!': [ 'source/data_log_unittest.cc', ],
         }],
-        ['os_posix==0', {
-          'sources!': [ 'source/thread_posix_unittest.cc', ],
-        }],
         ['OS=="android"', {
           'dependencies': [
             '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code',
diff --git a/webrtc/test/channel_transport/udp_socket2_manager_win.cc b/webrtc/test/channel_transport/udp_socket2_manager_win.cc
index 5a11abb..bd466a2 100644
--- a/webrtc/test/channel_transport/udp_socket2_manager_win.cc
+++ b/webrtc/test/channel_transport/udp_socket2_manager_win.cc
@@ -556,7 +556,7 @@
     if(!_init)
     {
         const char* threadName = "UdpSocket2ManagerWindows_thread";
-        _pThread = ThreadWrapper::CreateThread(Run, this, threadName);
+        _pThread = PlatformThread::CreateThread(Run, this, threadName);
         _init = true;
     }
     return 0;
diff --git a/webrtc/test/channel_transport/udp_socket2_manager_win.h b/webrtc/test/channel_transport/udp_socket2_manager_win.h
index c6af03a..9cfc0f0 100644
--- a/webrtc/test/channel_transport/udp_socket2_manager_win.h
+++ b/webrtc/test/channel_transport/udp_socket2_manager_win.h
@@ -17,7 +17,7 @@
 #include "webrtc/system_wrappers/include/atomic32.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/test/channel_transport/udp_socket2_win.h"
 #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h"
 #include "webrtc/test/channel_transport/udp_transport.h"
@@ -47,7 +47,7 @@
     int fromLen;
     // Should be set to true if the I/O context was passed to the system by
     // a thread not controlled by the socket implementation.
-    bool ioInitiatedByThreadWrapper;
+    bool ioInitiatedByPlatformThread;
     // TODO (hellner): Not used. Delete it.
     PerIoContext* pNextFree;
 };
@@ -105,7 +105,7 @@
     bool Process();
 private:
     HANDLE _ioCompletionHandle;
-    rtc::scoped_ptr<ThreadWrapper> _pThread;
+    rtc::scoped_ptr<PlatformThread> _pThread;
     static int32_t _numOfWorkers;
     int32_t _workerNumber;
     volatile bool _stop;
diff --git a/webrtc/test/channel_transport/udp_socket2_win.cc b/webrtc/test/channel_transport/udp_socket2_win.cc
index 4c63dc9..adeb46a 100644
--- a/webrtc/test/channel_transport/udp_socket2_win.cc
+++ b/webrtc/test/channel_transport/udp_socket2_win.cc
@@ -432,13 +432,13 @@
     if(pIOContext == NULL || error == ERROR_OPERATION_ABORTED)
     {
         if ((pIOContext != NULL) &&
-            !pIOContext->ioInitiatedByThreadWrapper &&
+            !pIOContext->ioInitiatedByPlatformThread &&
             (error == ERROR_OPERATION_ABORTED) &&
             (pIOContext->ioOperation == OP_READ) &&
             _outstandingCallsDisabled)
         {
-            // !pIOContext->initiatedIOByThreadWrapper indicate that the I/O
-            // was not initiated by a ThreadWrapper thread.
+            // !pIOContext->initiatedIOByPlatformThread indicate that the I/O
+            // was not initiated by a PlatformThread thread.
             // This may happen if the thread that initiated receiving (e.g.
             // by calling StartListen())) is deleted before any packets have
             // been received.
@@ -519,7 +519,7 @@
         {
             // The PerIoContext was posted by a thread controlled by the socket
             // implementation.
-            pIOContext->ioInitiatedByThreadWrapper = true;
+            pIOContext->ioInitiatedByPlatformThread = true;
         }
         OutstandingCallCompleted();
         return;
@@ -546,7 +546,7 @@
     }
     // This function may have been called by thread not controlled by the socket
     // implementation.
-    pIoContext->ioInitiatedByThreadWrapper = false;
+    pIoContext->ioInitiatedByPlatformThread = false;
     return PostRecv(pIoContext);
 }
 
diff --git a/webrtc/test/channel_transport/udp_socket_manager_posix.cc b/webrtc/test/channel_transport/udp_socket_manager_posix.cc
index 145efcb..6b597e7 100644
--- a/webrtc/test/channel_transport/udp_socket_manager_posix.cc
+++ b/webrtc/test/channel_transport/udp_socket_manager_posix.cc
@@ -188,8 +188,8 @@
 UdpSocketManagerPosixImpl::UdpSocketManagerPosixImpl()
 {
     _critSectList = CriticalSectionWrapper::CreateCriticalSection();
-    _thread = ThreadWrapper::CreateThread(UdpSocketManagerPosixImpl::Run, this,
-                                          "UdpSocketManagerPosixImplThread");
+    _thread = PlatformThread::CreateThread(UdpSocketManagerPosixImpl::Run, this,
+                                           "UdpSocketManagerPosixImplThread");
     FD_ZERO(&_readFds);
     WEBRTC_TRACE(kTraceMemory,  kTraceTransport, -1,
                  "UdpSocketManagerPosix created");
diff --git a/webrtc/test/channel_transport/udp_socket_manager_posix.h b/webrtc/test/channel_transport/udp_socket_manager_posix.h
index 64156fd..0750a4a 100644
--- a/webrtc/test/channel_transport/udp_socket_manager_posix.h
+++ b/webrtc/test/channel_transport/udp_socket_manager_posix.h
@@ -17,8 +17,8 @@
 #include <list>
 #include <map>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h"
 #include "webrtc/test/channel_transport/udp_socket_wrapper.h"
 
@@ -75,7 +75,7 @@
 private:
     typedef std::list<UdpSocketWrapper*> SocketList;
     typedef std::list<SOCKET> FdList;
-    rtc::scoped_ptr<ThreadWrapper> _thread;
+    rtc::scoped_ptr<PlatformThread> _thread;
     CriticalSectionWrapper* _critSectList;
 
     fd_set _readFds;
diff --git a/webrtc/test/direct_transport.cc b/webrtc/test/direct_transport.cc
index 6dcba81..837281b 100644
--- a/webrtc/test/direct_transport.cc
+++ b/webrtc/test/direct_transport.cc
@@ -21,7 +21,7 @@
     : send_call_(send_call),
       packet_event_(EventWrapper::Create()),
       thread_(
-          ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")),
+          PlatformThread::CreateThread(NetworkProcess, this, "NetworkProcess")),
       clock_(Clock::GetRealTimeClock()),
       shutting_down_(false),
       fake_network_(FakeNetworkPipe::Config()) {
@@ -33,7 +33,7 @@
     : send_call_(send_call),
       packet_event_(EventWrapper::Create()),
       thread_(
-          ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")),
+          PlatformThread::CreateThread(NetworkProcess, this, "NetworkProcess")),
       clock_(Clock::GetRealTimeClock()),
       shutting_down_(false),
       fake_network_(config) {
diff --git a/webrtc/test/direct_transport.h b/webrtc/test/direct_transport.h
index 241a5bc..d3cc084 100644
--- a/webrtc/test/direct_transport.h
+++ b/webrtc/test/direct_transport.h
@@ -15,9 +15,9 @@
 #include <deque>
 
 #include "webrtc/base/criticalsection.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/fake_network_pipe.h"
 #include "webrtc/transport.h"
 
@@ -53,7 +53,7 @@
   rtc::CriticalSection lock_;
   Call* const send_call_;
   rtc::scoped_ptr<EventWrapper> packet_event_;
-  rtc::scoped_ptr<ThreadWrapper> thread_;
+  rtc::scoped_ptr<PlatformThread> thread_;
   Clock* const clock_;
 
   bool shutting_down_;
diff --git a/webrtc/test/fake_audio_device.cc b/webrtc/test/fake_audio_device.cc
index 4408804..4eee660 100644
--- a/webrtc/test/fake_audio_device.cc
+++ b/webrtc/test/fake_audio_device.cc
@@ -13,11 +13,11 @@
 #include <algorithm>
 
 #include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/media_file/media_file_utility.h"
 #include "webrtc/system_wrappers/include/clock.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/file_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 
 namespace webrtc {
 namespace test {
@@ -53,8 +53,8 @@
 
   if (!tick_->StartTimer(true, 10))
     return -1;
-  thread_ = ThreadWrapper::CreateThread(FakeAudioDevice::Run, this,
-                                        "FakeAudioDevice");
+  thread_ = PlatformThread::CreateThread(FakeAudioDevice::Run, this,
+                                         "FakeAudioDevice");
   if (thread_.get() == NULL)
     return -1;
   if (!thread_->Start()) {
diff --git a/webrtc/test/fake_audio_device.h b/webrtc/test/fake_audio_device.h
index bdc6728..9733da3 100644
--- a/webrtc/test/fake_audio_device.h
+++ b/webrtc/test/fake_audio_device.h
@@ -23,7 +23,7 @@
 class EventTimerWrapper;
 class FileWrapper;
 class ModuleFileUtility;
-class ThreadWrapper;
+class PlatformThread;
 
 namespace test {
 
@@ -59,7 +59,7 @@
   Clock* clock_;
   rtc::scoped_ptr<EventTimerWrapper> tick_;
   mutable rtc::CriticalSection lock_;
-  rtc::scoped_ptr<ThreadWrapper> thread_;
+  rtc::scoped_ptr<PlatformThread> thread_;
   rtc::scoped_ptr<ModuleFileUtility> file_utility_;
   rtc::scoped_ptr<FileWrapper> input_stream_;
 };
diff --git a/webrtc/test/frame_generator_capturer.cc b/webrtc/test/frame_generator_capturer.cc
index 70e2c85..cc0ad88 100644
--- a/webrtc/test/frame_generator_capturer.cc
+++ b/webrtc/test/frame_generator_capturer.cc
@@ -11,11 +11,11 @@
 #include "webrtc/test/frame_generator_capturer.h"
 
 #include "webrtc/base/criticalsection.h"
-#include "webrtc/test/frame_generator.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/system_wrappers/include/clock.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/test/frame_generator.h"
 #include "webrtc/video_send_stream.h"
 
 namespace webrtc {
@@ -88,8 +88,8 @@
 
   if (!tick_->StartTimer(true, 1000 / target_fps_))
     return false;
-  thread_ = ThreadWrapper::CreateThread(FrameGeneratorCapturer::Run, this,
-                                        "FrameGeneratorCapturer");
+  thread_ = PlatformThread::CreateThread(FrameGeneratorCapturer::Run, this,
+                                         "FrameGeneratorCapturer");
   if (thread_.get() == NULL)
     return false;
   if (!thread_->Start()) {
diff --git a/webrtc/test/frame_generator_capturer.h b/webrtc/test/frame_generator_capturer.h
index aff906d..73c97a6 100644
--- a/webrtc/test/frame_generator_capturer.h
+++ b/webrtc/test/frame_generator_capturer.h
@@ -21,7 +21,7 @@
 
 class CriticalSectionWrapper;
 class EventTimerWrapper;
-class ThreadWrapper;
+class PlatformThread;
 
 namespace test {
 
@@ -64,7 +64,7 @@
 
   rtc::scoped_ptr<EventTimerWrapper> tick_;
   rtc::CriticalSection lock_;
-  rtc::scoped_ptr<ThreadWrapper> thread_;
+  rtc::scoped_ptr<PlatformThread> thread_;
   rtc::scoped_ptr<FrameGenerator> frame_generator_;
 
   int target_fps_;
diff --git a/webrtc/video/rampup_tests.cc b/webrtc/video/rampup_tests.cc
index c9b8e11..fc0d0cb 100644
--- a/webrtc/video/rampup_tests.cc
+++ b/webrtc/video/rampup_tests.cc
@@ -12,6 +12,7 @@
 #include "webrtc/base/checks.h"
 #include "webrtc/base/common.h"
 #include "webrtc/base/event.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/modules/pacing/packet_router.h"
 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
@@ -22,7 +23,6 @@
 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/testsupport/perf_test.h"
 #include "webrtc/video/rampup_tests.h"
 
@@ -60,9 +60,9 @@
       extension_type_(extension_type),
       ssrcs_(GenerateSsrcs(num_streams, 100)),
       rtx_ssrcs_(GenerateSsrcs(num_streams, 200)),
-      poller_thread_(ThreadWrapper::CreateThread(&BitrateStatsPollingThread,
-                                                 this,
-                                                 "BitrateStatsPollingThread")),
+      poller_thread_(PlatformThread::CreateThread(&BitrateStatsPollingThread,
+                                                  this,
+                                                  "BitrateStatsPollingThread")),
       sender_call_(nullptr) {
   if (rtx_) {
     for (size_t i = 0; i < ssrcs_.size(); ++i)
diff --git a/webrtc/video/rampup_tests.h b/webrtc/video/rampup_tests.h
index ff65c8d..3632a81 100644
--- a/webrtc/video/rampup_tests.h
+++ b/webrtc/video/rampup_tests.h
@@ -98,7 +98,7 @@
   std::vector<uint32_t> rtx_ssrcs_;
   SsrcMap rtx_ssrc_map_;
 
-  rtc::scoped_ptr<ThreadWrapper> poller_thread_;
+  rtc::scoped_ptr<PlatformThread> poller_thread_;
   Call* sender_call_;
 };
 
diff --git a/webrtc/video/video_capture_input.cc b/webrtc/video/video_capture_input.cc
index 37ea07e..d15932d 100644
--- a/webrtc/video/video_capture_input.cc
+++ b/webrtc/video/video_capture_input.cc
@@ -42,9 +42,9 @@
       local_renderer_(local_renderer),
       stats_proxy_(stats_proxy),
       incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()),
-      encoder_thread_(ThreadWrapper::CreateThread(EncoderThreadFunction,
-                                                  this,
-                                                  "EncoderThread")),
+      encoder_thread_(PlatformThread::CreateThread(EncoderThreadFunction,
+                                                   this,
+                                                   "EncoderThread")),
       capture_event_(EventWrapper::Create()),
       stop_(0),
       last_captured_timestamp_(0),
diff --git a/webrtc/video/video_capture_input.h b/webrtc/video/video_capture_input.h
index 22a8ddc..2cdcbf8 100644
--- a/webrtc/video/video_capture_input.h
+++ b/webrtc/video/video_capture_input.h
@@ -14,6 +14,7 @@
 #include <vector>
 
 #include "webrtc/base/criticalsection.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/common_types.h"
@@ -23,7 +24,6 @@
 #include "webrtc/modules/video_coding/include/video_coding.h"
 #include "webrtc/modules/video_processing/include/video_processing.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/typedefs.h"
 #include "webrtc/video_send_stream.h"
 
@@ -78,7 +78,7 @@
   rtc::scoped_ptr<CriticalSectionWrapper> incoming_frame_cs_;
   VideoFrame incoming_frame_;
 
-  rtc::scoped_ptr<ThreadWrapper> encoder_thread_;
+  rtc::scoped_ptr<PlatformThread> encoder_thread_;
   rtc::scoped_ptr<EventWrapper> capture_event_;
 
   volatile int stop_;
diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc
index 878beed..da52297 100644
--- a/webrtc/video/video_quality_test.cc
+++ b/webrtc/video/video_quality_test.cc
@@ -91,18 +91,18 @@
     }
 
     for (uint32_t i = 0; i < num_cores; ++i) {
-      rtc::scoped_ptr<ThreadWrapper> thread =
-          ThreadWrapper::CreateThread(&FrameComparisonThread, this, "Analyzer");
+      rtc::scoped_ptr<PlatformThread> thread = PlatformThread::CreateThread(
+          &FrameComparisonThread, this, "Analyzer");
       EXPECT_TRUE(thread->Start());
       comparison_thread_pool_.push_back(thread.release());
     }
 
     stats_polling_thread_ =
-        ThreadWrapper::CreateThread(&PollStatsThread, this, "StatsPoller");
+        PlatformThread::CreateThread(&PollStatsThread, this, "StatsPoller");
   }
 
   ~VideoAnalyzer() {
-    for (ThreadWrapper* thread : comparison_thread_pool_) {
+    for (PlatformThread* thread : comparison_thread_pool_) {
       EXPECT_TRUE(thread->Stop());
       delete thread;
     }
@@ -602,8 +602,8 @@
   const double avg_ssim_threshold_;
 
   rtc::CriticalSection comparison_lock_;
-  std::vector<ThreadWrapper*> comparison_thread_pool_;
-  rtc::scoped_ptr<ThreadWrapper> stats_polling_thread_;
+  std::vector<PlatformThread*> comparison_thread_pool_;
+  rtc::scoped_ptr<PlatformThread> stats_polling_thread_;
   const rtc::scoped_ptr<EventWrapper> comparison_available_event_;
   std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
   const rtc::scoped_ptr<EventWrapper> done_;
diff --git a/webrtc/video/video_send_stream_tests.cc b/webrtc/video/video_send_stream_tests.cc
index a1d7475..eefcfeb 100644
--- a/webrtc/video/video_send_stream_tests.cc
+++ b/webrtc/video/video_send_stream_tests.cc
@@ -16,6 +16,7 @@
 #include "webrtc/base/checks.h"
 #include "webrtc/base/criticalsection.h"
 #include "webrtc/base/logging.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/call.h"
 #include "webrtc/call/transport_adapter.h"
@@ -30,7 +31,6 @@
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/ref_count.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/test/call_test.h"
 #include "webrtc/test/configurable_frame_size_encoder.h"
 #include "webrtc/test/fake_texture_frame.h"
diff --git a/webrtc/video_engine/vie_channel.cc b/webrtc/video_engine/vie_channel.cc
index 4cfd0f0..2e56056 100644
--- a/webrtc/video_engine/vie_channel.cc
+++ b/webrtc/video_engine/vie_channel.cc
@@ -15,6 +15,7 @@
 
 #include "webrtc/base/checks.h"
 #include "webrtc/base/logging.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/common.h"
 #include "webrtc/common_video/include/incoming_video_stream.h"
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
@@ -29,7 +30,6 @@
 #include "webrtc/modules/video_render/video_render_defines.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/metrics.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/video/receive_statistics_proxy.h"
 #include "webrtc/video_engine/call_stats.h"
 #include "webrtc/video_engine/payload_router.h"
@@ -1150,8 +1150,8 @@
   // Start the decode thread
   if (decode_thread_)
     return;
-  decode_thread_ = ThreadWrapper::CreateThread(ChannelDecodeThreadFunction,
-                                               this, "DecodingThread");
+  decode_thread_ = PlatformThread::CreateThread(ChannelDecodeThreadFunction,
+                                                this, "DecodingThread");
   decode_thread_->Start();
   decode_thread_->SetPriority(kHighestPriority);
 }
diff --git a/webrtc/video_engine/vie_channel.h b/webrtc/video_engine/vie_channel.h
index 472dbc8..32f0301 100644
--- a/webrtc/video_engine/vie_channel.h
+++ b/webrtc/video_engine/vie_channel.h
@@ -41,7 +41,7 @@
 class ReceiveStatisticsProxy;
 class ReportBlockStats;
 class RtcpRttStats;
-class ThreadWrapper;
+class PlatformThread;
 class ViEChannelProtectionCallback;
 class ViERTPObserver;
 class VideoCodingModule;
@@ -433,7 +433,7 @@
   const rtc::scoped_ptr<RtcpBandwidthObserver> bandwidth_observer_;
   TransportFeedbackObserver* const transport_feedback_observer_;
 
-  rtc::scoped_ptr<ThreadWrapper> decode_thread_;
+  rtc::scoped_ptr<PlatformThread> decode_thread_;
 
   int nack_history_size_sender_;
   int max_nack_reordering_threshold_;
diff --git a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc
index ceafca9..55dfa15 100644
--- a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc
+++ b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc
@@ -15,7 +15,7 @@
 
 #include "webrtc/voice_engine/test/android/android_test/jni/org_webrtc_voiceengine_test_AndroidTest.h"
 
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 
 #include "webrtc/voice_engine/include/voe_audio_processing.h"
 #include "webrtc/voice_engine/include/voe_base.h"
@@ -177,7 +177,7 @@
     static bool Run(void* ptr);
     bool Process();
 private:
-    rtc::scoped_ptr<ThreadWrapper> _thread;
+    rtc::scoped_ptr<PlatformThread> _thread;
 };
 
 ThreadTest::~ThreadTest()
@@ -188,7 +188,7 @@
 
 ThreadTest::ThreadTest()
 {
-    _thread = ThreadWrapper::CreateThread(Run, this, "ThreadTest thread");
+    _thread = PlatformThread::CreateThread(Run, this, "ThreadTest thread");
 }
 
 bool ThreadTest::Run(void* ptr)
diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc
index 28ab352..e360d41 100644
--- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc
+++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc
@@ -40,9 +40,9 @@
     : pq_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()),
       stream_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()),
       packet_event_(webrtc::EventWrapper::Create()),
-      thread_(webrtc::ThreadWrapper::CreateThread(Run,
-                                                  this,
-                                                  "ConferenceTransport")),
+      thread_(webrtc::PlatformThread::CreateThread(Run,
+                                                   this,
+                                                   "ConferenceTransport")),
       rtt_ms_(0),
       stream_count_(0),
       rtp_header_parser_(webrtc::RtpHeaderParser::Create()) {
diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h
index fb430eb..b9b4e76 100644
--- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h
+++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h
@@ -17,12 +17,12 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 #include "webrtc/base/basictypes.h"
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/voice_engine/include/voe_base.h"
 #include "webrtc/voice_engine/include/voe_codec.h"
 #include "webrtc/voice_engine/include/voe_file.h"
@@ -131,7 +131,7 @@
   const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> pq_crit_;
   const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> stream_crit_;
   const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_;
-  const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_;
+  const rtc::scoped_ptr<webrtc::PlatformThread> thread_;
 
   unsigned int rtt_ms_;
   unsigned int stream_count_;
diff --git a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
index 1a1075c..7b4bc63 100644
--- a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
+++ b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
@@ -13,6 +13,7 @@
 
 #include <deque>
 
+#include "webrtc/base/platform_thread.h"
 #include "webrtc/base/scoped_ptr.h"
 #include "webrtc/common_types.h"
 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
@@ -20,7 +21,6 @@
 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/include/event_wrapper.h"
 #include "webrtc/system_wrappers/include/sleep.h"
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
 #include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h"
 
 class TestErrorObserver;
@@ -30,9 +30,9 @@
   LoopBackTransport(webrtc::VoENetwork* voe_network, int channel)
       : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()),
         packet_event_(webrtc::EventWrapper::Create()),
-        thread_(webrtc::ThreadWrapper::CreateThread(NetworkProcess,
-                                                    this,
-                                                    "LoopBackTransport")),
+        thread_(webrtc::PlatformThread::CreateThread(NetworkProcess,
+                                                     this,
+                                                     "LoopBackTransport")),
         channel_(channel),
         voe_network_(voe_network),
         transmitted_packets_(0) {
@@ -147,7 +147,7 @@
 
   const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_;
   const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_;
-  const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_;
+  const rtc::scoped_ptr<webrtc::PlatformThread> thread_;
   std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get());
   const int channel_;
   std::map<uint32_t, int> channels_ GUARDED_BY(crit_.get());
diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.h b/webrtc/voice_engine/test/auto_test/voe_standard_test.h
index 3bf8936..e60107c 100644
--- a/webrtc/voice_engine/test/auto_test/voe_standard_test.h
+++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.h
@@ -44,7 +44,7 @@
 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
 namespace webrtc {
 class CriticalSectionWrapper;
-class ThreadWrapper;
+class PlatformThread;
 class VoENetEqStats;
 }
 #endif
diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc
index b9e7115..91b39eb 100644
--- a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc
+++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc
@@ -334,8 +334,8 @@
   int rnd(0);
 
   // Start extra thread
-  _ptrExtraApiThread = ThreadWrapper::CreateThread(RunExtraApi, this,
-                                                   "StressTestExtraApiThread");
+  _ptrExtraApiThread = PlatformThread::CreateThread(RunExtraApi, this,
+                                                    "StressTestExtraApiThread");
   VALIDATE_STRESS(!_ptrExtraApiThread->Start());
 
   //       Some possible extensions include:
diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.h b/webrtc/voice_engine/test/auto_test/voe_stress_test.h
index 69b3a92..b69e8da 100644
--- a/webrtc/voice_engine/test/auto_test/voe_stress_test.h
+++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.h
@@ -11,7 +11,7 @@
 #ifndef WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H
 #define WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H
 
-#include "webrtc/system_wrappers/include/thread_wrapper.h"
+#include "webrtc/base/platform_thread.h"
 
 namespace voetest {
 // TODO(andrew): using directives are not permitted.
@@ -38,7 +38,7 @@
 
   VoETestManager& _mgr;
 
-  rtc::scoped_ptr<ThreadWrapper> _ptrExtraApiThread;
+  rtc::scoped_ptr<PlatformThread> _ptrExtraApiThread;
 };
 
 }  // namespace voetest