OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ | 5 #ifndef MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ |
6 #define MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ | 6 #define MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
| 10 #include "base/callback.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "base/test/simple_test_tick_clock.h" | 13 #include "base/test/simple_test_tick_clock.h" |
13 #include "base/test/test_pending_task.h" | 14 #include "base/test/test_pending_task.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 namespace cast { | 17 namespace cast { |
17 namespace test { | 18 namespace test { |
18 | 19 |
19 // This class wraps a SingleThreadTaskRunner, and allows you to scale | 20 // This class wraps a SingleThreadTaskRunner, and allows you to scale |
20 // the delay for any posted task by a factor. The factor is changed by | 21 // the delay for any posted task by a factor. The factor is changed by |
21 // calling SetSkew(). A skew of 2.0 means that all delayed task will | 22 // calling SetSkew(). A skew of 2.0 means that all delayed task will |
22 // have to wait twice as long. | 23 // have to wait twice as long. |
23 class SkewedSingleThreadTaskRunner : public base::SingleThreadTaskRunner { | 24 class SkewedSingleThreadTaskRunner : public base::SingleThreadTaskRunner { |
24 public: | 25 public: |
25 explicit SkewedSingleThreadTaskRunner( | 26 explicit SkewedSingleThreadTaskRunner( |
26 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
27 | 28 |
28 // Set the delay multiplier to |skew|. | 29 // Set the delay multiplier to |skew|. |
29 void SetSkew(double skew); | 30 void SetSkew(double skew); |
30 | 31 |
31 // base::SingleThreadTaskRunner implementation. | 32 // base::SingleThreadTaskRunner implementation. |
32 bool PostDelayedTask(const tracked_objects::Location& from_here, | 33 bool PostDelayedTask(const tracked_objects::Location& from_here, |
33 const base::Closure& task, | 34 base::Closure task, |
34 base::TimeDelta delay) final; | 35 base::TimeDelta delay) final; |
35 | 36 |
36 bool RunsTasksOnCurrentThread() const final; | 37 bool RunsTasksOnCurrentThread() const final; |
37 | 38 |
38 // This function is currently not used, and will return false. | 39 // This function is currently not used, and will return false. |
39 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 40 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
40 const base::Closure& task, | 41 base::Closure task, |
41 base::TimeDelta delay) final; | 42 base::TimeDelta delay) final; |
42 | 43 |
43 protected: | 44 protected: |
44 ~SkewedSingleThreadTaskRunner() final; | 45 ~SkewedSingleThreadTaskRunner() final; |
45 | 46 |
46 private: | 47 private: |
47 double skew_; | 48 double skew_; |
48 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 49 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(SkewedSingleThreadTaskRunner); | 51 DISALLOW_COPY_AND_ASSIGN(SkewedSingleThreadTaskRunner); |
51 }; | 52 }; |
52 | 53 |
53 } // namespace test | 54 } // namespace test |
54 } // namespace cast | 55 } // namespace cast |
55 } // namespace media | 56 } // namespace media |
56 | 57 |
57 #endif // MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ | 58 #endif // MEDIA_CAST_TEST_SKEWED_SINGLE_THREAD_TASK_RUNNER_H_ |
OLD | NEW |