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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
|
// 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.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/390223051): Remove C-library calls to fix the errors.
#pragma allow_unsafe_libc_calls
#endif
#include "components/segmentation_platform/embedder/home_modules/home_modules_card_registry.h"
#include <string_view>
#include "base/containers/contains.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_split.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/segmentation_platform/embedder/home_modules/auxiliary_search_promo.h"
#include "components/segmentation_platform/embedder/home_modules/card_selection_info.h"
#include "components/segmentation_platform/embedder/home_modules/constants.h"
#include "components/segmentation_platform/embedder/home_modules/default_browser_promo.h"
#include "components/segmentation_platform/embedder/home_modules/ephemeral_module_utils.h"
#include "components/segmentation_platform/embedder/home_modules/history_sync_promo.h"
#include "components/segmentation_platform/embedder/home_modules/price_tracking_notification_promo.h"
#include "components/segmentation_platform/embedder/home_modules/quick_delete_promo.h"
#include "components/segmentation_platform/embedder/home_modules/send_tab_notification_promo.h"
#include "components/segmentation_platform/embedder/home_modules/tab_group_promo.h"
#include "components/segmentation_platform/embedder/home_modules/tab_group_sync_promo.h"
#include "components/segmentation_platform/embedder/home_modules/tips_manager/constants.h"
#include "components/segmentation_platform/public/constants.h"
#include "components/segmentation_platform/public/features.h"
#if BUILDFLAG(IS_IOS)
#include "components/segmentation_platform/embedder/home_modules/address_bar_position_ephemeral_module.h"
#include "components/segmentation_platform/embedder/home_modules/autofill_passwords_ephemeral_module.h"
#include "components/segmentation_platform/embedder/home_modules/enhanced_safe_browsing_ephemeral_module.h"
#include "components/segmentation_platform/embedder/home_modules/ephemeral_module_utils.h"
#include "components/segmentation_platform/embedder/home_modules/lens_ephemeral_module.h"
#include "components/segmentation_platform/embedder/home_modules/save_passwords_ephemeral_module.h"
#endif
namespace segmentation_platform::home_modules {
#if BUILDFLAG(IS_ANDROID)
const char kAuxiliarySearchPromoImpressionCounterPref[] =
"ephemeral_pref_counter.auxiliary_search_promo_counter";
const char kAuxiliarySearchPromoInteractedPref[] =
"ephemeral_pref_interacted.auxiliary_search_promo_interacted";
const char kDefaultBrowserPromoImpressionCounterPref[] =
"ephemeral_pref_counter.default_browser_promo_counter";
const char kDefaultBrowserPromoInteractedPref[] =
"ephemeral_pref_interacted.default_browser_promo_interacted";
const char kTabGroupPromoImpressionCounterPref[] =
"ephemeral_pref_counter.tab_group_promo_counter";
const char kTabGroupPromoInteractedPref[] =
"ephemeral_pref_interacted.tab_group_promo_interacted";
const char kTabGroupSyncPromoImpressionCounterPref[] =
"ephemeral_pref_counter.tab_group_sync_promo_counter";
const char kTabGroupSyncPromoInteractedPref[] =
"ephemeral_pref_interacted.tab_group_sync_promo_interacted";
const char kQuickDeletePromoImpressionCounterPref[] =
"ephemeral_pref_counter.quick_delete_promo_counter";
const char kQuickDeletePromoInteractedPref[] =
"ephemeral_pref_interacted.quick_delete_promo_interacted";
const char kHistorySyncPromoImpressionCounterPref[] =
"ephemeral_pref_counter.history_sync_promo_counter";
const char kHistorySyncPromoInteractedPref[] =
"ephemeral_pref_interacted.history_sync_promo_interacted";
#endif
namespace {
#if BUILDFLAG(IS_IOS)
// Impression counter for the Price Tracking notification promo card.
const char kPriceTrackingPromoImpressionCounterPref[] =
"ephemeral_pref_counter.price_tracking_promo_counter";
// Impression counter for the Address Bar Position ephemeral module.
const char kAddressBarPositionEphemeralModuleImpressionCounterPref[] =
"ephemeral_pref_counter.address_bar_position_ephemeral_module_counter";
// Impression counter for the Autofill Passwords ephemeral module.
const char kAutofillPasswordsEphemeralModuleImpressionCounterPref[] =
"ephemeral_pref_counter.autofill_passwords_ephemeral_module_counter";
// Impression counter for the Enhanced Safe Browsing ephemeral module.
const char kEnhancedSafeBrowsingEphemeralModuleImpressionCounterPref[] =
"ephemeral_pref_counter.enhanced_safe_browsing_ephemeral_module_counter";
// Impression counter for the Save Passwords ephemeral module.
const char kSavePasswordsEphemeralModuleImpressionCounterPref[] =
"ephemeral_pref_counter.save_passwords_ephemeral_module_counter";
// Impression counter for the Lens ephemeral module.
const char kLensEphemeralModuleImpressionCounterPref[] =
"ephemeral_pref_counter.lens_ephemeral_module_counter";
// Impression counter for the Send Tab ephemeral module.
const char kSendTabPromoImpressionCounterPref[] =
"ephemeral_pref_counter.send_tab_promo_counter";
// Creates a card corresponding to the given ephemeral `tip` module and adds
// it to the `cards` list if the module is enabled.
void AddCardForTip(TipIdentifier tip,
std::vector<std::unique_ptr<CardSelectionInfo>>& cards,
PrefService* prefs) {
switch (tip) {
case TipIdentifier::kUnknown:
return; // Do nothing for unknown tips
case TipIdentifier::kLensSearch:
case TipIdentifier::kLensShop:
case TipIdentifier::kLensTranslate: {
int impression_count =
prefs->GetInteger(kLensEphemeralModuleImpressionCounterPref);
if (LensEphemeralModule::IsEnabled(impression_count)) {
cards.push_back(std::make_unique<LensEphemeralModule>(prefs));
}
break;
}
case TipIdentifier::kAddressBarPosition: {
int impression_count = prefs->GetInteger(
kAddressBarPositionEphemeralModuleImpressionCounterPref);
if (AddressBarPositionEphemeralModule::IsEnabled(impression_count)) {
cards.push_back(
std::make_unique<AddressBarPositionEphemeralModule>(prefs));
}
break;
}
case TipIdentifier::kSavePasswords: {
int impression_count =
prefs->GetInteger(kSavePasswordsEphemeralModuleImpressionCounterPref);
if (SavePasswordsEphemeralModule::IsEnabled(impression_count)) {
cards.push_back(std::make_unique<SavePasswordsEphemeralModule>(prefs));
}
break;
}
case TipIdentifier::kAutofillPasswords: {
int impression_count = prefs->GetInteger(
kAutofillPasswordsEphemeralModuleImpressionCounterPref);
if (AutofillPasswordsEphemeralModule::IsEnabled(impression_count)) {
cards.push_back(
std::make_unique<AutofillPasswordsEphemeralModule>(prefs));
}
break;
}
case TipIdentifier::kEnhancedSafeBrowsing: {
int impression_count = prefs->GetInteger(
kEnhancedSafeBrowsingEphemeralModuleImpressionCounterPref);
if (EnhancedSafeBrowsingEphemeralModule::IsEnabled(impression_count)) {
cards.push_back(
std::make_unique<EnhancedSafeBrowsingEphemeralModule>(prefs));
}
break;
}
}
}
#endif
} // namespace
HomeModulesCardRegistry::HomeModulesCardRegistry(PrefService* profile_prefs)
: profile_prefs_(profile_prefs) {
CreateAllCards();
}
HomeModulesCardRegistry::HomeModulesCardRegistry(
PrefService* profile_prefs,
std::vector<std::unique_ptr<CardSelectionInfo>> cards)
: profile_prefs_(profile_prefs) {
all_cards_by_priority_.swap(cards);
InitializeAfterAddingCards();
}
HomeModulesCardRegistry::~HomeModulesCardRegistry() = default;
// static
void HomeModulesCardRegistry::RegisterProfilePrefs(
PrefRegistrySimple* registry) {
#if BUILDFLAG(IS_IOS)
registry->RegisterIntegerPref(kPriceTrackingPromoImpressionCounterPref, 0);
registry->RegisterIntegerPref(kSendTabPromoImpressionCounterPref, 0);
registry->RegisterIntegerPref(
kAddressBarPositionEphemeralModuleImpressionCounterPref, 0);
registry->RegisterIntegerPref(
kAutofillPasswordsEphemeralModuleImpressionCounterPref, 0);
registry->RegisterIntegerPref(
kEnhancedSafeBrowsingEphemeralModuleImpressionCounterPref, 0);
registry->RegisterIntegerPref(
kSavePasswordsEphemeralModuleImpressionCounterPref, 0);
registry->RegisterIntegerPref(kLensEphemeralModuleImpressionCounterPref, 0);
registry->RegisterBooleanPref(
kAddressBarPositionEphemeralModuleInteractedPref, false);
registry->RegisterBooleanPref(kAutofillPasswordsEphemeralModuleInteractedPref,
false);
registry->RegisterBooleanPref(
kEnhancedSafeBrowsingEphemeralModuleInteractedPref, false);
registry->RegisterBooleanPref(kSavePasswordsEphemeralModuleInteractedPref,
false);
registry->RegisterBooleanPref(kLensEphemeralModuleInteractedPref, false);
registry->RegisterBooleanPref(
kLensEphemeralModuleSearchVariationInteractedPref, false);
registry->RegisterBooleanPref(kLensEphemeralModuleShopVariationInteractedPref,
false);
registry->RegisterBooleanPref(
kLensEphemeralModuleTranslateVariationInteractedPref, false);
#endif
#if BUILDFLAG(IS_ANDROID)
registry->RegisterIntegerPref(kAuxiliarySearchPromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kAuxiliarySearchPromoInteractedPref, false);
registry->RegisterIntegerPref(kDefaultBrowserPromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kDefaultBrowserPromoInteractedPref, false);
registry->RegisterIntegerPref(kTabGroupPromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kTabGroupPromoInteractedPref, false);
registry->RegisterIntegerPref(kTabGroupSyncPromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kTabGroupSyncPromoInteractedPref, false);
registry->RegisterIntegerPref(kQuickDeletePromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kQuickDeletePromoInteractedPref, false);
registry->RegisterIntegerPref(kHistorySyncPromoImpressionCounterPref, 0);
registry->RegisterBooleanPref(kHistorySyncPromoInteractedPref, false);
#endif
}
// static
bool HomeModulesCardRegistry::IsEphemeralTipsModuleLabel(
std::string_view label) {
#if BUILDFLAG(IS_IOS)
return AddressBarPositionEphemeralModule::IsModuleLabel(label) ||
AutofillPasswordsEphemeralModule::IsModuleLabel(label) ||
EnhancedSafeBrowsingEphemeralModule::IsModuleLabel(label) ||
SavePasswordsEphemeralModule::IsModuleLabel(label) ||
LensEphemeralModule::IsModuleLabel(label);
#else
return false;
#endif
}
void HomeModulesCardRegistry::NotifyCardShown(const char* card_name) {
#if BUILDFLAG(IS_IOS)
if (strcmp(card_name, kPriceTrackingNotificationPromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kPriceTrackingPromoImpressionCounterPref);
profile_prefs_->SetInteger(kPriceTrackingPromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kAddressBarPositionEphemeralModule) == 0) {
int freshness_impression_count = profile_prefs_->GetInteger(
kAddressBarPositionEphemeralModuleImpressionCounterPref);
profile_prefs_->SetInteger(
kAddressBarPositionEphemeralModuleImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kAutofillPasswordsEphemeralModule) == 0) {
int freshness_impression_count = profile_prefs_->GetInteger(
kAutofillPasswordsEphemeralModuleImpressionCounterPref);
profile_prefs_->SetInteger(
kAutofillPasswordsEphemeralModuleImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kEnhancedSafeBrowsingEphemeralModule) == 0) {
int freshness_impression_count = profile_prefs_->GetInteger(
kEnhancedSafeBrowsingEphemeralModuleImpressionCounterPref);
profile_prefs_->SetInteger(
kEnhancedSafeBrowsingEphemeralModuleImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kSavePasswordsEphemeralModule) == 0) {
int freshness_impression_count = profile_prefs_->GetInteger(
kSavePasswordsEphemeralModuleImpressionCounterPref);
profile_prefs_->SetInteger(
kSavePasswordsEphemeralModuleImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kLensEphemeralModule) == 0 ||
strcmp(card_name, kLensEphemeralModuleSearchVariation) == 0 ||
strcmp(card_name, kLensEphemeralModuleShopVariation) == 0 ||
strcmp(card_name, kLensEphemeralModuleTranslateVariation) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kLensEphemeralModuleImpressionCounterPref);
profile_prefs_->SetInteger(kLensEphemeralModuleImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kSendTabNotificationPromo) == 0) {
int impression_count =
profile_prefs_->GetInteger(kSendTabPromoImpressionCounterPref);
profile_prefs_->SetInteger(kSendTabPromoImpressionCounterPref,
impression_count + 1);
}
#endif
#if BUILDFLAG(IS_ANDROID)
if (strcmp(card_name, kDefaultBrowserPromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kDefaultBrowserPromoImpressionCounterPref);
profile_prefs_->SetInteger(kDefaultBrowserPromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (ShouldNotifyCardShownPerSession(card_name)) {
// Educational tip cards, except for the default browser promo card, will
// send a notification when the card is shown once per session, rather than
// every time it is displayed.
if (strcmp(card_name, kTabGroupPromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kTabGroupPromoImpressionCounterPref);
profile_prefs_->SetInteger(kTabGroupPromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kTabGroupSyncPromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kTabGroupSyncPromoImpressionCounterPref);
profile_prefs_->SetInteger(kTabGroupSyncPromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kQuickDeletePromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kQuickDeletePromoImpressionCounterPref);
profile_prefs_->SetInteger(kQuickDeletePromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kAuxiliarySearch) == 0) {
int freshness_impression_count = profile_prefs_->GetInteger(
kAuxiliarySearchPromoImpressionCounterPref);
profile_prefs_->SetInteger(kAuxiliarySearchPromoImpressionCounterPref,
freshness_impression_count + 1);
} else if (strcmp(card_name, kHistorySyncPromo) == 0) {
int freshness_impression_count =
profile_prefs_->GetInteger(kHistorySyncPromoImpressionCounterPref);
profile_prefs_->SetInteger(kHistorySyncPromoImpressionCounterPref,
freshness_impression_count + 1);
}
}
#endif
}
#if BUILDFLAG(IS_ANDROID)
bool HomeModulesCardRegistry::ShouldNotifyCardShownPerSession(
const std::string& card_name) {
if (shown_in_current_session_.find(card_name) !=
shown_in_current_session_.end()) {
return false;
}
shown_in_current_session_.insert(card_name);
return true;
}
#endif
void HomeModulesCardRegistry::NotifyCardInteracted(const char* card_name) {
#if BUILDFLAG(IS_IOS)
if (strcmp(card_name, kAddressBarPositionEphemeralModule) == 0) {
profile_prefs_->SetBoolean(kAddressBarPositionEphemeralModuleInteractedPref,
true);
} else if (strcmp(card_name, kAutofillPasswordsEphemeralModule) == 0) {
profile_prefs_->SetBoolean(kAutofillPasswordsEphemeralModuleInteractedPref,
true);
} else if (strcmp(card_name, kEnhancedSafeBrowsingEphemeralModule) == 0) {
profile_prefs_->SetBoolean(
kEnhancedSafeBrowsingEphemeralModuleInteractedPref, true);
} else if (strcmp(card_name, kSavePasswordsEphemeralModule) == 0) {
profile_prefs_->SetBoolean(kSavePasswordsEphemeralModuleInteractedPref,
true);
} else if (strcmp(card_name, kLensEphemeralModule) == 0) {
profile_prefs_->SetBoolean(kLensEphemeralModuleInteractedPref, true);
} else if (strcmp(card_name, kLensEphemeralModuleSearchVariation) == 0) {
profile_prefs_->SetBoolean(
kLensEphemeralModuleSearchVariationInteractedPref, true);
} else if (strcmp(card_name, kLensEphemeralModuleShopVariation) == 0) {
profile_prefs_->SetBoolean(kLensEphemeralModuleShopVariationInteractedPref,
true);
} else if (strcmp(card_name, kLensEphemeralModuleTranslateVariation) == 0) {
profile_prefs_->SetBoolean(
kLensEphemeralModuleTranslateVariationInteractedPref, true);
}
#endif
#if BUILDFLAG(IS_ANDROID)
if (strcmp(card_name, kDefaultBrowserPromo) == 0) {
profile_prefs_->SetBoolean(kDefaultBrowserPromoInteractedPref, true);
} else if (strcmp(card_name, kTabGroupPromo) == 0) {
profile_prefs_->SetBoolean(kTabGroupPromoInteractedPref, true);
} else if (strcmp(card_name, kTabGroupSyncPromo) == 0) {
profile_prefs_->SetBoolean(kTabGroupSyncPromoInteractedPref, true);
} else if (strcmp(card_name, kQuickDeletePromo) == 0) {
profile_prefs_->SetBoolean(kQuickDeletePromoInteractedPref, true);
} else if (strcmp(card_name, kAuxiliarySearch) == 0) {
profile_prefs_->SetBoolean(kAuxiliarySearchPromoInteractedPref, true);
} else if (strcmp(card_name, kHistorySyncPromo) == 0) {
profile_prefs_->SetBoolean(kHistorySyncPromoInteractedPref, true);
}
#endif
}
void HomeModulesCardRegistry::CreateAllCards() {
#if BUILDFLAG(IS_IOS)
int price_tracking_promo_count =
profile_prefs_->GetInteger(kPriceTrackingPromoImpressionCounterPref);
int send_tab_promo_count =
profile_prefs_->GetInteger(kSendTabPromoImpressionCounterPref);
if (PriceTrackingNotificationPromo::IsEnabled(price_tracking_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<PriceTrackingNotificationPromo>(
price_tracking_promo_count));
}
if (base::FeatureList::IsEnabled(
features::kSegmentationPlatformTipsEphemeralCard)) {
std::optional<CardSelectionInfo::ShowResult> forced_result =
GetForcedEphemeralModuleShowResult();
// Determine the forced card identifier and label, if any.
TipIdentifier forced_identifier = TipIdentifier::kUnknown;
std::string_view forced_label;
if (forced_result.has_value() &&
forced_result.value().position == EphemeralHomeModuleRank::kTop) {
forced_label = forced_result.value().result_label.value();
forced_identifier = TipIdentifierForOutputLabel(forced_label);
if (forced_identifier != TipIdentifier::kUnknown) {
AddCardForTip(forced_identifier, all_cards_by_priority_,
profile_prefs_);
}
}
// Iterate through variation labels and add unique cards.
for (std::string_view variation_label :
base::SplitString(features::TipsExperimentTrainEnabled(), ",",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
TipIdentifier identifier = TipIdentifierForOutputLabel(variation_label);
// Skip adding if:
// 1. The identifier is unknown.
// 2. It matches the forced identifier.
// 3. Both belong to the same "family" of Lens cards.
if (identifier == TipIdentifier::kUnknown ||
identifier == forced_identifier ||
(LensEphemeralModule::IsModuleLabel(variation_label) &&
LensEphemeralModule::IsModuleLabel(forced_label))) {
continue;
}
AddCardForTip(identifier, all_cards_by_priority_, profile_prefs_);
}
}
if (SendTabNotificationPromo::IsEnabled(send_tab_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<SendTabNotificationPromo>(send_tab_promo_count));
}
#endif
#if BUILDFLAG(IS_ANDROID)
int auxiliary_search_promo_count =
profile_prefs_->GetInteger(kAuxiliarySearchPromoImpressionCounterPref);
if (AuxiliarySearchPromo::IsEnabled(auxiliary_search_promo_count)) {
all_cards_by_priority_.push_back(std::make_unique<AuxiliarySearchPromo>());
}
// TODO(crbug.com/420897397): Move the forced card check out from each card.
std::vector<std::string> enabled_educational_tip_cards_list =
GetEnabledCardList();
auto is_in_enabled_cards_set = [&](const std::string& card_name) {
return enabled_educational_tip_cards_list.empty() ||
base::Contains(enabled_educational_tip_cards_list, card_name);
};
int default_browser_promo_count =
profile_prefs_->GetInteger(kDefaultBrowserPromoImpressionCounterPref);
if (DefaultBrowserPromo::IsEnabled(
is_in_enabled_cards_set(kDefaultBrowserPromo),
default_browser_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<DefaultBrowserPromo>(profile_prefs_));
}
int history_sync_educational_promo_show_count =
profile_prefs_->GetInteger(kHistorySyncPromoImpressionCounterPref);
if (HistorySyncPromo::IsEnabled(is_in_enabled_cards_set(kHistorySyncPromo),
history_sync_educational_promo_show_count)) {
all_cards_by_priority_.push_back(
std::make_unique<HistorySyncPromo>(profile_prefs_));
}
int tab_group_promo_count =
profile_prefs_->GetInteger(kTabGroupPromoImpressionCounterPref);
if (TabGroupPromo::IsEnabled(is_in_enabled_cards_set(kTabGroupPromo),
tab_group_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<TabGroupPromo>(profile_prefs_));
}
int tab_group_sync_promo_count =
profile_prefs_->GetInteger(kTabGroupSyncPromoImpressionCounterPref);
if (TabGroupSyncPromo::IsEnabled(is_in_enabled_cards_set(kTabGroupSyncPromo),
tab_group_sync_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<TabGroupSyncPromo>(profile_prefs_));
}
int quick_delete_promo_count =
profile_prefs_->GetInteger(kQuickDeletePromoImpressionCounterPref);
if (QuickDeletePromo::IsEnabled(is_in_enabled_cards_set(kQuickDeletePromo),
quick_delete_promo_count)) {
all_cards_by_priority_.push_back(
std::make_unique<QuickDeletePromo>(profile_prefs_));
}
#endif
InitializeAfterAddingCards();
}
void HomeModulesCardRegistry::InitializeAfterAddingCards() {
size_t input_counter = 0;
AddCardLabels({kPlaceholderEphemeralModuleLabel});
for (std::unique_ptr<CardSelectionInfo>& card : all_cards_by_priority_) {
std::map<SignalKey, size_t> card_signals;
const auto& card_inputs = card->GetInputs();
for (const auto& key_and_input : card_inputs) {
card_signals[key_and_input.first] = input_counter;
input_counter++;
}
card_signal_map_[card->card_name()] = card_signals;
std::vector<std::string> card_labels = card->OutputLabels();
if (!card_labels.empty()) {
AddCardLabels(card_labels);
} else {
AddCardLabels({card->card_name()});
}
}
all_cards_input_size_ = input_counter;
}
void HomeModulesCardRegistry::AddCardLabels(
const std::vector<std::string>& card_labels) {
for (const std::string& label : card_labels) {
CHECK(!label_to_output_index_.count(label));
label_to_output_index_[label] = all_output_labels_.size();
all_output_labels_.push_back(label);
}
}
base::WeakPtr<HomeModulesCardRegistry> HomeModulesCardRegistry::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
std::vector<std::string> HomeModulesCardRegistry::GetEnabledCardList() {
std::string raw_value = features::KNamesOfEphemeralCardsToShow.Get();
std::vector<std::string> result = base::SplitString(
raw_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
return result;
}
} // namespace segmentation_platform::home_modules
|