File: main_thread_scheduler.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (130 lines) | stat: -rw-r--r-- 5,058 bytes parent folder | download | duplicates (9)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_MAIN_THREAD_SCHEDULER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_MAIN_THREAD_SCHEDULER_H_

#include <memory>

#include "base/functional/callback_forward.h"
#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/public/common/input/web_input_event_attribution.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {
class AgentGroupScheduler;

namespace scheduler {
class WebThreadScheduler;
}  // namespace scheduler

namespace test {
class TaskEnvironment;
}  // namespace test

class RAILModeObserver;

class ExecuteAfterCurrentTaskRestricted {
 private:
  // Permitted users of `ThreadScheduler::ExecuteAfterCurrentTaskForTesting()`.
  friend class DOMScheduler;

  ExecuteAfterCurrentTaskRestricted() = default;
};

// This class is used to submit tasks and pass other information from Blink to
// the platform's main thread scheduler.
class PLATFORM_EXPORT MainThreadScheduler : public ThreadScheduler {
 public:
  // RAII handle for pausing the renderer. Renderer is paused while
  // at least one pause handle exists.
  class PLATFORM_EXPORT RendererPauseHandle {
   public:
    RendererPauseHandle() = default;
    RendererPauseHandle(const RendererPauseHandle&) = delete;
    RendererPauseHandle& operator=(const RendererPauseHandle&) = delete;
    virtual ~RendererPauseHandle() = default;
  };

  // Tells the scheduler that the renderer process should be paused.
  // Pausing means that all javascript callbacks should not fire.
  // https://html.spec.whatwg.org/#pause
  //
  // Renderer will be resumed when the handle is destroyed.
  // Handle should be destroyed before the renderer.
  [[nodiscard]] virtual std::unique_ptr<RendererPauseHandle>
  PauseScheduler() = 0;

  // Returns a task runner which does not generate system wakeups on its own.
  // This means that if a delayed task is posted to it, it will run when
  // the delay expires AND another task runs.
  virtual scoped_refptr<base::SingleThreadTaskRunner> NonWakingTaskRunner() = 0;

  // Creates a AgentGroupScheduler implementation.
  virtual AgentGroupScheduler* CreateAgentGroupScheduler() = 0;

  // The current active AgentGroupScheduler is set when the task gets
  // started (i.e., OnTaskStarted) and unset when the task gets
  // finished (i.e., OnTaskCompleted). GetCurrentAgentGroupScheduler()
  // returns nullptr in task observers.
  virtual AgentGroupScheduler* GetCurrentAgentGroupScheduler() = 0;

  virtual void AddRAILModeObserver(RAILModeObserver* observer) = 0;

  virtual void RemoveRAILModeObserver(RAILModeObserver const* observer) = 0;

  // Calls the callback for each unique isolate that bound to the main thread.
  virtual void ForEachMainThreadIsolate(
      base::RepeatingCallback<void(v8::Isolate* isolate)> callback) = 0;

  // Returns a list of all unique attributions that are marked for event
  // dispatch. If |include_continuous| is true, include event types from
  // "continuous" sources (see PendingUserInput::IsContinuousEventTypes).
  virtual Vector<WebInputEventAttribution> GetPendingUserInputInfo(
      bool include_continuous) const {
    return {};
  }

  // Test helpers

  // Runs `on_completion_task` after the current task has finished.
  virtual void ExecuteAfterCurrentTaskForTesting(
      base::OnceClosure on_completion_task,
      ExecuteAfterCurrentTaskRestricted) = 0;

  // Starts an idle period, allowing pending idle tasks to run. Idle tasks can
  // only run within an idle period, which is determined based on compositor
  // signals. This method enables idle tasks to run in tests outside of a
  // detected idle period. The idle period ends once all idle tasks scheduled
  // before this method was called have run.
  virtual void StartIdlePeriodForTesting() = 0;

  // See WebThreadScheduler::SetRendererBackgrounded().
  virtual void SetRendererBackgroundedForTesting(bool backgrounded) = 0;

 private:
  // For `ToWebMainThreadScheduler`.
  friend class scheduler::WebThreadScheduler;

  // For `Isolate`.
  friend class ScopedMainThreadOverrider;
  friend class test::TaskEnvironment;

  // Get the isolate previously set with `SetV8Isolate`. This method is scoped
  // private so only friends can use it. Other users should use
  // `WebAgentGroupScheduler::Isolate` instead.
  virtual v8::Isolate* Isolate() = 0;

  // Return a reference to an underlying main thread WebThreadScheduler object.
  // This will be null if the `MainThreadScheduler` object doesn't support this,
  // which can happen in tests if not using a real scheduler.
  virtual scheduler::WebThreadScheduler* ToWebMainThreadScheduler() {
    return nullptr;
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_MAIN_THREAD_SCHEDULER_H_