• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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 BASE_TASK_SEQUENCE_MANAGER_TEST_LAZY_THREAD_CONTROLLER_FOR_TEST_H_
6 #define BASE_TASK_SEQUENCE_MANAGER_TEST_LAZY_THREAD_CONTROLLER_FOR_TEST_H_
7 
8 #include "base/run_loop.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/task/sequence_manager/thread_controller_impl.h"
11 #include "base/threading/platform_thread.h"
12 
13 namespace base {
14 namespace sequence_manager {
15 
16 // This class connects the scheduler to a MessageLoop, but unlike
17 // ThreadControllerImpl it allows the message loop to be created lazily
18 // after the scheduler has been brought up. This is needed in testing scenarios
19 // where Blink is initialized before a MessageLoop has been created.
20 //
21 // TODO(skyostil): Fix the relevant test suites and remove this class
22 // (crbug.com/495659).
23 class LazyThreadControllerForTest : public internal::ThreadControllerImpl {
24  public:
25   LazyThreadControllerForTest();
26   ~LazyThreadControllerForTest() override;
27 
28   // internal::ThreadControllerImpl:
29   void AddNestingObserver(RunLoop::NestingObserver* observer) override;
30   void RemoveNestingObserver(RunLoop::NestingObserver* observer) override;
31   bool RunsTasksInCurrentSequence() override;
32   void ScheduleWork() override;
33   void SetNextDelayedDoWork(LazyNow* lazy_now, TimeTicks run_time) override;
34   void SetDefaultTaskRunner(
35       scoped_refptr<SingleThreadTaskRunner> task_runner) override;
36   void RestoreDefaultTaskRunner() override;
37 
38  private:
39   bool HasMessageLoop();
40   void EnsureMessageLoop();
41 
42   PlatformThreadRef thread_ref_;
43 
44   bool pending_observer_ = false;
45   scoped_refptr<SingleThreadTaskRunner> pending_default_task_runner_;
46 
47   DISALLOW_COPY_AND_ASSIGN(LazyThreadControllerForTest);
48 };
49 
50 }  // namespace sequence_manager
51 }  // namespace base
52 
53 #endif  // BASE_TASK_SEQUENCE_MANAGER_TEST_LAZY_THREAD_CONTROLLER_FOR_TEST_H_
54