| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_SYSTEM_TEST_UTILS_H_ | 5 #ifndef MOJO_SYSTEM_TEST_UTILS_H_ |
| 6 #define MOJO_SYSTEM_TEST_UTILS_H_ | 6 #define MOJO_SYSTEM_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void Start() { start_time_ = base::TimeTicks::Now(); } | 47 void Start() { start_time_ = base::TimeTicks::Now(); } |
| 48 | 48 |
| 49 base::TimeDelta Elapsed() { return base::TimeTicks::Now() - start_time_; } | 49 base::TimeDelta Elapsed() { return base::TimeTicks::Now() - start_time_; } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 base::TimeTicks start_time_; | 52 base::TimeTicks start_time_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(Stopwatch); | 54 DISALLOW_COPY_AND_ASSIGN(Stopwatch); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // TestIOThread ---------------------------------------------------------------- | |
| 58 | |
| 59 class TestIOThread { | |
| 60 public: | |
| 61 enum Mode { kAutoStart, kManualStart }; | |
| 62 explicit TestIOThread(Mode mode); | |
| 63 // Stops the I/O thread if necessary. | |
| 64 ~TestIOThread(); | |
| 65 | |
| 66 // |Start()|/|Stop()| should only be called from the main (creation) thread. | |
| 67 // After |Stop()|, |Start()| may be called again to start a new I/O thread. | |
| 68 // |Stop()| may be called even when the I/O thread is not started. | |
| 69 void Start(); | |
| 70 void Stop(); | |
| 71 | |
| 72 void PostTask(const tracked_objects::Location& from_here, | |
| 73 const base::Closure& task); | |
| 74 void PostTaskAndWait(const tracked_objects::Location& from_here, | |
| 75 const base::Closure& task); | |
| 76 | |
| 77 base::MessageLoopForIO* message_loop() { | |
| 78 return static_cast<base::MessageLoopForIO*>(io_thread_.message_loop()); | |
| 79 } | |
| 80 | |
| 81 scoped_refptr<base::TaskRunner> task_runner() { | |
| 82 return message_loop()->message_loop_proxy(); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 base::Thread io_thread_; | |
| 87 bool io_thread_started_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(TestIOThread); | |
| 90 }; | |
| 91 | |
| 92 } // namespace test | 57 } // namespace test |
| 93 } // namespace system | 58 } // namespace system |
| 94 } // namespace mojo | 59 } // namespace mojo |
| 95 | 60 |
| 96 #endif // MOJO_SYSTEM_TEST_UTILS_H_ | 61 #endif // MOJO_SYSTEM_TEST_UTILS_H_ |
| OLD | NEW |