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
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/growth/campaigns_configuration_provider.h"
#include <cstring>
#include <string>
#include "ash/constants/ash_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "chromeos/ash/components/growth/campaigns_utils.h"
#include "components/feature_engagement/public/configuration.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/feature_list.h"
#include "components/feature_engagement/public/field_trial_utils.h"
#include "components/feature_engagement/public/group_list.h"
namespace growth {
namespace {
constexpr char kGrowthFramework[] = "ChromeOS Growth Framework";
constexpr char kGrowthCampaignsEventUsed[] =
"ChromeOSAshGrowthCampaigns_EventUsed";
constexpr char kGrowthCampaignsEventTrigger[] =
"ChromeOSAshGrowthCampaigns_EventTrigger";
feature_engagement::FeatureConfig CreateEmptyConfig() {
feature_engagement::FeatureConfig config;
config.valid = true;
config.availability =
feature_engagement::Comparator(feature_engagement::ANY, 0);
config.session_rate =
feature_engagement::Comparator(feature_engagement::ANY, 0);
config.used = feature_engagement::EventConfig(
kGrowthCampaignsEventUsed,
feature_engagement::Comparator(feature_engagement::ANY, 0), 0, 0);
config.trigger = feature_engagement::EventConfig(
kGrowthCampaignsEventTrigger,
feature_engagement::Comparator(feature_engagement::ANY, 0), 0, 0);
return config;
}
bool HasDebugClearEventsSwitch() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
ash::switches::kGrowthCampaignsClearEventsAtSessionStart);
}
} // namespace
CampaignsConfigurationProvider::CampaignsConfigurationProvider() {
SetConfig(CreateEmptyConfig());
}
CampaignsConfigurationProvider::~CampaignsConfigurationProvider() = default;
bool CampaignsConfigurationProvider::MaybeProvideFeatureConfiguration(
const base::Feature& feature,
feature_engagement::FeatureConfig& config,
const feature_engagement::FeatureVector& known_features,
const feature_engagement::GroupVector& known_groups) const {
// Skip if it is not growth framework feature.
if (UNSAFE_TODO(std::strcmp((&feature_engagement::kIPHGrowthFramework)->name,
feature.name))) {
return false;
}
// TODO: b/330533766 - Implement the matching logic.
config = config_;
return true;
}
const char* CampaignsConfigurationProvider::GetConfigurationSourceDescription()
const {
return kGrowthFramework;
}
std::set<std::string>
CampaignsConfigurationProvider::MaybeProvideAllowedEventPrefixes(
const base::Feature& feature) const {
if (UNSAFE_TODO(std::strcmp((&feature_engagement::kIPHGrowthFramework)->name,
feature.name))) {
return {};
}
// By returning empty prefixes, the `feature engagement` component will
// clear all events with the `kGrowthCampaignsEventNamePrefix` and prevent
// evaluating/recording the events with the prefix.
// NOTE: To make growth framework events targeting work, need to remove the
// debugging switch and restart the device again.
if (HasDebugClearEventsSwitch()) {
return {};
} else {
return {std::string(growth::GetGrowthCampaignsEventNamePrefix())};
}
}
void CampaignsConfigurationProvider::SetConfig(
std::map<std::string, std::string> params) {
config_ = feature_engagement::FeatureConfig();
uint32_t parse_errors = 0;
feature_engagement::ConfigParseOutput output(parse_errors);
output.trigger = &config_.trigger;
output.used = &config_.used;
output.event_configs = &config_.event_configs;
feature_engagement::ParseConfigFields(
&feature_engagement::kIPHGrowthFramework, params, output,
/*known_features=*/{},
/*known_groups=*/{});
config_.valid = parse_errors == 0;
}
void CampaignsConfigurationProvider::SetConfig(
const feature_engagement::FeatureConfig& config) {
config_ = config;
}
} // namespace growth
|