Chromium Code Reviews| 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..dfb501addd6bb3ee13c9ce86707a9aa44031562d 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,52 @@ 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)) |
|
sky
2017/02/17 00:57:23
{}
mrefaat
2017/02/17 04:31:49
Not sure why ?
sky
2017/02/17 19:06:25
Generally when the conditional spans multiple line
mrefaat
2017/02/17 21:53:13
Acknowledged.
|
| + 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]); |
| - int show_count = |
| - prefs->GetInteger(kEntryPointLocalPrefs[(int)entry_point][0]); |
| + bool is_dismissed = local_state->GetBoolean( |
| + kEntryPointLocalPrefs[static_cast<int>(entry_point) + |
| + kPromotionEntrypointIndexOffset][1]); |
| + int show_count = local_state->GetInteger( |
| + kEntryPointLocalPrefs[static_cast<int>(entry_point) + |
| + kPromotionEntrypointIndexOffset][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[static_cast<int>(entry_point) + |
| + kPromotionEntrypointIndexOffset]) |
| 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 +90,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 +117,17 @@ 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 |
| + [static_cast<int>(entry_point) + |
| + kPromotionEntrypointIndexOffset]), |
| + 1, static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE), |
| + static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE) + 1, |
| + base::HistogramBase::kUmaTargetedHistogramFlag) |
| + ->Add((int)desktop_ios_promotion::PromotionDismissalReason::SEND_SMS); |
|
Mark P
2017/02/16 23:18:57
Should this be |reason|?
Also, nit: mixing differ
mrefaat
2017/02/17 00:20:58
Thanks for catching this one
|
| +} |
| + |
| } // namespace desktop_ios_promotion |