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