• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MOJO_SYSTEM_TEST_UTILS_H_
6 #define MOJO_SYSTEM_TEST_UTILS_H_
7 
8 #include <stdint.h>
9 
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/task_runner.h"
14 #include "base/time/time.h"
15 
16 namespace tracked_objects {
17 class Location;
18 }
19 
20 namespace mojo {
21 namespace system {
22 namespace test {
23 
24 class Stopwatch {
25  public:
Stopwatch()26   Stopwatch() {}
~Stopwatch()27   ~Stopwatch() {}
28 
Start()29   void Start() {
30     start_time_ = base::TimeTicks::HighResNow();
31   }
32 
Elapsed()33   int64_t Elapsed() {
34     return (base::TimeTicks::HighResNow() - start_time_).InMicroseconds();
35   }
36 
37  private:
38   base::TimeTicks start_time_;
39 
40   DISALLOW_COPY_AND_ASSIGN(Stopwatch);
41 };
42 
43 // Posts the given task (to the given task runner) and waits for it to complete.
44 // (Note: Doesn't spin the current thread's message loop, so if you're careless
45 // this could easily deadlock.)
46 void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner,
47                      const tracked_objects::Location& from_here,
48                      const base::Closure& task);
49 
50 }  // namespace test
51 }  // namespace system
52 }  // namespace mojo
53 
54 #endif  // MOJO_SYSTEM_TEST_UTILS_H_
55