chromium/components/feature_engagement/public/feature_configurations.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/feature_engagement/public/feature_configurations.h"

#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "components/feature_engagement/public/configuration.h"
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/feature_constants.h"

#if BUILDFLAG(IS_IOS)
#include "base/metrics/field_trial_params.h"
#include "components/feature_engagement/public/ios_promo_feature_configuration.h"
#endif  // BUILDFLAG(IS_IOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/feature_engagement/public/scalable_iph_feature_configurations.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
const int k10YearsInDays = 365 * 10;
#endif
}  // namespace

namespace feature_engagement {

FeatureConfig CreateAlwaysTriggerConfig(const base::Feature* feature) {}

#if BUILDFLAG(IS_IOS)
std::optional<FeatureConfig> CreateNewUserGestureInProductHelpConfig(
    const base::Feature& feature,
    const char* action_event,
    const char* trigger_event,
    const char* used_event,
    const char* dismiss_button_tap_event) {
  // Maximum storage days for iOS gesture IPHs in days. Note that they only
  // triggered for users who installed Chrome on iOS in the last specific number
  // of days, so this could be used as the maximum storage period of respective
  // events.
  const int kTotalMaxOccurrences = 2;
  const uint32_t kMaxStorageDays = 61;
  // The IPH only shows once a week, and honors `kTotalMaxOccurrences`.
  const int kDaysBetweenOccurrences = 7;

  std::optional<FeatureConfig> config = FeatureConfig();
  config->valid = true;
  config->availability = Comparator(ANY, 0);
  config->session_rate = Comparator(EQUAL, 0);
  // The user hasn't done the action suggested by the IPH.
  config->used = EventConfig(used_event, Comparator(EQUAL, 0), kMaxStorageDays,
                             kMaxStorageDays);
  // The IPH shows at most once per `kDaysBetweenOccurrences`.
  config->trigger =
      EventConfig(trigger_event, Comparator(EQUAL, 0), kDaysBetweenOccurrences,
                  kDaysBetweenOccurrences);
  config->event_configs.insert(
      EventConfig(trigger_event, Comparator(LESS_THAN, kTotalMaxOccurrences),
                  kMaxStorageDays, kMaxStorageDays));
  // The IPH only shows when user performs the action that should trigger the
  // IPH at least twice since the last time the IPH shows, or since installation
  // if it hasn't.
  config->event_configs.insert(
      EventConfig(action_event, Comparator(GREATER_THAN_OR_EQUAL, 2),
                  kDaysBetweenOccurrences, kDaysBetweenOccurrences));
  // The user hasn't explicitly dismissed the same IPH before.
  config->event_configs.insert(EventConfig(dismiss_button_tap_event,
                                           Comparator(EQUAL, 0),
                                           kMaxStorageDays, kMaxStorageDays));
  return config;
}
#endif

std::optional<FeatureConfig> GetClientSideFeatureConfig(
    const base::Feature* feature) {}

}  // namespace feature_engagement