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
|
// 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_SAFE_BROWSING_EXTENSION_TELEMETRY_EXTENSION_TELEMETRY_CONFIG_MANAGER_H_
#define CHROME_BROWSER_SAFE_BROWSING_EXTENSION_TELEMETRY_EXTENSION_TELEMETRY_CONFIG_MANAGER_H_
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "extensions/common/extension_id.h"
class PrefService;
namespace safe_browsing {
enum class ExtensionSignalType;
class ExtensionTelemetryReportResponse_Configuration;
// The ExtensionTelemetryConfigManager manages the configuration of the
// Extension Telemetry Service. Configuration data includes items such as:
// - how often telemetry reports are uploaded
// - how often telemetry reports are persisted to disk
// - which extensions and signals are to be included in telemetry
// reports
// ExtensionTelemetryConfigManager persists the configuration data using
// Chrome's pref service. It also provides methods to look up this data.
// This object is instantiated and owned by the ExtensionTelemetryService
// and lives on the Browser UI thread.
class ExtensionTelemetryConfigManager {
public:
explicit ExtensionTelemetryConfigManager(PrefService* pref_service);
ExtensionTelemetryConfigManager(const ExtensionTelemetryConfigManager&) =
delete;
ExtensionTelemetryConfigManager& operator=(
const ExtensionTelemetryConfigManager&) = delete;
virtual ~ExtensionTelemetryConfigManager();
// Loads telemetry configuration data from prefs into its own internal
// copy. If there is no configuration data present, the internal copy
// becomes/remains empty. All configuration getters return default
// values.
void LoadConfig();
// The telemetry configuration is sent by a telemetry server in response
// to an uploaded telemetry report. The ExtensionTelemetryService calls
// this method to pass the response protobuf to the
// ExtensionTelemetryConfigManager. If the protobuf has a newer
// version than the currently saved config, it extracts the
// configuration data and persists it in Chrome's pref service.
// A copy of the configuration data is also kept in an internal member.
void SaveConfig(
const ExtensionTelemetryReportResponse_Configuration& telemetry_config);
// Determines if the specified signal_type should be processed for the
// specified extension. Returns true if no configuration data has been
// saved.
bool IsSignalEnabled(const extensions::ExtensionId& extension_id,
ExtensionSignalType signal_type) const;
// Returns the writes per interval determined by the current
// configuration or a default value if no configuration data has been
// saved.
uint32_t GetWritesPerInterval() const;
// Returns the reporting interval determined by the current
// configuration or a default value if no configuration data has been
// saved.
uint32_t GetReportingInterval() const;
// Returns the config version determined by the current
// configuration or a default value if no configuration data has been
// saved.
uint32_t GetConfigVersion() const;
// Returns the signal enables bitmask for the `extension_id` determined
// by the current configuration or a default value if no configuration
// data has been saved.
uint64_t GetSignalEnables(const extensions::ExtensionId& extension_id) const;
private:
// Holds string values that map to the configurable Extension Telemetry
// Service variables. Packed into a base::Value::Dict so it can be
// stored in Chrome prefs.
base::Value::Dict configuration_;
// ExtensionTelemetryConfigManager uses the pref service to store
// the telemetry config.
raw_ptr<PrefService> pref_service_;
};
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_EXTENSION_TELEMETRY_EXTENSION_TELEMETRY_CONFIG_MANAGER_H_
|