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

Side by Side Diff: mojo/edk/test/test_io_thread.cc

Issue 1427633003: Move scoped_test_dir.* and test_io_thread.* from edk/test to edk/system/test. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/test/test_io_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/test/test_io_thread.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/synchronization/waitable_event.h"
11
12 namespace mojo {
13 namespace test {
14
15 namespace {
16
17 void PostTaskAndWaitHelper(base::WaitableEvent* event,
18 const base::Closure& task) {
19 task.Run();
20 event->Signal();
21 }
22
23 } // namespace
24
25 TestIOThread::TestIOThread(StartMode start_mode)
26 : io_thread_("test_io_thread"), io_thread_started_(false) {
27 switch (start_mode) {
28 case StartMode::AUTO:
29 Start();
30 return;
31 case StartMode::MANUAL:
32 return;
33 }
34 CHECK(false) << "Invalid mode";
35 }
36
37 TestIOThread::~TestIOThread() {
38 Stop();
39 }
40
41 void TestIOThread::Start() {
42 CHECK(!io_thread_started_);
43 io_thread_started_ = true;
44 CHECK(io_thread_.StartWithOptions(
45 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
46 }
47
48 void TestIOThread::Stop() {
49 // Note: It's okay to call |Stop()| even if the thread isn't running.
50 io_thread_.Stop();
51 io_thread_started_ = false;
52 }
53
54 void TestIOThread::PostTask(const base::Closure& task) {
55 task_runner()->PostTask(tracked_objects::Location(), task);
56 }
57
58 void TestIOThread::PostTaskAndWait(const base::Closure& task) {
59 base::WaitableEvent event(false, false);
60 task_runner()->PostTask(tracked_objects::Location(),
61 base::Bind(&PostTaskAndWaitHelper, &event, task));
62 event.Wait();
63 }
64
65 } // namespace test
66 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/test/test_io_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698