OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_bubble_c
ontroller.h" |
| 6 |
| 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_factory.h" |
| 15 #include "components/prefs/pref_service.h" |
| 16 |
| 17 DesktopIOSPromotionBubbleController::DesktopIOSPromotionBubbleController( |
| 18 Profile* profile, |
| 19 DesktopIOSPromotionView* promotion_view, |
| 20 desktop_ios_promotion::PromotionEntryPoint entry_point) |
| 21 : DesktopIOSPromotionController(profile, entry_point), |
| 22 sms_service_(SMSServiceFactory::GetForProfile(profile)), |
| 23 promotion_view_(promotion_view), |
| 24 weak_ptr_factory_(this) { |
| 25 sms_service_->QueryPhoneNumber( |
| 26 base::Bind(&DesktopIOSPromotionBubbleController::OnGotPhoneNumber, |
| 27 weak_ptr_factory_.GetWeakPtr())); |
| 28 } |
| 29 |
| 30 DesktopIOSPromotionBubbleController::~DesktopIOSPromotionBubbleController() = |
| 31 default; |
| 32 |
| 33 void DesktopIOSPromotionBubbleController::OnSendSMSClicked() { |
| 34 sms_service_->SendSMS( |
| 35 desktop_ios_promotion::GetSMSID(), |
| 36 base::Bind(&DesktopIOSPromotionBubbleController::OnSendSMS, |
| 37 weak_ptr_factory_.GetWeakPtr())); |
| 38 |
| 39 // Update Profile prefs. |
| 40 profile_prefs()->SetInteger(prefs::kIOSPromotionSMSEntryPoint, |
| 41 static_cast<int>(entry_point())); |
| 42 |
| 43 // Update dismissal reason. |
| 44 SetDismissalReason(desktop_ios_promotion::PromotionDismissalReason::SEND_SMS); |
| 45 } |
| 46 |
| 47 void DesktopIOSPromotionBubbleController::OnNoThanksClicked() { |
| 48 if (entry_point() != |
| 49 desktop_ios_promotion::PromotionEntryPoint::FOOTNOTE_FOLLOWUP_BUBBLE) { |
| 50 PrefService* local_state = g_browser_process->local_state(); |
| 51 local_state->SetBoolean( |
| 52 desktop_ios_promotion::kEntryPointLocalPrefs |
| 53 [static_cast<int>(entry_point())][static_cast<int>( |
| 54 desktop_ios_promotion::EntryPointLocalPrefType::DISMISSED)], |
| 55 true); |
| 56 } |
| 57 SetDismissalReason( |
| 58 desktop_ios_promotion::PromotionDismissalReason::NO_THANKS); |
| 59 } |
| 60 |
| 61 std::string DesktopIOSPromotionBubbleController::GetUsersRecoveryPhoneNumber() { |
| 62 return recovery_number_; |
| 63 } |
| 64 |
| 65 void DesktopIOSPromotionBubbleController::OnGotPhoneNumber( |
| 66 SMSService::Request* request, |
| 67 bool success, |
| 68 const std::string& number) { |
| 69 DCHECK(promotion_view_); |
| 70 if (success) { |
| 71 recovery_number_ = desktop_ios_promotion::FormatPhoneNumber(number); |
| 72 promotion_view_->UpdateRecoveryPhoneLabel(); |
| 73 } |
| 74 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.QueryPhoneNumberSucceeded", |
| 75 success); |
| 76 } |
| 77 |
| 78 void DesktopIOSPromotionBubbleController::OnSendSMS( |
| 79 SMSService::Request* request, |
| 80 bool success, |
| 81 const std::string& number) { |
| 82 UMA_HISTOGRAM_BOOLEAN("DesktopIOSPromotion.SendSMSSucceeded", success); |
| 83 } |
OLD | NEW |