Chromium Code Reviews| 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 | |
| 27 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( | |
| 28 PrefService* pref_service, | |
| 29 browser_sync::ProfileSyncService* sync_service) | |
| 30 : pref_service_(pref_service), sync_service_(sync_service) { | |
| 31 DCHECK(pref_service_); | |
| 32 DCHECK(sync_service_); | |
| 33 sync_service_->AddObserver(this); | |
| 34 } | |
| 35 | |
| 36 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { | |
| 37 sync_service_->RemoveObserver(this); | |
| 38 } | |
| 39 | |
| 40 void DesktopPromotionSyncObserver::OnStateChanged() { | |
| 41 if (desktop_metrics_logger_initiated_ || | |
| 42 !sync_service_->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 desktop_metrics_logger_initiated_ = true; | |
| 47 bool done_logging = | |
| 48 pref_service_->GetBoolean(prefs::kDesktopIOSPromotionDone); | |
| 49 double last_impression = | |
| 50 pref_service_->GetDouble(prefs::kDesktopIOSPromotionLastImpression); | |
| 51 base::TimeDelta delta = | |
| 52 base::Time::Now() - base::Time::FromDoubleT(last_impression); | |
| 53 if (done_logging || delta.InDays() >= 7) { | |
| 54 return; | |
| 55 } | |
| 56 | |
| 57 // This user have seen the promotion in the last 7 days so it may be a | |
| 58 // reason of the installation. | |
| 59 int sms_entrypoint = | |
| 60 pref_service_->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); | |
| 61 int shown_entrypoints = | |
| 62 pref_service_->GetInteger(prefs::kDesktopIOSPromotionShownEntryPoints); | |
| 63 | |
| 64 // Entry points are represented on the preference by integers [1..4]. | |
| 65 // TODO(crbug.com/681885): Add reference to the Entry point Constants defined | |
| 66 // in the | |
|
Mark P
2017/01/27 18:58:59
nit: formatting
mrefaat
2017/01/27 19:58:41
Done.
| |
| 67 // desktop code side. | |
| 68 int entrypoint_prefixes_count = | |
| 69 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); | |
| 70 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { | |
| 71 if (sms_entrypoint == i) { | |
| 72 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason", | |
| 73 i, entrypoint_prefixes_count + 1); | |
| 74 base::Histogram::FactoryGet( | |
| 75 base::StringPrintf( | |
| 76 "DesktopIOSPromotion.%s.CompletionTime", | |
| 77 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), | |
| 78 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag) | |
|
Mark P
2017/01/27 18:58:59
Something seems wrong here.
In the DesktopIOSPromo
mrefaat
2017/01/27 19:58:41
It's only logged if the user saw a promotion on la
| |
| 79 ->Add(std::max(0, delta.InHours())); | |
| 80 } else { | |
| 81 // If the user saw this promotion type, log that it could be a reason | |
| 82 // for the signin. | |
| 83 if ((1 << i) & shown_entrypoints) | |
| 84 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason", | |
| 85 i, entrypoint_prefixes_count + 1); | |
| 86 } | |
| 87 } | |
| 88 pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true); | |
| 89 } | |
| OLD | NEW |