File: performance_controls_hats_service.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (69 lines) | stat: -rw-r--r-- 2,595 bytes parent folder | download | duplicates (3)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_PERFORMANCE_CONTROLS_PERFORMANCE_CONTROLS_HATS_SERVICE_H_
#define CHROME_BROWSER_UI_PERFORMANCE_CONTROLS_PERFORMANCE_CONTROLS_HATS_SERVICE_H_

#include <optional>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.h"

class PerformanceControlsHatsService : public KeyedService {
 public:
  // Names of Product Specific Data bit entries.
  static constexpr char kBatterySaverPSDName[] = "Battery Saver Mode Enabled";
  static constexpr char kMemorySaverPSDName[] = "Memory Saver Mode Enabled";
  static constexpr char kUniformSamplePSDName[] = "Selected for Uniform Sample";

  // Names of Product Specific Data string entries.
  static constexpr char kChannelPSDName[] = "Channel";
  static constexpr char kPerformanceSegmentPSDName[] =
      "Performance Characteristics (OS and Total Memory)";

  explicit PerformanceControlsHatsService(Profile* profile);

  // Called when the user opens an NTP. This allows the service to check if one
  // of the performance controls surveys should be shown.
  void OpenedNewTabPage();

  // Returns the delay that must pass after the session starts before showing
  // the PPM survey.
  base::TimeDelta delay_before_ppm_survey() const {
    return delay_before_ppm_survey_;
  }

  // Lets tests override the random delay before showing the PPM survey.
  void SetDelayBeforePPMSurveyForTesting(base::TimeDelta delay) {
    delay_before_ppm_survey_ = delay;
  }

  // Overrides the amount of physical memory reported for testing.
  void SetAmountOfPhysicalMemoryMBForTesting(uint64_t memory_mb) {
    memory_mb_for_testing_ = memory_mb;
  }

 private:
  // Returns true if the PPM survey can be shown at this time.
  bool MayLaunchPPMSurvey() const;

  // Returns the name of the segment this client falls into for the PPM survey,
  // or an empty string if it doesn't fall into any defined survey segment.
  std::string GetPPMSurveySegmentName();

  raw_ptr<Profile> profile_;

  // Delay before showing the PPM UMA survey. Randomly generated when the
  // service is created.
  base::TimeDelta delay_before_ppm_survey_;

  // A value to use instead of calling base::SysInfo::AmountOfPhysicalMemoryMB()
  // in tests.
  std::optional<uint64_t> memory_mb_for_testing_;
};

#endif  // CHROME_BROWSER_UI_PERFORMANCE_CONTROLS_PERFORMANCE_CONTROLS_HATS_SERVICE_H_