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
|
// 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 CHROME_BROWSER_GLIC_HOST_GLIC_SYNTHETIC_TRIAL_MANAGER_H_
#define CHROME_BROWSER_GLIC_HOST_GLIC_SYNTHETIC_TRIAL_MANAGER_H_
#include <string>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/metrics/metrics_logs_event_manager.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/variations/synthetic_trial_registry.h"
namespace glic {
class GlicSyntheticTrialManager : metrics::MetricsLogsEventManager::Observer {
public:
explicit GlicSyntheticTrialManager(
metrics_services_manager::MetricsServicesManager*
metrics_services_manager);
GlicSyntheticTrialManager(const GlicSyntheticTrialManager&) = delete;
GlicSyntheticTrialManager& operator=(const GlicSyntheticTrialManager&) =
delete;
~GlicSyntheticTrialManager() override;
// Used by the web client to enroll Chrome in the specified synthetic trial
// group. If a conflicting group is already registered by another profile
// than we instead register into a new group called `MultiProfileDetected` to
// indicate the log file is corrupted. At this point we stage the requested
// group for enrollment when the next log file is created.
void SetSyntheticExperimentState(const std::string& trial_name,
const std::string& group_name);
// metrics::MetricsLogsEventManager::Observer:
void OnLogEvent(metrics::MetricsLogsEventManager::LogEvent event,
std::string_view log_hash,
std::string_view message) override;
void OnLogCreated(
std::string_view log_hash,
std::string_view log_data,
std::string_view log_timestamp,
metrics::MetricsLogsEventManager::CreateReason reason) override {}
private:
std::map<std::string, std::string> synthetic_field_trial_groups_;
std::map<std::string, std::string> staged_synthetic_field_trial_groups_;
raw_ptr<metrics::MetricsService> metrics_service_;
const raw_ptr<metrics_services_manager::MetricsServicesManager>
metrics_services_manager_;
base::WeakPtrFactory<GlicSyntheticTrialManager> weak_ptr_factory_{this};
};
} // namespace glic
#endif // CHROME_BROWSER_GLIC_HOST_GLIC_SYNTHETIC_TRIAL_MANAGER_H_
|