| 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 #import "ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <memory> |
| 9 |
| 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/time/time.h" |
| 13 #include "components/browser_sync/profile_sync_service.h" |
| 14 #include "components/prefs/pref_service.h" |
| 15 #include "ios/chrome/browser/pref_names.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // These values are written to logs. New values can be added, but existing |
| 20 // values must never be reordered or deleted and reused. |
| 21 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
| 22 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| 23 "HistoryPage", |
| 24 }; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( |
| 29 PrefService* pref_service, |
| 30 browser_sync::ProfileSyncService* sync_service) |
| 31 : pref_service_(pref_service), sync_service_(sync_service) { |
| 32 DCHECK(pref_service_); |
| 33 DCHECK(sync_service_); |
| 34 sync_service_->AddObserver(this); |
| 35 } |
| 36 |
| 37 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { |
| 38 sync_service_->RemoveObserver(this); |
| 39 } |
| 40 |
| 41 void DesktopPromotionSyncObserver::OnStateChanged() { |
| 42 if (desktop_metrics_logger_initiated_ || |
| 43 !sync_service_->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { |
| 44 return; |
| 45 } |
| 46 |
| 47 desktop_metrics_logger_initiated_ = true; |
| 48 bool done_logging = |
| 49 pref_service_->GetBoolean(prefs::kDesktopIOSPromotionDone); |
| 50 double last_impression = |
| 51 pref_service_->GetDouble(prefs::kDesktopIOSPromotionLastImpression); |
| 52 base::TimeDelta delta = |
| 53 base::Time::Now() - base::Time::FromDoubleT(last_impression); |
| 54 if (done_logging || delta.InDays() >= 7) { |
| 55 sync_service_->RemoveObserver(this); |
| 56 return; |
| 57 } |
| 58 |
| 59 // This user have seen the promotion in the last 7 days so it may be a |
| 60 // reason of the installation. |
| 61 int sms_entrypoint = |
| 62 pref_service_->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); |
| 63 int shown_entrypoints = |
| 64 pref_service_->GetInteger(prefs::kDesktopIOSPromotionShownEntryPoints); |
| 65 |
| 66 // Entry points are represented on the preference by integers [1..4]. |
| 67 // TODO(crbug.com/681885): Add reference to the Entry point Constants defined |
| 68 // in the desktop code side. |
| 69 int entrypoint_prefixes_count = |
| 70 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); |
| 71 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { |
| 72 if (sms_entrypoint == i) { |
| 73 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason", |
| 74 i, entrypoint_prefixes_count + 1); |
| 75 // If the time delta is negative due to client bad clock we log 0 instead. |
| 76 base::Histogram::FactoryGet( |
| 77 base::StringPrintf( |
| 78 "DesktopIOSPromotion.%s.SMSToSigninTime", |
| 79 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), |
| 80 1, 168, 24, base::Histogram::kUmaTargetedHistogramFlag) |
| 81 ->Add(std::max(0, delta.InHours())); |
| 82 } else { |
| 83 // If the user saw this promotion type, log that it could be a reason |
| 84 // for the signin. |
| 85 if ((1 << i) & shown_entrypoints) |
| 86 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason", |
| 87 i, entrypoint_prefixes_count + 1); |
| 88 } |
| 89 } |
| 90 pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| 91 sync_service_->RemoveObserver(this); |
| 92 } |
| OLD | NEW |