OLD | NEW |
---|---|
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)) | |
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.
| |
36 return true; | |
37 | |
24 // Promotion should only show for english locale. | 38 // Promotion should only show for english locale. |
39 PrefService* local_state = g_browser_process->local_state(); | |
25 std::string locale = base::i18n::GetConfiguredLocale(); | 40 std::string locale = base::i18n::GetConfiguredLocale(); |
26 if (locale != "en-US" && locale != "en-CA") | 41 if (locale != "en-US" && locale != "en-CA") |
27 return false; | 42 return false; |
28 if (!base::FeatureList::IsEnabled(features::kDesktopIOSPromotion) || | 43 if (!base::FeatureList::IsEnabled(features::kDesktopIOSPromotion) || |
29 !sync_service || !sync_service->IsSyncAllowed()) | 44 !sync_service || !sync_service->IsSyncAllowed()) |
30 return false; | 45 return false; |
46 | |
31 // TODO(crbug.com/676655): Check if the specific entrypoint is enabled by | 47 // TODO(crbug.com/676655): Check if the specific entrypoint is enabled by |
32 // Finch. | 48 // Finch. |
33 bool is_dismissed = | 49 bool is_dismissed = local_state->GetBoolean( |
34 prefs->GetBoolean(kEntryPointLocalPrefs[(int)entry_point][1]); | 50 kEntryPointLocalPrefs[static_cast<int>(entry_point) + |
35 int show_count = | 51 kPromotionEntrypointIndexOffset][1]); |
36 prefs->GetInteger(kEntryPointLocalPrefs[(int)entry_point][0]); | 52 int show_count = local_state->GetInteger( |
53 kEntryPointLocalPrefs[static_cast<int>(entry_point) + | |
54 kPromotionEntrypointIndexOffset][0]); | |
37 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the | 55 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the |
38 // value from the entryPointImpressionCap array. | 56 // value from the entryPointImpressionCap array. |
39 if (is_dismissed || show_count >= kEntryPointImpressionCap[(int)entry_point]) | 57 if (is_dismissed || |
58 show_count >= kEntryPointImpressionCap[static_cast<int>(entry_point) + | |
59 kPromotionEntrypointIndexOffset]) | |
40 return false; | 60 return false; |
61 | |
62 // Don't show the promotion if the user have used any entry point to recieve | |
63 // SMS on the last 7 days. | |
64 double last_impression = prefs->GetDouble(prefs::kIOSPromotionLastImpression); | |
65 int sms_entrypoint = prefs->GetInteger(prefs::kIOSPromotionSMSEntryPoint); | |
66 base::TimeDelta delta = | |
67 base::Time::Now() - base::Time::FromDoubleT(last_impression); | |
68 if (delta.InDays() <= 7 && sms_entrypoint != 0) | |
69 return false; | |
70 | |
41 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible); | 71 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible); |
42 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone); | 72 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone); |
43 return is_user_eligible && !did_promo_done_before; | 73 return is_user_eligible && !did_promo_done_before; |
44 } | 74 } |
45 | 75 |
46 base::string16 GetPromoBubbleText( | 76 base::string16 GetPromoBubbleText( |
47 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 77 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
48 if (entry_point == | 78 if (entry_point == |
49 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { | 79 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { |
50 return l10n_util::GetStringUTF16( | 80 return l10n_util::GetStringUTF16( |
51 IDS_PASSWORD_MANAGER_DESKTOP_TO_IOS_PROMO_TEXT); | 81 IDS_PASSWORD_MANAGER_DESKTOP_TO_IOS_PROMO_TEXT); |
52 } | 82 } |
53 return base::string16(); | 83 return base::string16(); |
54 } | 84 } |
55 | 85 |
56 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 86 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
57 registry->RegisterBooleanPref( | 87 registry->RegisterBooleanPref( |
58 prefs::kIOSPromotionEligible, false, | 88 prefs::kIOSPromotionEligible, false, |
59 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | 89 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); |
60 registry->RegisterBooleanPref( | 90 registry->RegisterBooleanPref( |
61 prefs::kIOSPromotionDone, false, | 91 prefs::kIOSPromotionDone, false, |
62 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | 92 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); |
93 registry->RegisterIntegerPref( | |
94 prefs::kIOSPromotionSMSEntryPoint, 0, | |
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | |
96 registry->RegisterIntegerPref( | |
97 prefs::kIOSPromotionShownEntryPoints, 0, | |
98 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | |
99 registry->RegisterDoublePref( | |
100 prefs::kIOSPromotionLastImpression, 0, | |
101 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF); | |
63 } | 102 } |
64 | 103 |
65 void RegisterLocalPrefs(PrefRegistrySimple* registry) { | 104 void RegisterLocalPrefs(PrefRegistrySimple* registry) { |
66 registry->RegisterIntegerPref(prefs::kNumberSavePasswordsBubbleIOSPromoShown, | 105 registry->RegisterIntegerPref(prefs::kNumberSavePasswordsBubbleIOSPromoShown, |
67 0); | 106 0); |
68 registry->RegisterBooleanPref(prefs::kSavePasswordsBubbleIOSPromoDismissed, | 107 registry->RegisterBooleanPref(prefs::kSavePasswordsBubbleIOSPromoDismissed, |
69 false); | 108 false); |
70 registry->RegisterIntegerPref(prefs::kNumberBookmarksBubbleIOSPromoShown, 0); | 109 registry->RegisterIntegerPref(prefs::kNumberBookmarksBubbleIOSPromoShown, 0); |
71 registry->RegisterBooleanPref(prefs::kBookmarksBubbleIOSPromoDismissed, | 110 registry->RegisterBooleanPref(prefs::kBookmarksBubbleIOSPromoDismissed, |
72 false); | 111 false); |
73 registry->RegisterIntegerPref(prefs::kNumberBookmarksFootNoteIOSPromoShown, | 112 registry->RegisterIntegerPref(prefs::kNumberBookmarksFootNoteIOSPromoShown, |
74 0); | 113 0); |
75 registry->RegisterBooleanPref(prefs::kBookmarksFootNoteIOSPromoDismissed, | 114 registry->RegisterBooleanPref(prefs::kBookmarksFootNoteIOSPromoDismissed, |
76 false); | 115 false); |
77 registry->RegisterIntegerPref(prefs::kNumberHistoryPageIOSPromoShown, 0); | 116 registry->RegisterIntegerPref(prefs::kNumberHistoryPageIOSPromoShown, 0); |
78 registry->RegisterBooleanPref(prefs::kHistoryPageIOSPromoDismissed, false); | 117 registry->RegisterBooleanPref(prefs::kHistoryPageIOSPromoDismissed, false); |
79 } | 118 } |
80 | 119 |
120 void LogDismissalReason(PromotionDismissalReason reason, | |
121 PromotionEntryPoint entry_point) { | |
122 base::Histogram::FactoryGet( | |
123 base::StringPrintf("DesktopIOSPromotion.%s.DismissalReason", | |
124 desktop_ios_promotion::kEntrypointHistogramPrefix | |
125 [static_cast<int>(entry_point) + | |
126 kPromotionEntrypointIndexOffset]), | |
127 1, static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE), | |
128 static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE) + 1, | |
129 base::HistogramBase::kUmaTargetedHistogramFlag) | |
130 ->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
| |
131 } | |
132 | |
81 } // namespace desktop_ios_promotion | 133 } // namespace desktop_ios_promotion |
OLD | NEW |