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_controll
er.h" | 5 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_controll
er.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/metrics/field_trial_params.h" | 7 #include "base/metrics/field_trial_params.h" |
9 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
10 #include "base/time/time.h" | 9 #include "base/time/time.h" |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h" | 12 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h" |
14 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_view.h" | |
15 #include "chrome/browser/ui/desktop_ios_promotion/sms_service.h" | |
16 #include "chrome/browser/ui/desktop_ios_promotion/sms_service_factory.h" | |
17 #include "chrome/common/chrome_features.h" | 13 #include "chrome/common/chrome_features.h" |
18 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
19 | 15 |
20 DesktopIOSPromotionController::DesktopIOSPromotionController( | 16 DesktopIOSPromotionController::DesktopIOSPromotionController( |
21 Profile* profile, | 17 Profile* profile, |
22 DesktopIOSPromotionView* promotion_view, | |
23 desktop_ios_promotion::PromotionEntryPoint entry_point) | 18 desktop_ios_promotion::PromotionEntryPoint entry_point) |
24 : profile_prefs_(profile->GetPrefs()), | 19 : profile_prefs_(profile->GetPrefs()), |
25 entry_point_(entry_point), | 20 entry_point_(entry_point), |
26 sms_service_(SMSServiceFactory::GetForProfile(profile)), | |
27 promotion_view_(promotion_view), | |
28 dismissal_reason_( | 21 dismissal_reason_( |
29 desktop_ios_promotion::PromotionDismissalReason::FOCUS_LOST), | 22 desktop_ios_promotion::PromotionDismissalReason::FOCUS_LOST) {} |
30 weak_ptr_factory_(this) { | |
31 sms_service_->QueryPhoneNumber( | |
32 base::Bind(&DesktopIOSPromotionController::OnGotPhoneNumber, | |
33 weak_ptr_factory_.GetWeakPtr())); | |
34 } | |
35 | 23 |
36 DesktopIOSPromotionController::~DesktopIOSPromotionController() { | 24 DesktopIOSPromotionController::~DesktopIOSPromotionController() { |
37 desktop_ios_promotion::LogDismissalReason(dismissal_reason_, entry_point_); | 25 desktop_ios_promotion::LogDismissalReason(dismissal_reason_, entry_point_); |
38 } | 26 } |
39 | 27 |
40 void DesktopIOSPromotionController::OnSendSMSClicked() { | 28 void DesktopIOSPromotionController::OnPromotionShown() { |
41 sms_service_->SendSMS(desktop_ios_promotion::GetSMSID(), | 29 UMA_HISTOGRAM_ENUMERATION( |
42 base::Bind(&DesktopIOSPromotionController::OnSendSMS, | 30 "DesktopIOSPromotion.ImpressionFromEntryPoint", |
43 weak_ptr_factory_.GetWeakPtr())); | 31 static_cast<int>(entry_point_), |
| 32 static_cast<int>( |
| 33 desktop_ios_promotion::PromotionEntryPoint::ENTRY_POINT_MAX_VALUE)); |
44 | 34 |
45 // Update Profile prefs. | 35 if (entry_point_ == |
46 profile_prefs_->SetInteger(prefs::kIOSPromotionSMSEntryPoint, | 36 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE) { |
47 static_cast<int>(entry_point_)); | 37 // We don't want to update sync with the impression of this entrypoint. |
48 | 38 return; |
49 // Update dismissal reason. | 39 } |
50 dismissal_reason_ = desktop_ios_promotion::PromotionDismissalReason::SEND_SMS; | |
51 } | |
52 | |
53 void DesktopIOSPromotionController::OnPromotionShown() { | |
54 // update the impressions count. | 40 // update the impressions count. |
55 PrefService* local_state = g_browser_process->local_state(); | 41 PrefService* local_state = g_browser_process->local_state(); |
56 int impressions = local_state->GetInteger( | 42 int impressions = local_state->GetInteger( |
57 desktop_ios_promotion::kEntryPointLocalPrefs | 43 desktop_ios_promotion::kEntryPointLocalPrefs |
58 [static_cast<int>(entry_point_)][static_cast<int>( | 44 [static_cast<int>(entry_point_)][static_cast<int>( |
59 desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS)]); | 45 desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS)]); |
60 impressions++; | 46 impressions++; |
61 local_state->SetInteger( | 47 local_state->SetInteger( |
62 desktop_ios_promotion::kEntryPointLocalPrefs | 48 desktop_ios_promotion::kEntryPointLocalPrefs |
63 [static_cast<int>(entry_point_)][static_cast<int>( | 49 [static_cast<int>(entry_point_)][static_cast<int>( |
(...skipping 14 matching lines...) Expand all Loading... |
78 double last_impression = base::Time::NowFromSystemTime().ToDoubleT(); | 64 double last_impression = base::Time::NowFromSystemTime().ToDoubleT(); |
79 profile_prefs_->SetDouble(prefs::kIOSPromotionLastImpression, | 65 profile_prefs_->SetDouble(prefs::kIOSPromotionLastImpression, |
80 last_impression); | 66 last_impression); |
81 | 67 |
82 // If the variation id paramater is set on the finch experiement, set this | 68 // If the variation id paramater is set on the finch experiement, set this |
83 // variation id to chrome sync pref to be accessed from iOS side. | 69 // variation id to chrome sync pref to be accessed from iOS side. |
84 int variation_id = base::GetFieldTrialParamByFeatureAsInt( | 70 int variation_id = base::GetFieldTrialParamByFeatureAsInt( |
85 features::kDesktopIOSPromotion, "promo_variation_id", 0); | 71 features::kDesktopIOSPromotion, "promo_variation_id", 0); |
86 if (variation_id) | 72 if (variation_id) |
87 profile_prefs_->SetInteger(prefs::kIOSPromotionVariationId, variation_id); | 73 profile_prefs_->SetInteger(prefs::kIOSPromotionVariationId, variation_id); |
88 | |
89 // Update histograms. | |
90 UMA_HISTOGRAM_ENUMERATION( | |
91 "DesktopIOSPromotion.ImpressionFromEntryPoint", | |
92 static_cast<int>(entry_point_), | |
93 static_cast<int>( | |
94 desktop_ios_promotion::PromotionEntryPoint::ENTRY_POINT_MAX_VALUE)); | |
95 } | 74 } |
96 | 75 |
97 void DesktopIOSPromotionController::OnNoThanksClicked() { | 76 void DesktopIOSPromotionController::OnLearnMoreLinkClicked() { |
98 PrefService* local_state = g_browser_process->local_state(); | |
99 local_state->SetBoolean( | |
100 desktop_ios_promotion::kEntryPointLocalPrefs | |
101 [static_cast<int>(entry_point_)][static_cast<int>( | |
102 desktop_ios_promotion::EntryPointLocalPrefType::DISMISSED)], | |
103 true); | |
104 dismissal_reason_ = | 77 dismissal_reason_ = |
105 desktop_ios_promotion::PromotionDismissalReason::NO_THANKS; | 78 desktop_ios_promotion::PromotionDismissalReason::LEARN_MORE; |
106 } | 79 } |
107 | 80 |
108 std::string DesktopIOSPromotionController::GetUsersRecoveryPhoneNumber() { | 81 void DesktopIOSPromotionController::SetDismissalReason( |
109 return recovery_number_; | 82 desktop_ios_promotion::PromotionDismissalReason reason) { |
| 83 dismissal_reason_ = reason; |
110 } | 84 } |
111 | |
112 void DesktopIOSPromotionController::OnGotPhoneNumber( | |
113 SMSService::Request* request, | |
114 bool success, | |
115 const std::string& number) { | |
116 if (success) { | |
117 recovery_number_ = desktop_ios_promotion::FormatPhoneNumber(number); | |
118 promotion_view_->UpdateRecoveryPhoneLabel(); | |
119 } | |
120 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.QueryPhoneNumberSucceeded", | |
121 success); | |
122 } | |
123 | |
124 void DesktopIOSPromotionController::OnSendSMS(SMSService::Request* request, | |
125 bool success, | |
126 const std::string& number) { | |
127 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.SendSMSSucceeded", success); | |
128 } | |
OLD | NEW |