OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESSAGE
_LOOP_DELEGATE_FOR_TESTS_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESSAGE
_LOOP_DELEGATE_FOR_TESTS_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESSAGE
_LOOP_DELEGATE_FOR_TESTS_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESSAGE
_LOOP_DELEGATE_FOR_TESTS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
14 #include "platform/scheduler/child/scheduler_tqm_delegate.h" | 14 #include "platform/scheduler/child/scheduler_tqm_delegate.h" |
15 | 15 |
| 16 namespace base { |
| 17 class MessageLoop; |
| 18 } |
| 19 |
16 namespace blink { | 20 namespace blink { |
17 namespace scheduler { | 21 namespace scheduler { |
18 | 22 |
19 // This class connects the scheduler to a MessageLoop, but unlike | 23 // This class connects the scheduler to a MessageLoop, but unlike |
20 // SchedulerMessageLoopDelegate it allows the message loop to be created lazily | 24 // SchedulerMessageLoopDelegate it allows the message loop to be created lazily |
21 // after the scheduler has been brought up. This is needed in testing scenarios | 25 // after the scheduler has been brought up. This is needed in testing scenarios |
22 // where Blink is initialized before a MessageLoop has been created. | 26 // where Blink is initialized before a MessageLoop has been created. |
23 // | 27 // |
24 // TODO(skyostil): Fix the relevant test suites and remove this class | 28 // TODO(skyostil): Fix the relevant test suites and remove this class |
25 // (crbug.com/495659). | 29 // (crbug.com/495659). |
26 class LazySchedulerMessageLoopDelegateForTests : public SchedulerTqmDelegate { | 30 class LazySchedulerMessageLoopDelegateForTests : public SchedulerTqmDelegate { |
27 public: | 31 public: |
28 static scoped_refptr<LazySchedulerMessageLoopDelegateForTests> Create(); | 32 static scoped_refptr<LazySchedulerMessageLoopDelegateForTests> Create(); |
29 | 33 |
30 // SchedulerTqmDelegate implementation | 34 // SchedulerTqmDelegate implementation |
31 void SetDefaultTaskRunner( | 35 void SetDefaultTaskRunner( |
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; | 36 scoped_refptr<base::SingleThreadTaskRunner> task_runner) override; |
33 void RestoreDefaultTaskRunner() override; | 37 void RestoreDefaultTaskRunner() override; |
34 bool PostDelayedTask(const tracked_objects::Location& from_here, | 38 bool PostDelayedTask(const tracked_objects::Location& from_here, |
35 base::OnceClosure task, | 39 base::OnceClosure task, |
36 base::TimeDelta delay) override; | 40 base::TimeDelta delay) override; |
37 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 41 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
38 base::OnceClosure task, | 42 base::OnceClosure task, |
39 base::TimeDelta delay) override; | 43 base::TimeDelta delay) override; |
40 bool RunsTasksOnCurrentThread() const override; | 44 bool RunsTasksOnCurrentThread() const override; |
41 bool IsNested() const override; | 45 bool IsNested() const override; |
42 void AddNestingObserver( | 46 void AddNestingObserver(base::RunLoop::NestingObserver* observer) override; |
43 base::MessageLoop::NestingObserver* observer) override; | 47 void RemoveNestingObserver(base::RunLoop::NestingObserver* observer) override; |
44 void RemoveNestingObserver( | |
45 base::MessageLoop::NestingObserver* observer) override; | |
46 base::TimeTicks NowTicks() override; | 48 base::TimeTicks NowTicks() override; |
47 | 49 |
48 private: | 50 private: |
49 LazySchedulerMessageLoopDelegateForTests(); | 51 LazySchedulerMessageLoopDelegateForTests(); |
50 ~LazySchedulerMessageLoopDelegateForTests() override; | 52 ~LazySchedulerMessageLoopDelegateForTests() override; |
51 | 53 |
52 bool HasMessageLoop() const; | 54 bool HasMessageLoop() const; |
53 base::MessageLoop* EnsureMessageLoop() const; | 55 base::MessageLoop* EnsureMessageLoop() const; |
54 | 56 |
55 mutable base::MessageLoop* message_loop_; | 57 mutable base::MessageLoop* message_loop_; |
56 base::PlatformThreadId thread_id_; | 58 base::PlatformThreadId thread_id_; |
57 | 59 |
58 // A task runner which hasn't yet been overridden in the message loop. | 60 // A task runner which hasn't yet been overridden in the message loop. |
59 mutable scoped_refptr<base::SingleThreadTaskRunner> pending_task_runner_; | 61 mutable scoped_refptr<base::SingleThreadTaskRunner> pending_task_runner_; |
60 mutable scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_; | 62 mutable scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_; |
61 std::unique_ptr<base::TickClock> time_source_; | 63 std::unique_ptr<base::TickClock> time_source_; |
62 | 64 |
63 base::MessageLoop::NestingObserver* pending_observer_; | 65 base::RunLoop::NestingObserver* pending_observer_; |
64 | 66 |
65 DISALLOW_COPY_AND_ASSIGN(LazySchedulerMessageLoopDelegateForTests); | 67 DISALLOW_COPY_AND_ASSIGN(LazySchedulerMessageLoopDelegateForTests); |
66 }; | 68 }; |
67 | 69 |
68 } // namespace scheduler | 70 } // namespace scheduler |
69 } // namespace blink | 71 } // namespace blink |
70 | 72 |
71 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESS
AGE_LOOP_DELEGATE_FOR_TESTS_H_ | 73 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_TEST_LAZY_SCHEDULER_MESS
AGE_LOOP_DELEGATE_FOR_TESTS_H_ |
OLD | NEW |