Skip to content

Commit

Permalink
Add ScalableIph client side config
Browse files Browse the repository at this point in the history
- This is a first CL for adding client side config of ScalableIph. More
  config will be added with following CLs.

Bug: b:308010596
Test: na
Change-Id: I45b627063a39777122fd56543ad3b41d0d532966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4982366
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Commit-Queue: Yuki Awano <yawano@google.com>
Reviewed-by: Angela Xiao <angelaxiao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216476}
  • Loading branch information
Yuki Awano authored and Chromium LUCI CQ committed Oct 28, 2023
1 parent 9e2f74e commit 27dc06c
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 4 deletions.
18 changes: 18 additions & 0 deletions ash/constants/ash_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,16 @@ BASE_FEATURE(kScalableIphDebug,
"ScalableIphDebug",
base::FEATURE_DISABLED_BY_DEFAULT);

// Set all ScalableIph client side config to tracking only config.
BASE_FEATURE(kScalableIphTrackingOnly,
"ScalableIphTrackingOnly",
base::FEATURE_DISABLED_BY_DEFAULT);

// Use client side config.
BASE_FEATURE(kScalableIphClientConfig,
"ScalableIphClientConfig",
base::FEATURE_DISABLED_BY_DEFAULT);

// If enabled, the jelly colors will be used in the scanning app. Requires
// jelly-colors flag to also be enabled.
BASE_FEATURE(kScanningAppJelly,
Expand Down Expand Up @@ -4051,6 +4061,14 @@ bool IsScalableIphDebugEnabled() {
return base::FeatureList::IsEnabled(kScalableIphDebug);
}

bool IsScalableIphTrackingOnlyEnabled() {
return base::FeatureList::IsEnabled(kScalableIphTrackingOnly);
}

bool IsScalableIphClientConfigEnabled() {
return base::FeatureList::IsEnabled(kScalableIphClientConfig);
}

bool IsSeaPenEnabled() {
return base::FeatureList::IsEnabled(kSeaPen);
}
Expand Down
4 changes: 4 additions & 0 deletions ash/constants/ash_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ BASE_DECLARE_FEATURE(kResetShortcutCustomizations);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kSameAppWindowCycle);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScalableIph);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScalableIphDebug);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScalableIphTrackingOnly);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScalableIphClientConfig);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScanningAppJelly);
COMPONENT_EXPORT(ASH_CONSTANTS) BASE_DECLARE_FEATURE(kScreenSaverDuration);
COMPONENT_EXPORT(ASH_CONSTANTS)
Expand Down Expand Up @@ -1156,6 +1158,8 @@ COMPONENT_EXPORT(ASH_CONSTANTS)
bool IsSamlNotificationOnPasswordChangeSuccessEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsScalableIphEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsScalableIphDebugEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsScalableIphTrackingOnlyEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsScalableIphClientConfigEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsScreenSaverDurationEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsSeaPenEnabled();
COMPONENT_EXPORT(ASH_CONSTANTS) bool IsSeaPenTextInputEnabled();
Expand Down
16 changes: 15 additions & 1 deletion chromeos/ash/components/scalable_iph/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import("//chromeos/ash/components/scalable_iph/scalable_iph.gni")

assert(is_chromeos_ash)

source_set("config") {
sources = [
"config.cc",
"config.h",
]
deps = [
":scalable_iph_delegate",
"//ash/constants",
"//components/feature_engagement/public",
]
}

source_set("constants") {
sources = [
"scalable_iph_constants.cc",
Expand All @@ -22,6 +34,7 @@ source_set("scalable_iph") {
]

deps = [
":config",
":constants",
":iph_session",
":logger",
Expand Down Expand Up @@ -55,8 +68,9 @@ source_set("scalable_iph_delegate") {
deps = [
":constants",
":iph_session",
"//components/keyed_service/core",
]

public_deps = [ "//base" ]
}

source_set("logger") {
Expand Down
32 changes: 32 additions & 0 deletions chromeos/ash/components/scalable_iph/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.

#include "chromeos/ash/components/scalable_iph/config.h"

#include "ash/constants/ash_features.h"
#include "components/feature_engagement/public/feature_constants.h"

namespace scalable_iph {

Config::Config() = default;
Config::~Config() = default;

std::unique_ptr<Config> GetConfig(const base::Feature& feature) {
if (!ash::features::IsScalableIphClientConfigEnabled()) {
return nullptr;
}

if (&feature == &feature_engagement::kIPHScalableIphHelpAppBasedOneFeature) {
std::unique_ptr<Config> config = std::make_unique<Config>();
config->version_number = kCurrentVersionNumber;
config->ui_type = UiType::kNone;
return config;
}

// TODO(b/308010596): Move other config.

return nullptr;
}

} // namespace scalable_iph
25 changes: 25 additions & 0 deletions chromeos/ash/components/scalable_iph/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_CONFIG_H_
#define CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_CONFIG_H_

#include "chromeos/ash/components/scalable_iph/scalable_iph_delegate.h"

namespace scalable_iph {

struct Config {
Config();
~Config();
int version_number;
UiType ui_type;
std::unique_ptr<ScalableIphDelegate::NotificationParams> notification_params;
std::unique_ptr<ScalableIphDelegate::BubbleParams> bubble_params;
};

std::unique_ptr<Config> GetConfig(const base::Feature& feature);

} // namespace scalable_iph

#endif // CHROMEOS_ASH_COMPONENTS_SCALABLE_IPH_CONFIG_H_
42 changes: 39 additions & 3 deletions chromeos/ash/components/scalable_iph/scalable_iph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chromeos/ash/components/scalable_iph/config.h"
#include "chromeos/ash/components/scalable_iph/iph_session.h"
#include "chromeos/ash/components/scalable_iph/logger.h"
#include "chromeos/ash/components/scalable_iph/scalable_iph_constants.h"
Expand Down Expand Up @@ -276,6 +277,15 @@ UiType ParseUiType(Logger* logger, const base::Feature& feature) {
return UiType::kNone;
}

UiType GetUiType(Logger* logger, const base::Feature& feature) {
std::unique_ptr<Config> config = GetConfig(feature);
if (config) {
return config->ui_type;
}

return ParseUiType(logger, feature);
}

ActionType ParseActionType(const std::string& action_type_string) {
auto it = GetActionTypesMap().find(action_type_string);
if (it == GetActionTypesMap().end()) {
Expand Down Expand Up @@ -420,6 +430,17 @@ std::unique_ptr<NotificationParams> ParseNotificationParams(
return param;
}

std::unique_ptr<NotificationParams> GetNotificationParams(
Logger* logger,
const base::Feature& feature) {
std::unique_ptr<Config> config = GetConfig(feature);
if (config) {
return std::move(config->notification_params);
}

return ParseNotificationParams(logger, feature);
}

BubbleIcon ParseBubbleIcon(const std::string& icon_string) {
auto it = GetBubbleIconsMap().find(icon_string);
if (it == GetBubbleIconsMap().end()) {
Expand Down Expand Up @@ -490,7 +511,22 @@ std::unique_ptr<BubbleParams> ParseBubbleParams(Logger* logger,
return param;
}

std::unique_ptr<BubbleParams> GetBubbleParams(Logger* logger,
const base::Feature& feature) {
std::unique_ptr<Config> config = GetConfig(feature);
if (config) {
return std::move(config->bubble_params);
}

return ParseBubbleParams(logger, feature);
}

bool ValidateVersionNumber(const base::Feature& feature) {
std::unique_ptr<Config> config = GetConfig(feature);
if (config) {
return config->version_number == kCurrentVersionNumber;
}

std::string version_number_value =
GetParamValue(feature, kCustomParamsVersionNumberParamName);
if (version_number_value.empty()) {
Expand Down Expand Up @@ -861,11 +897,11 @@ void ScalableIph::CheckTriggerConditions(
"for "
<< feature->name;

UiType ui_type = ParseUiType(GetLogger(), *feature);
UiType ui_type = GetUiType(GetLogger(), *feature);
switch (ui_type) {
case UiType::kNotification: {
std::unique_ptr<NotificationParams> notification_params =
ParseNotificationParams(GetLogger(), *feature);
GetNotificationParams(GetLogger(), *feature);
if (!notification_params) {
SCALABLE_IPH_LOG(GetLogger())
<< "Failed to parse notification params for " << feature->name
Expand All @@ -880,7 +916,7 @@ void ScalableIph::CheckTriggerConditions(
}
case UiType::kBubble: {
std::unique_ptr<BubbleParams> bubble_params =
ParseBubbleParams(GetLogger(), *feature);
GetBubbleParams(GetLogger(), *feature);
if (!bubble_params) {
SCALABLE_IPH_LOG(GetLogger())
<< "Failed to parse bubble params for " << feature->name
Expand Down
15 changes: 15 additions & 0 deletions components/feature_engagement/public/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

if (is_chromeos) {
import("//build/config/chromeos/ui_mode.gni")
}

if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
Expand Down Expand Up @@ -62,6 +66,17 @@ source_set("public") {
"ios_promo_feature_configuration.h",
]
}

if (is_chromeos && is_chromeos_ash) {
sources += [
"scalable_iph_feature_configurations.cc",
"scalable_iph_feature_configurations.h",
]
deps += [
"//ash/constants",
"//chromeos/ash/components/scalable_iph:constants",
]
}
}

source_set("unit_tests") {
Expand Down
7 changes: 7 additions & 0 deletions components/feature_engagement/public/DEPS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
include_rules = [
"+components/feature_engagement/features.h",
]

specific_include_rules = {
"scalable_iph_feature_configurations.*": [
"+ash/constants/ash_features.h",
"+chromeos/ash/components/scalable_iph/scalable_iph_constants.h",
],
}
1 change: 1 addition & 0 deletions components/feature_engagement/public/OWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
per-file ios_promo_feature_configuration*=file://ios/chrome/browser/promos_manager/OWNERS
per-file scalable_iph_feature_configurations*=file://chromeos/ash/components/scalable_iph/OWNERS
10 changes: 10 additions & 0 deletions components/feature_engagement/public/feature_configurations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#if BUILDFLAG(IS_IOS)
#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)
Expand Down Expand Up @@ -1872,6 +1875,13 @@ absl::optional<FeatureConfig> GetClientSideFeatureConfig(
}
#endif // BUILDFLAG(IS_IOS)

#if BUILDFLAG(IS_CHROMEOS_ASH)
if (absl::optional<FeatureConfig> scalable_iph_feature_config =
GetScalableIphFeatureConfig(feature)) {
return scalable_iph_feature_config;
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

if (kIPHDummyFeature.name == feature->name) {
// Only used for tests. Various magic tricks are used below to ensure this
// config is invalid and unusable.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.

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

#include "ash/constants/ash_features.h"
#include "chromeos/ash/components/scalable_iph/scalable_iph_constants.h"
#include "components/feature_engagement/public/configuration.h"
#include "components/feature_engagement/public/feature_constants.h"

namespace feature_engagement {
namespace {
absl::optional<FeatureConfig> GetBaseConfig() {
absl::optional<FeatureConfig> config = FeatureConfig();
config->valid = true;
config->availability = Comparator(ANY, 0);
config->session_rate = Comparator(ANY, 0);
config->session_rate_impact.type = SessionRateImpact::Type::NONE;
config->blocked_by.type = BlockedBy::Type::NONE;
config->blocking.type = Blocking::Type::NONE;
return config;
}

bool IsTrackingOnly() {
return ash::features::IsScalableIphTrackingOnlyEnabled();
}
} // namespace

absl::optional<FeatureConfig> GetScalableIphFeatureConfig(
const base::Feature* feature) {
if (!ash::features::IsScalableIphClientConfigEnabled()) {
return absl::nullopt;
}

if (kIPHScalableIphHelpAppBasedOneFeature.name == feature->name) {
absl::optional<FeatureConfig> config = GetBaseConfig();
config->used =
EventConfig(scalable_iph::kEventNameHelpAppActionTypeOpenChrome,
Comparator(ANY, 0), 7, 8);
config->trigger = EventConfig("ScalableIphHelpAppBasedOneTriggerNotUsed",
Comparator(EQUAL, 0), 7, 8);

config->tracking_only = IsTrackingOnly();
return config;
}

// TODO(b/308010596): Move other config.

return absl::nullopt;
}

} // namespace feature_engagement
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 COMPONENTS_FEATURE_ENGAGEMENT_PUBLIC_SCALABLE_IPH_FEATURE_CONFIGURATIONS_H_
#define COMPONENTS_FEATURE_ENGAGEMENT_PUBLIC_SCALABLE_IPH_FEATURE_CONFIGURATIONS_H_

#include "base/feature_list.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace feature_engagement {

struct FeatureConfig;

absl::optional<FeatureConfig> GetScalableIphFeatureConfig(
const base::Feature* feature);

} // namespace feature_engagement

#endif // COMPONENTS_FEATURE_ENGAGEMENT_PUBLIC_SCALABLE_IPH_FEATURE_CONFIGURATIONS_H_

0 comments on commit 27dc06c

Please sign in to comment.