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

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

Powered by Google App Engine
This is Rietveld 408576698