EDK: Convert TestIOThread to use the new I/O thread abstraction.

R=vardhan@google.com

Review URL: https://codereview.chromium.org/1514113004 .
diff --git a/mojo/edk/system/test/test_io_thread.cc b/mojo/edk/system/test/test_io_thread.cc
index 92f7fe3..81f84bd 100644
--- a/mojo/edk/system/test/test_io_thread.cc
+++ b/mojo/edk/system/test/test_io_thread.cc
@@ -6,8 +6,12 @@
 
 #include <utility>
 
+#include "base/logging.h"
+#include "mojo/edk/platform/io_thread.h"
+#include "mojo/edk/platform/thread.h"
 #include "mojo/edk/util/waitable_event.h"
 
+using mojo::platform::CreateAndStartIOThread;
 using mojo::util::AutoResetWaitableEvent;
 using mojo::util::MakeRefCounted;
 
@@ -16,7 +20,7 @@
 namespace test {
 
 TestIOThread::TestIOThread(StartMode start_mode)
-    : io_thread_("test_io_thread"), io_thread_started_(false) {
+    : io_platform_handle_watcher_(nullptr) {
   switch (start_mode) {
     case StartMode::AUTO:
       Start();
@@ -32,23 +36,23 @@
 }
 
 void TestIOThread::Start() {
-  CHECK(!io_thread_started_);
-  io_thread_started_ = true;
-  CHECK(io_thread_.StartWithOptions(
-      base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
-  io_task_runner_ = MakeRefCounted<base_edk::PlatformTaskRunnerImpl>(
-      message_loop()->task_runner());
+  CHECK(!io_thread_);
+  io_thread_ =
+      CreateAndStartIOThread(&io_task_runner_, &io_platform_handle_watcher_);
 }
 
 void TestIOThread::Stop() {
-  // Note: It's okay to call |Stop()| even if the thread isn't running.
-  io_thread_.Stop();
-  io_thread_started_ = false;
+  if (!io_thread_)
+    return;  // Nothing to do.
+
+  io_thread_->Stop();
+  io_thread_.reset();
+  io_task_runner_ = nullptr;
+  io_platform_handle_watcher_ = nullptr;
 }
 
 bool TestIOThread::IsCurrentAndRunning() const {
-  return base::MessageLoop::current() == io_thread_.message_loop() &&
-         io_thread_.message_loop()->is_running();
+  return io_task_runner_->RunsTasksOnCurrentThread();
 }
 
 void TestIOThread::PostTask(std::function<void()>&& task) {
diff --git a/mojo/edk/system/test/test_io_thread.h b/mojo/edk/system/test/test_io_thread.h
index b27b3a4..fd84b16 100644
--- a/mojo/edk/system/test/test_io_thread.h
+++ b/mojo/edk/system/test/test_io_thread.h
@@ -6,14 +6,19 @@
 #define MOJO_EDK_SYSTEM_TEST_TEST_IO_THREAD_H_
 
 #include <functional>
+#include <memory>
 
-#include "base/threading/thread.h"
-#include "mojo/edk/base_edk/platform_task_runner_impl.h"
 #include "mojo/edk/platform/task_runner.h"
 #include "mojo/edk/util/ref_ptr.h"
 #include "mojo/public/cpp/system/macros.h"
 
 namespace mojo {
+
+namespace platform {
+class PlatformHandleWatcher;
+class Thread;
+}
+
 namespace system {
 namespace test {
 
@@ -41,18 +46,18 @@
   // posted task is executed (note the deadlock risk!).
   void PostTaskAndWait(std::function<void()>&& task);
 
-  base::MessageLoopForIO* message_loop() {
-    return static_cast<base::MessageLoopForIO*>(io_thread_.message_loop());
-  }
-
   const util::RefPtr<platform::TaskRunner>& task_runner() const {
     return io_task_runner_;
   }
 
+  platform::PlatformHandleWatcher* platform_handle_watcher() const {
+    return io_platform_handle_watcher_;
+  }
+
  private:
-  base::Thread io_thread_;
-  bool io_thread_started_;
+  std::unique_ptr<platform::Thread> io_thread_;
   util::RefPtr<platform::TaskRunner> io_task_runner_;
+  platform::PlatformHandleWatcher* io_platform_handle_watcher_;
 
   MOJO_DISALLOW_COPY_AND_ASSIGN(TestIOThread);
 };