Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
|
sdefresne
2017/01/30 15:47:19
Why is this file a .mm instead of a .cc? It looks
| |
| 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 | |
|
sdefresne
2017/01/30 15:47:19
nit: remove blank newline (or add one before closi
mrefaat
2017/01/30 16:32:23
Done.
| |
| 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 } | |
|
sdefresne
2017/01/30 15:47:19
nit: add "// namespace"
mrefaat
2017/01/30 16:32:23
Done.
| |
| 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 desktop code side. | |
| 67 int entrypoint_prefixes_count = | |
| 68 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); | |
| 69 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { | |
| 70 if (sms_entrypoint == i) { | |
| 71 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason", | |
| 72 i, entrypoint_prefixes_count + 1); | |
| 73 // If the time delta is negative due to client bad clock we log 0 instead. | |
| 74 base::Histogram::FactoryGet( | |
| 75 base::StringPrintf( | |
| 76 "DesktopIOSPromotion.%s.SMSToSigninTime", | |
| 77 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), | |
| 78 1, 168, 24, base::Histogram::kUmaTargetedHistogramFlag) | |
| 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); | |
|
sdefresne
2017/01/30 15:47:19
nit: should this instance unregister as an Observe
mrefaat
2017/01/30 16:32:23
Done.
| |
| 89 } | |
| OLD | NEW |