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_
|