Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1529)

Unified Diff: mojo/edk/system/test/test_io_thread.cc

Issue 1514113004: EDK: Convert TestIOThread to use the new I/O thread abstraction. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/test/test_io_thread.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/test/test_io_thread.cc
diff --git a/mojo/edk/system/test/test_io_thread.cc b/mojo/edk/system/test/test_io_thread.cc
index 92f7fe375eef070668765e296ed47b81a6de7887..81f84bdf467f2926026114bda167cf013e29f394 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 system {
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 @@ TestIOThread::~TestIOThread() {
}
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) {
« no previous file with comments | « mojo/edk/system/test/test_io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698