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)) | |
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)][1]); |
35 int show_count = | 51 int show_count = local_state->GetInteger( |
36 prefs->GetInteger(kEntryPointLocalPrefs[(int)entry_point][0]); | 52 kEntryPointLocalPrefs[static_cast<int>(entry_point)][0]); |
37 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the | 53 // TODO(crbug.com/676655): Get the impression cap. from Finch and replace the |
38 // value from the entryPointImpressionCap array. | 54 // value from the entryPointImpressionCap array. |
39 if (is_dismissed || show_count >= kEntryPointImpressionCap[(int)entry_point]) | 55 if (is_dismissed || |
56 show_count >= kEntryPointImpressionCap[static_cast<int>(entry_point)]) | |
40 return false; | 57 return false; |
58 | |
59 // Don't show the promotion if the user have used any entry point to recieve | |
60 // SMS on the last 7 days. | |
61 double last_impression = prefs->GetDouble(prefs::kIOSPromotionLastImpression); | |
62 int sms_entrypoint = prefs->GetInteger(prefs::kIOSPromotionSMSEntryPoint); | |
63 base::TimeDelta delta = | |
64 base::Time::Now() - base::Time::FromDoubleT(last_impression); | |
65 if (delta.InDays() <= 7 && sms_entrypoint != 0) | |
66 return false; | |
67 | |
41 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible); | 68 bool is_user_eligible = prefs->GetBoolean(prefs::kIOSPromotionEligible); |
42 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone); | 69 bool did_promo_done_before = prefs->GetBoolean(prefs::kIOSPromotionDone); |
43 return is_user_eligible && !did_promo_done_before; | 70 return is_user_eligible && !did_promo_done_before; |
44 } | 71 } |
45 | 72 |
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 base::Histogram::FactoryGet( | |
120 base::StringPrintf( | |
121 "DesktopIOSPromotion.%s.DismissalReason", | |
122 desktop_ios_promotion::kEntrypointHistogramPrefix[static_cast<int>( | |
123 entry_point)]), | |
124 1, static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE), | |
sky
2017/02/17 19:06:29
I assume 1 is the minimum value, which you are ass
mrefaat
2017/02/17 21:53:14
Done.
| |
125 static_cast<int>(PromotionEntryPoint::ENTRY_POINT_MAX_VALUE) + 1, | |
sky
2017/02/17 19:06:29
Why the +1 here?
mrefaat
2017/02/17 21:53:14
These are the number of buckets should be max_boun
| |
126 base::HistogramBase::kUmaTargetedHistogramFlag) | |
127 ->Add(static_cast<int>(reason)); | |
128 } | |
129 | |
81 } // namespace desktop_ios_promotion | 130 } // namespace desktop_ios_promotion |
OLD | NEW |