Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.cc

Issue 2694893002: Integrate SMS service with Desktop iOS promotion (Closed)
Patch Set: nits Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h" 5 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h"
6 6
7 #include "base/command_line.h"
7 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/browser_process.h"
8 #include "chrome/common/chrome_features.h" 12 #include "chrome/common/chrome_features.h"
13 #include "chrome/common/chrome_switches.h"
9 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
10 #include "components/browser_sync/profile_sync_service.h" 15 #include "components/browser_sync/profile_sync_service.h"
11 #include "components/pref_registry/pref_registry_syncable.h" 16 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
13 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
14 19
15 namespace desktop_ios_promotion { 20 namespace desktop_ios_promotion {
16 21
17 // Default Impression cap. for each entry point. 22 // Default Impression cap. for each entry point.
18 const int kEntryPointImpressionCap[] = {2, 2, 5, 10}; 23 const int kEntryPointImpressionCap[] = {2, 2, 5, 10};
19 24
25 const char* kEntrypointHistogramPrefix[] = {
26 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksFootNote",
27 "HistoryPage",
28 };
29
20 bool IsEligibleForIOSPromotion( 30 bool IsEligibleForIOSPromotion(
21 PrefService* prefs, 31 PrefService* prefs,
22 const syncer::SyncService* sync_service, 32 const syncer::SyncService* sync_service,
23 desktop_ios_promotion::PromotionEntryPoint entry_point) { 33 desktop_ios_promotion::PromotionEntryPoint entry_point) {
34 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kForceDesktopIOSPromotion)) {
36 return true;
37 }
38
24 // Promotion should only show for english locale. 39 // Promotion should only show for english locale.
40 PrefService* local_state = g_browser_process->local_state();
25 std::string locale = base::i18n::GetConfiguredLocale(); 41 std::string locale = base::i18n::GetConfiguredLocale();
26 if (locale != "en-US" && locale != "en-CA") 42 if (locale != "en-US" && locale != "en-CA")
27 return false; 43 return false;
28 if (!base::FeatureList::IsEnabled(features::kDesktopIOSPromotion) || 44 if (!base::FeatureList::IsEnabled(features::kDesktopIOSPromotion) ||
29 !sync_service || !sync_service->IsSyncAllowed()) 45 !sync_service || !sync_service->IsSyncAllowed())
30 return false; 46 return false;
47
31 // TODO(crbug.com/676655): Check if the specific entrypoint is enabled by 48 // TODO(crbug.com/676655): Check if the specific entrypoint is enabled by
32 // Finch. 49 // Finch.
33 bool is_dismissed = 50 bool is_dismissed = local_state->GetBoolean(
34 prefs->GetBoolean(kEntryPointLocalPrefs[(int)entry_point][1]); 51 kEntryPointLocalPrefs[static_cast<int>(entry_point)][1]);
35 int show_count = 52 int show_count = local_state->GetInteger(
36 prefs->GetInteger(kEntryPointLocalPrefs[(int)entry_point][0]); 53 kEntryPointLocalPrefs[static_cast<int>(entry_point)][0]);
37 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the 54 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the
38 // value from the entryPointImpressionCap array. 55 // value from the entryPointImpressionCap array.
39 if (is_dismissed || show_count >= kEntryPointImpressionCap[(int)entry_point]) 56 if (is_dismissed ||
57 show_count >= kEntryPointImpressionCap[static_cast<int>(entry_point)])
40 return false; 58 return false;
59
60 // Don't show the promotion if the user have used any entry point to recieve
61 // SMS on the last 7 days.
62 double last_impression = prefs->GetDouble(prefs::kIOSPromotionLastImpression);
63 int sms_entrypoint = prefs->GetInteger(prefs::kIOSPromotionSMSEntryPoint);
64 base::TimeDelta delta =
65 base::Time::Now() - base::Time::FromDoubleT(last_impression);
66 if (delta.InDays() <= 7 && sms_entrypoint != 0)
67 return false;
68
41 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible); 69 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible);
42 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone); 70 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone);
43 return is_user_eligible && !did_promo_done_before; 71 return is_user_eligible && !did_promo_done_before;
44 } 72 }
45
46 base::string16 GetPromoBubbleText( 73 base::string16 GetPromoBubbleText(
47 desktop_ios_promotion::PromotionEntryPoint entry_point) { 74 desktop_ios_promotion::PromotionEntryPoint entry_point) {
48 if (entry_point == 75 if (entry_point ==
49 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { 76 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) {
50 return l10n_util::GetStringUTF16( 77 return l10n_util::GetStringUTF16(
51 IDS_PASSWORD_MANAGER_DESKTOP_TO_IOS_PROMO_TEXT); 78 IDS_PASSWORD_MANAGER_DESKTOP_TO_IOS_PROMO_TEXT);
52 } 79 }
53 return base::string16(); 80 return base::string16();
54 } 81 }
55 82
56 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 83 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
57 registry->RegisterBooleanPref( 84 registry->RegisterBooleanPref(
58 prefs::kIOSPromotionEligible, false, 85 prefs::kIOSPromotionEligible, false,
59 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); 86 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
60 registry->RegisterBooleanPref( 87 registry->RegisterBooleanPref(
61 prefs::kIOSPromotionDone, false, 88 prefs::kIOSPromotionDone, false,
62 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); 89 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
90 registry->RegisterIntegerPref(
91 prefs::kIOSPromotionSMSEntryPoint, 0,
92 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
93 registry->RegisterIntegerPref(
94 prefs::kIOSPromotionShownEntryPoints, 0,
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
96 registry->RegisterDoublePref(
97 prefs::kIOSPromotionLastImpression, 0,
98 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
63 } 99 }
64 100
65 void RegisterLocalPrefs(PrefRegistrySimple* registry) { 101 void RegisterLocalPrefs(PrefRegistrySimple* registry) {
66 registry->RegisterIntegerPref(prefs::kNumberSavePasswordsBubbleIOSPromoShown, 102 registry->RegisterIntegerPref(prefs::kNumberSavePasswordsBubbleIOSPromoShown,
67 0); 103 0);
68 registry->RegisterBooleanPref(prefs::kSavePasswordsBubbleIOSPromoDismissed, 104 registry->RegisterBooleanPref(prefs::kSavePasswordsBubbleIOSPromoDismissed,
69 false); 105 false);
70 registry->RegisterIntegerPref(prefs::kNumberBookmarksBubbleIOSPromoShown, 0); 106 registry->RegisterIntegerPref(prefs::kNumberBookmarksBubbleIOSPromoShown, 0);
71 registry->RegisterBooleanPref(prefs::kBookmarksBubbleIOSPromoDismissed, 107 registry->RegisterBooleanPref(prefs::kBookmarksBubbleIOSPromoDismissed,
72 false); 108 false);
73 registry->RegisterIntegerPref(prefs::kNumberBookmarksFootNoteIOSPromoShown, 109 registry->RegisterIntegerPref(prefs::kNumberBookmarksFootNoteIOSPromoShown,
74 0); 110 0);
75 registry->RegisterBooleanPref(prefs::kBookmarksFootNoteIOSPromoDismissed, 111 registry->RegisterBooleanPref(prefs::kBookmarksFootNoteIOSPromoDismissed,
76 false); 112 false);
77 registry->RegisterIntegerPref(prefs::kNumberHistoryPageIOSPromoShown, 0); 113 registry->RegisterIntegerPref(prefs::kNumberHistoryPageIOSPromoShown, 0);
78 registry->RegisterBooleanPref(prefs::kHistoryPageIOSPromoDismissed, false); 114 registry->RegisterBooleanPref(prefs::kHistoryPageIOSPromoDismissed, false);
79 } 115 }
80 116
117 void LogDismissalReason(PromotionDismissalReason reason,
118 PromotionEntryPoint entry_point) {
119 constexpr int dismissal_reason_min =
120 static_cast<int>(PromotionDismissalReason::FOCUS_LOST);
121 base::Histogram::FactoryGet(
122 base::StringPrintf(
123 "DesktopIOSPromotion.%s.DismissalReason",
124 desktop_ios_promotion::kEntrypointHistogramPrefix[static_cast<int>(
125 entry_point)]),
126 dismissal_reason_min,
127 static_cast<int>(PromotionDismissalReason::DISMISSAL_REASON_MAX_VALUE),
128 static_cast<int>(PromotionDismissalReason::DISMISSAL_REASON_MAX_VALUE) +
129 1,
130 base::HistogramBase::kUmaTargetedHistogramFlag)
131 ->Add(static_cast<int>(reason));
132 }
133
81 } // namespace desktop_ios_promotion 134 } // namespace desktop_ios_promotion
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698