File: prefs.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 (155 lines) | stat: -rw-r--r-- 5,795 bytes parent folder | download | duplicates (5)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// 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 COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_USER_TUNING_PREFS_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_USER_TUNING_PREFS_H_

#include <string>
#include <vector>

#include "base/time/time.h"
#include "base/timer/timer.h"

class PrefRegistrySimple;
class PrefService;

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace performance_manager::user_tuning::prefs {

// DEPRECATED: being replaced by kMemorySaverModeState
inline constexpr char kMemorySaverModeEnabled[] =
    "performance_tuning.high_efficiency_mode.enabled";

enum class MemorySaverModeState {
  kDisabled = 0,
  // This option is now deprecated. It was only ever available behind an
  // unlaunched experiment.
  kDeprecated = 1,
  kEnabled = 2,
};

inline constexpr char kMemorySaverModeState[] =
    "performance_tuning.high_efficiency_mode.state";

inline constexpr char kMemorySaverModeTimeBeforeDiscardInMinutes[] =
    "performance_tuning.high_efficiency_mode.time_before_discard_in_minutes";

constexpr int kDefaultMemorySaverModeTimeBeforeDiscardInMinutes = 120;

enum class MemorySaverModeAggressiveness {
  kConservative = 0,
  kMedium = 1,
  kAggressive = 2,
  kMaxValue = kAggressive,
};

inline constexpr char kMemorySaverModeAggressiveness[] =
    "performance_tuning.high_efficiency_mode.aggressiveness";

enum class BatterySaverModeState {
  kDisabled = 0,
  kEnabledBelowThreshold = 1,
  kEnabledOnBattery = 2,
  kEnabled = 3,
};

inline constexpr char kBatterySaverModeState[] =
    "performance_tuning.battery_saver_mode.state";

// Stores the timestamp of the last battery usage while unplugged.
inline constexpr char kLastBatteryUseTimestamp[] =
    "performance_tuning.last_battery_use.timestamp";

// The pref storing the list of URL patterns that prevent a tab from being
// discarded.
inline constexpr char kTabDiscardingExceptions[] =
    "performance_tuning.tab_discarding.exceptions";

// The pref storing the list of URL patterns that prevent a tab from being
// discarded.
inline constexpr char kTabDiscardingExceptionsWithTime[] =
    "performance_tuning.tab_discarding.exceptions_with_time";

// The pref storing the enterprise-managed list of URL patterns that prevent a
// tab from being discarded. This list is merged with
// `kTabDiscardingExceptions`.
inline constexpr char kManagedTabDiscardingExceptions[] =
    "performance_tuning.tab_discarding.exceptions_managed";

// The pref storing whether the discard ring treatment should appear around
// favicons on tabs.
inline constexpr char kDiscardRingTreatmentEnabled[] =
    "performance_tuning.discard_ring_treatment.enabled";

// The pref storing whether performance intervention notifications should be
// shown.
inline constexpr char kPerformanceInterventionNotificationEnabled[] =
    "performance_tuning.intervention_notification.enabled";

// The pref storing when was the last time the performance intervention
// notification was shown.
inline constexpr char kPerformanceInterventionNotificationLastShown[] =
    "performance_tuning.intervention_notification.last_shown";

// The pref storing a boolean list which keeps track whether the user has
// accepted performance intervention with a true value and false if the
// intervention was rejected. This is the second version of this pref
// because the first was deprecated for saving inaccurate entries.
inline constexpr char kPerformanceInterventionNotificationAcceptHistory[] =
    "performance_tuning.intervention_notification.accept_history2";

void RegisterLocalStatePrefs(PrefRegistrySimple* registry);

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

MemorySaverModeState GetCurrentMemorySaverModeState(PrefService* pref_service);

MemorySaverModeAggressiveness GetCurrentMemorySaverMode(
    PrefService* pref_service);

base::TimeDelta GetCurrentMemorySaverModeTimeBeforeDiscard(
    PrefService* pref_service);

BatterySaverModeState GetCurrentBatterySaverModeState(
    PrefService* pref_service);

bool ShouldShowDiscardRingTreatment(PrefService* pref_service);

bool ShouldShowPerformanceInterventionNotification(PrefService* pref_service);

// This function migrates the old, boolean Memory Saver preference to the new,
// integer one that represents a value of the `MemorySaverModeState` enum. This
// is done once at startup.
void MigrateMemorySaverModePref(PrefService* pref_service);

// This function migrates the kDeprecated state to kEnabled. During previous
// experimentation, this state represented an option to use a heuristic version
// of Memory Saver. But this mode got migrated in to what is now called
// KEnabled.
void MigrateMultiStateMemorySaverModePref(PrefService* pref_service);

// Returns if the given site is in the discard exception list
bool IsSiteInTabDiscardExceptionsList(PrefService* pref_service,
                                      const std::string& site);

// Adds the given site to the discard exception list
void AddSiteToTabDiscardExceptionsList(PrefService* pref_service,
                                       const std::string& site);

// Returns a list of tab discard exception patterns during the time range.
std::vector<std::string> GetTabDiscardExceptionsBetween(
    PrefService* pref_service,
    base::Time period_start,
    base::Time period_end);

// Clears all discard exception prefs modified or created during the time range.
void ClearTabDiscardExceptions(PrefService* pref_service,
                               base::Time delete_begin,
                               base::Time delete_end);
}  // namespace performance_manager::user_tuning::prefs

#endif  // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_USER_TUNING_PREFS_H_