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 DesktopIOSPromotionController::DesktopIOSPromotionController() {} | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram_macros.h" | |
9 #include "base/time/time.h" | |
10 #include "chrome/browser/browser_process.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h" | |
13 #include "chrome/browser/ui/desktop_ios_promotion/sms_service.h" | |
14 #include "chrome/browser/ui/desktop_ios_promotion/sms_service_factory.h" | |
15 #include "components/prefs/pref_service.h" | |
16 | |
17 DesktopIOSPromotionController::DesktopIOSPromotionController( | |
18 Profile* profile, | |
19 desktop_ios_promotion::PromotionEntryPoint entry_point) | |
20 : weak_ptr_factory_(this), | |
sky
2017/02/16 00:13:35
Order of member initialize list should match that
mrefaat
2017/02/16 21:02:39
Done.
| |
21 recovery_number_(std::string()), | |
sky
2017/02/16 00:13:35
Don't bother initializing members that have empty
mrefaat
2017/02/16 21:02:39
Done.
| |
22 entry_point_(entry_point), | |
23 profile_prefs_(profile->GetPrefs()) { | |
24 sms_service_ = SMSServiceFactory::GetForProfile(profile); | |
sky
2017/02/16 00:13:36
Move to member initializer.
mrefaat
2017/02/16 21:02:39
Done.
| |
25 sms_service_->QueryPhoneNumber( | |
26 base::Bind(&DesktopIOSPromotionController::OnQueryPhoneNumber, | |
27 weak_ptr_factory_.GetWeakPtr())); | |
28 } | |
8 | 29 |
9 DesktopIOSPromotionController::~DesktopIOSPromotionController() {} | 30 DesktopIOSPromotionController::~DesktopIOSPromotionController() {} |
10 | 31 |
11 void DesktopIOSPromotionController::OnSendSMSClicked() { | 32 void DesktopIOSPromotionController::OnSendSMSClicked() { |
12 // TODO(crbug.com/676655): Call the growth api to send sms. | 33 // TODO(crbug.com/676655): Get the SMS message id from the finch group. |
34 std::string sms_message_id = "19001507"; | |
35 sms_service_->SendSMS(sms_message_id, | |
36 base::Bind(&DesktopIOSPromotionController::OnSendSMS, | |
37 weak_ptr_factory_.GetWeakPtr())); | |
38 | |
39 // Update Profile prefs. | |
40 profile_prefs_->SetInteger(prefs::kIOSPromotionSMSEntryPoint, | |
41 (int)entry_point_); | |
sky
2017/02/16 00:13:35
Use c++ casts.
mrefaat
2017/02/16 21:02:39
Done.
| |
42 | |
43 // Update histograms. | |
44 desktop_ios_promotion::LogDismissalReason( | |
45 desktop_ios_promotion::PromotionDismissalReason::SEND_SMS, entry_point_); | |
46 } | |
47 | |
48 void DesktopIOSPromotionController::OnPromotionShown() { | |
49 // update the impressions count. | |
50 PrefService* local_state = g_browser_process->local_state(); | |
51 int impressions = local_state->GetInteger( | |
52 desktop_ios_promotion::kEntryPointLocalPrefs[(int)entry_point_ - 1][( | |
sky
2017/02/16 00:13:36
Again with the casts, also, use a constant for the
mrefaat
2017/02/16 21:02:39
made a constant but i think it shouldn't be in the
| |
53 int)desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS]); | |
54 impressions++; | |
55 local_state->SetInteger( | |
56 desktop_ios_promotion::kEntryPointLocalPrefs[(int)entry_point_ - 1][( | |
57 int)desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS], | |
58 impressions); | |
59 | |
60 // Update synced profile prefs. | |
61 int shown_entrypoints = | |
62 profile_prefs_->GetInteger(prefs::kIOSPromotionShownEntryPoints); | |
63 shown_entrypoints |= 1 << (int)entry_point_; | |
64 profile_prefs_->SetInteger(prefs::kIOSPromotionShownEntryPoints, | |
65 shown_entrypoints); | |
66 | |
67 // If the promo is seen then it means the SMS was not sent on the last 7 days, | |
68 // reset the pref. | |
69 profile_prefs_->SetInteger(prefs::kIOSPromotionSMSEntryPoint, 0); | |
70 | |
71 double last_impression = base::Time::NowFromSystemTime().ToDoubleT(); | |
72 profile_prefs_->SetDouble(prefs::kIOSPromotionLastImpression, | |
73 last_impression); | |
74 // Update histograms. | |
75 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.ImpressionFromEntryPoint", | |
76 (int)entry_point_, 5); | |
sky
2017/02/16 00:13:36
Use a constant for 5.
mrefaat
2017/02/16 21:02:39
Done.
| |
13 } | 77 } |
14 | 78 |
15 void DesktopIOSPromotionController::OnNoThanksClicked() { | 79 void DesktopIOSPromotionController::OnNoThanksClicked() { |
16 // TODO(crbug.com/676655): Handle logging & update sync. | 80 PrefService* local_state = g_browser_process->local_state(); |
81 local_state->SetBoolean( | |
82 desktop_ios_promotion::kEntryPointLocalPrefs[(int)entry_point_ - 1][( | |
83 int)desktop_ios_promotion::EntryPointLocalPrefType::DISMISSED], | |
84 true); | |
85 | |
86 desktop_ios_promotion::LogDismissalReason( | |
87 desktop_ios_promotion::PromotionDismissalReason::NO_THANKS, entry_point_); | |
17 } | 88 } |
89 | |
90 void DesktopIOSPromotionController::OnQueryPhoneNumber( | |
91 SMSService::Request* request, | |
92 bool success, | |
93 const std::string& number) { | |
94 if (success) { | |
sky
2017/02/16 00:13:36
no {}
mrefaat
2017/02/16 21:02:39
Done.
| |
95 recovery_number_ = number; | |
sky
2017/02/16 00:13:36
AFAICT this isn't used.
Based on my understanding
mrefaat
2017/02/16 21:02:39
Our Targeting set will only have the user if their
sky
2017/02/17 00:04:12
Not sure I follow. That sort of implies success is
| |
96 } | |
97 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.QueryPhoneNumberSucceeded", | |
98 success); | |
99 } | |
100 | |
101 void DesktopIOSPromotionController::OnSendSMS(SMSService::Request* request, | |
102 bool success, | |
103 const std::string& number) { | |
104 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.SendSMSSucceeded", success); | |
105 } | |
OLD | NEW |