File: process_performance_scenarios.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (103 lines) | stat: -rw-r--r-- 4,210 bytes parent folder | download | duplicates (4)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_SCENARIOS_PROCESS_PERFORMANCE_SCENARIOS_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_SCENARIOS_PROCESS_PERFORMANCE_SCENARIOS_H_

#include "base/observer_list.h"
#include "base/scoped_observation_traits.h"
#include "components/performance_manager/scenario_api/performance_scenarios.h"

namespace performance_scenarios {
class MatchingScenarioObserver;
class PerformanceScenarioObserver;
}  // namespace performance_scenarios

namespace performance_manager {

class ProcessNode;

// Functions to let the browser process query the performance scenarios for a
// child process. These are similar to functions in
// components/performance_manager/scenario_api/performance_scenarios.h, but have
// extra performance_manager dependencies.
//
// These functions all take a ProcessNode, and read the scenario values that are
// visible for ScenarioScope::kCurrentProcess in that process. Scenario values
// that are visible for ScenarioScope::kGlobal are the same in all processes, so
// can be read in the browser process using the API in performance_scenarios.h.
//
// All functions must be called on the UI thread. They return scenario values
// directly instead of `scenario_api::SharedAtomicRef` because the browser
// process updates scenario memory on the UI thread, so it won't change
// unexpectedly.

// Returns the current LoadingScenario for `process`.
performance_scenarios::LoadingScenario GetProcessLoadingScenario(
    const ProcessNode* process);

// Returns the current InputScenario for `process`.
performance_scenarios::InputScenario GetProcessInputScenario(
    const ProcessNode* process);

// Returns true if the current scenarios for `process` match `pattern`.
bool CurrentProcessScenariosMatch(
    const ProcessNode* process,
    performance_scenarios::ScenarioPattern pattern);

// Returns a list of PerformanceScenarioObservers for `process` that will be
// notified when the scenarios for that process change. The list is only valid
// as long as the ProcessNode exists.
base::ObserverList<performance_scenarios::PerformanceScenarioObserver>&
GetScenarioObserversForProcess(const ProcessNode* process);

// Returns a list of MatchingScenarioObservers for `process` that will be
// notified when the scenarios for that process change to start or stop
// matching a scenario pattern. The list is only valid as long as the
// ProcessNode exists.
base::ObserverList<performance_scenarios::MatchingScenarioObserver>&
GetMatchingScenarioObserversForProcess(const ProcessNode* process);

}  // namespace performance_manager

namespace base {

// Specialize ScopedObservation to look up the observer lists for a ProcessNode.
// These must be in the same namespace as base::ScopedObservationTraits.

template <>
struct ScopedObservationTraits<
    performance_manager::ProcessNode,
    performance_scenarios::PerformanceScenarioObserver> {
  static void AddObserver(
      const performance_manager::ProcessNode* source,
      performance_scenarios::PerformanceScenarioObserver* observer) {
    GetScenarioObserversForProcess(source).AddObserver(observer);
  }
  static void RemoveObserver(
      const performance_manager::ProcessNode* source,
      performance_scenarios::PerformanceScenarioObserver* observer) {
    GetScenarioObserversForProcess(source).RemoveObserver(observer);
  }
};

template <>
struct ScopedObservationTraits<
    performance_manager::ProcessNode,
    performance_scenarios::MatchingScenarioObserver> {
  static void AddObserver(
      const performance_manager::ProcessNode* source,
      performance_scenarios::MatchingScenarioObserver* observer) {
    GetMatchingScenarioObserversForProcess(source).AddObserver(observer);
  }
  static void RemoveObserver(
      const performance_manager::ProcessNode* source,
      performance_scenarios::MatchingScenarioObserver* observer) {
    GetMatchingScenarioObserversForProcess(source).RemoveObserver(observer);
  }
};

}  // namespace base

#endif  // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_SCENARIOS_PROCESS_PERFORMANCE_SCENARIOS_H_