summaryrefslogtreecommitdiffstats
path: root/chromium/base/task_scheduler/scheduler_service_thread.h
blob: e6c9fd0cb976bff8becd075a5a7bcf70168397a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_TASK_SCHEDULER_SERVICE_THREAD_H_
#define BASE_TASK_SCHEDULER_SERVICE_THREAD_H_

#include <memory>

#include "base/base_export.h"
#include "base/macros.h"

namespace base {
namespace internal {

class DelayedTaskManager;
class SchedulerWorker;
class TaskTracker;

// A thread dedicated to performing Task Scheduler related work.
class BASE_EXPORT SchedulerServiceThread {
 public:
  ~SchedulerServiceThread();

  // Creates a SchedulerServiceThread. |task_tracker| and |delayed_task_manager|
  // are passed through to the underlying SchedulerWorker. Returns a nullptr on
  // failure.
  static std::unique_ptr<SchedulerServiceThread> Create(
      TaskTracker* task_tracker, DelayedTaskManager* delayed_task_manager);

  // Wakes the SchedulerServiceThread if it wasn't already awake. This also has
  // the impact of updating the amount of time the thread sleeps for delayed
  // tasks.
  void WakeUp();

  // Joins this SchedulerServiceThread. This can only be called once.
  void JoinForTesting();

 private:
  SchedulerServiceThread(std::unique_ptr<SchedulerWorker> worker);

  const std::unique_ptr<SchedulerWorker> worker_;

  DISALLOW_COPY_AND_ASSIGN(SchedulerServiceThread);
};

}  // namespace internal
}  // namespace base

#endif  // BASE_TASK_SCHEDULER_SERVICE_THREAD_H_