| Index: chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc
|
| diff --git a/chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc b/chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc
|
| index 8f46fc1f004ead38f5bbb60b11e5639d7c853255..6ef8be3b1d6f731fb5a24f9c33ac26950e11b600 100644
|
| --- a/chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc
|
| +++ b/chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc
|
| @@ -4,8 +4,13 @@
|
|
|
| #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h"
|
|
|
| +#include "base/command_line.h"
|
| #include "base/i18n/rtl.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/common/chrome_features.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "components/browser_sync/profile_sync_service.h"
|
| #include "components/pref_registry/pref_registry_syncable.h"
|
| @@ -17,27 +22,49 @@ namespace desktop_ios_promotion {
|
| // Default Impression cap. for each entry point.
|
| const int kEntryPointImpressionCap[] = {2, 2, 5, 10};
|
|
|
| +const char* kEntrypointHistogramPrefix[] = {
|
| + "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksFootNote",
|
| + "HistoryPage",
|
| +};
|
| +
|
| bool IsEligibleForIOSPromotion(
|
| PrefService* prefs,
|
| const syncer::SyncService* sync_service,
|
| desktop_ios_promotion::PromotionEntryPoint entry_point) {
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kForceDesktopIOSPromotion))
|
| + return true;
|
| +
|
| // Promotion should only show for english locale.
|
| + PrefService* local_state = g_browser_process->local_state();
|
| std::string locale = base::i18n::GetConfiguredLocale();
|
| if (locale != "en-US" && locale != "en-CA")
|
| return false;
|
| if (!base::FeatureList::IsEnabled(features::kDesktopIOSPromotion) ||
|
| !sync_service || !sync_service->IsSyncAllowed())
|
| return false;
|
| +
|
| // TODO(crbug.com/676655): Check if the specific entrypoint is enabled by
|
| // Finch.
|
| bool is_dismissed =
|
| - prefs->GetBoolean(kEntryPointLocalPrefs[(int)entry_point][1]);
|
| + local_state->GetBoolean(kEntryPointLocalPrefs[(int)entry_point - 1][1]);
|
| int show_count =
|
| - prefs->GetInteger(kEntryPointLocalPrefs[(int)entry_point][0]);
|
| + local_state->GetInteger(kEntryPointLocalPrefs[(int)entry_point - 1][0]);
|
| // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the
|
| // value from the entryPointImpressionCap array.
|
| - if (is_dismissed || show_count >= kEntryPointImpressionCap[(int)entry_point])
|
| + if (is_dismissed ||
|
| + show_count >= kEntryPointImpressionCap[(int)entry_point - 1])
|
| return false;
|
| +
|
| + // Don't show the promotion if the user have used any entry point to recieve
|
| + // SMS on the last 7 days.
|
| + double last_impression = prefs->GetDouble(prefs::kIOSPromotionLastImpression);
|
| + int sms_entrypoint = prefs->GetInteger(prefs::kIOSPromotionSMSEntryPoint);
|
| + base::TimeDelta delta =
|
| + base::Time::Now() - base::Time::FromDoubleT(last_impression);
|
| + if (delta.InDays() <= 7 && sms_entrypoint != 0)
|
| + return false;
|
| +
|
| bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible);
|
| bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone);
|
| return is_user_eligible && !did_promo_done_before;
|
| @@ -60,6 +87,15 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
|
| registry->RegisterBooleanPref(
|
| prefs::kIOSPromotionDone, false,
|
| user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
|
| + registry->RegisterIntegerPref(
|
| + prefs::kIOSPromotionSMSEntryPoint, 0,
|
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
|
| + registry->RegisterIntegerPref(
|
| + prefs::kIOSPromotionShownEntryPoints, 0,
|
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
|
| + registry->RegisterDoublePref(
|
| + prefs::kIOSPromotionLastImpression, 0,
|
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
|
| }
|
|
|
| void RegisterLocalPrefs(PrefRegistrySimple* registry) {
|
| @@ -78,4 +114,15 @@ void RegisterLocalPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterBooleanPref(prefs::kHistoryPageIOSPromoDismissed, false);
|
| }
|
|
|
| +void LogDismissalReason(PromotionDismissalReason reason,
|
| + PromotionEntryPoint entry_point) {
|
| + base::Histogram::FactoryGet(
|
| + base::StringPrintf(
|
| + "DesktopIOSPromotion.%s.DismissalReason",
|
| + desktop_ios_promotion::kEntrypointHistogramPrefix[(int)entry_point -
|
| + 1]),
|
| + 1, 4, 5, base::HistogramBase::kUmaTargetedHistogramFlag)
|
| + ->Add((int)desktop_ios_promotion::PromotionDismissalReason::SEND_SMS);
|
| +}
|
| +
|
| } // namespace desktop_ios_promotion
|
|
|