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

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

Issue 2694893002: Integrate SMS service with Desktop iOS promotion (Closed)
Patch Set: add desktop_ios_promotion_util unittest 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_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.h"
13 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_util.h"
14 #include "chrome/browser/ui/desktop_ios_promotion/sms_service.h"
15 #include "chrome/browser/ui/desktop_ios_promotion/sms_service_factory.h"
16 #include "components/prefs/pref_service.h"
17
18 DesktopIOSPromotionController::DesktopIOSPromotionController(
19 Profile* profile,
20 desktop_ios_promotion::PromotionEntryPoint entry_point)
21 : profile_prefs_(profile->GetPrefs()),
22 entry_point_(entry_point),
23 sms_service_(SMSServiceFactory::GetForProfile(profile)),
24 weak_ptr_factory_(this) {
25 sms_service_->QueryPhoneNumber(
26 base::Bind(&DesktopIOSPromotionController::OnGotPhoneNumber,
27 weak_ptr_factory_.GetWeakPtr()));
28 }
8 29
9 DesktopIOSPromotionController::~DesktopIOSPromotionController() {} 30 DesktopIOSPromotionController::~DesktopIOSPromotionController() {}
10 31
32 desktop_ios_promotion::PromotionEntryPoint
33 DesktopIOSPromotionController::GetEntryPoint() {
34 return entry_point_;
35 }
36
37 void DesktopIOSPromotionController::SetPromotion(
38 DesktopIOSPromotion* promotion) {
39 promotion_ = promotion;
40 }
41
11 void DesktopIOSPromotionController::OnSendSMSClicked() { 42 void DesktopIOSPromotionController::OnSendSMSClicked() {
12 // TODO(crbug.com/676655): Call the growth api to send sms. 43 // TODO(crbug.com/676655): Get the SMS message id from the finch group.
44 std::string sms_message_id = "19001507";
45 sms_service_->SendSMS(sms_message_id,
46 base::Bind(&DesktopIOSPromotionController::OnSendSMS,
47 weak_ptr_factory_.GetWeakPtr()));
48
49 // Update Profile prefs.
50 profile_prefs_->SetInteger(prefs::kIOSPromotionSMSEntryPoint,
51 static_cast<int>(entry_point_));
52
53 // Update histograms.
54 desktop_ios_promotion::LogDismissalReason(
55 desktop_ios_promotion::PromotionDismissalReason::SEND_SMS, entry_point_);
56 }
57
58 void DesktopIOSPromotionController::OnPromotionShown() {
59 // update the impressions count.
60 PrefService* local_state = g_browser_process->local_state();
61 int impressions = local_state->GetInteger(
62 desktop_ios_promotion::kEntryPointLocalPrefs
63 [static_cast<int>(entry_point_)][static_cast<int>(
64 desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS)]);
65 impressions++;
66 local_state->SetInteger(
67 desktop_ios_promotion::kEntryPointLocalPrefs
68 [static_cast<int>(entry_point_)][static_cast<int>(
69 desktop_ios_promotion::EntryPointLocalPrefType::IMPRESSIONS)],
70 impressions);
71
72 // Update synced profile prefs.
73 int shown_entrypoints =
74 profile_prefs_->GetInteger(prefs::kIOSPromotionShownEntryPoints);
75 shown_entrypoints |= 1 << static_cast<int>(entry_point_);
76 profile_prefs_->SetInteger(prefs::kIOSPromotionShownEntryPoints,
77 shown_entrypoints);
78
79 // If the promo is seen then it means the SMS was not sent on the last 7 days,
80 // reset the pref.
81 profile_prefs_->SetInteger(prefs::kIOSPromotionSMSEntryPoint, 0);
82
83 double last_impression = base::Time::NowFromSystemTime().ToDoubleT();
84 profile_prefs_->SetDouble(prefs::kIOSPromotionLastImpression,
85 last_impression);
86 // Update histograms.
87 UMA_HISTOGRAM_ENUMERATION(
88 "DesktopIOSPromotion.ImpressionFromEntryPoint",
89 static_cast<int>(entry_point_),
90 static_cast<int>(
91 desktop_ios_promotion::PromotionEntryPoint::ENTRY_POINT_MAX_VALUE));
13 } 92 }
14 93
15 void DesktopIOSPromotionController::OnNoThanksClicked() { 94 void DesktopIOSPromotionController::OnNoThanksClicked() {
16 // TODO(crbug.com/676655): Handle logging & update sync. 95 PrefService* local_state = g_browser_process->local_state();
96 local_state->SetBoolean(
97 desktop_ios_promotion::kEntryPointLocalPrefs
98 [static_cast<int>(entry_point_)][static_cast<int>(
99 desktop_ios_promotion::EntryPointLocalPrefType::DISMISSED)],
100 true);
101 desktop_ios_promotion::LogDismissalReason(
102 desktop_ios_promotion::PromotionDismissalReason::NO_THANKS, entry_point_);
17 } 103 }
104
105 std::string DesktopIOSPromotionController::GetUsersRecoveryPhoneNumber() {
106 return recovery_number_;
107 }
108
109 void DesktopIOSPromotionController::OnGotPhoneNumber(
110 SMSService::Request* request,
111 bool success,
112 const std::string& number) {
113 if (success)
114 recovery_number_ = number;
115 if (promotion_)
116 promotion_->UpdateRecoveryPhoneLabel();
117 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.QueryPhoneNumberSucceeded",
118 success);
119 }
120
121 void DesktopIOSPromotionController::OnSendSMS(SMSService::Request* request,
122 bool success,
123 const std::string& number) {
124 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.SendSMSSucceeded", success);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698