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 <memory> | |
| 8 | |
| 9 #include "base/metrics/histogram.h" | |
|
Mark P
2017/01/19 23:35:48
nit: use histogram_macros.h
mrefaat
2017/01/20 19:14:59
Done.
| |
| 10 #include "base/strings/stringprintf.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "components/browser_sync/profile_sync_service.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | |
| 15 #include "ios/chrome/browser/desktop_promotion/desktop_promotion_prefs.h" | |
| 16 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Needed by UMA_HISTOGRAM_ENUM as the max value that shouldn't be exceeded. | |
| 21 const int kMaxEntryPoints = 5; | |
|
Mark P
2017/01/19 23:35:48
Can't you do arraysize(kDesktopIOSPromotionEntrypo
mrefaat
2017/01/20 19:14:59
Acknowledged.
| |
| 22 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { | |
| 23 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", | |
| 24 "HistoryPage"}; | |
| 25 const char kSMSSentIOSSigninReasonHistogram[] = | |
|
Mark P
2017/01/19 23:35:48
nit: only used in one place; don't need a special
mrefaat
2017/01/20 19:14:59
Acknowledged.
| |
| 26 "DesktopIOSPromotion.SMSSent.IOSSigninReason"; | |
|
Mark P
2017/01/19 23:35:48
These two histograms aren't listed in histograms.x
mrefaat
2017/01/20 19:14:59
they are defined by a suffix in histograms.xml
Mark P
2017/01/20 19:40:05
Ah, I forgot about histogram_suffixes supporting p
mrefaat
2017/01/24 19:57:19
Acknowledged.
| |
| 27 const char kNoSMSIOSSigninReasonHistogram[] = | |
| 28 "DesktopIOSPromotion.NoSMS.IOSSigninReason"; | |
| 29 } | |
| 30 | |
| 31 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( | |
| 32 ios::ChromeBrowserState* browser_state) | |
| 33 : browser_state_(browser_state) { | |
| 34 browser_sync::ProfileSyncService* sync_service = | |
| 35 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); | |
| 36 sync_service->AddObserver(this); | |
| 37 } | |
| 38 | |
| 39 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { | |
| 40 browser_sync::ProfileSyncService* sync_service = | |
| 41 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); | |
| 42 sync_service->RemoveObserver(this); | |
| 43 } | |
| 44 | |
| 45 void DesktopPromotionSyncObserver::OnStateChanged() { | |
| 46 browser_sync::ProfileSyncService* sync_service = | |
| 47 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); | |
| 48 if (!desktop_metrics_logger_initiated_ && | |
| 49 sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { | |
| 50 desktop_metrics_logger_initiated_ = true; | |
| 51 PrefService* prefs = browser_state_->GetPrefs(); | |
| 52 bool done_logging = prefs->GetBoolean(prefs::kDesktopIOSPromotionDone); | |
| 53 double last_impression = | |
| 54 prefs->GetDouble(prefs::kDesktopIOSPromotionLastImpression); | |
| 55 base::TimeDelta delta = | |
| 56 base::Time::Now() - base::Time::FromDoubleT(last_impression); | |
| 57 if (!done_logging && delta.InDays() < 7) { | |
| 58 // This user have seen the promotion in the last 7 days so it may be a | |
| 59 // reason of the installation. | |
| 60 int sms_entrypoint = | |
| 61 prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); | |
| 62 int targeted_entrypoints = | |
| 63 prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints); | |
| 64 // Entry points are represented on the preference by integers [1..4]. | |
| 65 for (int i = 1; i < kMaxEntryPoints; i++) { | |
| 66 if (sms_entrypoint == i) { | |
| 67 UMA_HISTOGRAM_ENUMERATION(kSMSSentIOSSigninReasonHistogram, i, | |
| 68 kMaxEntryPoints); | |
| 69 UMA_HISTOGRAM_COUNTS( | |
| 70 base::StringPrintf( | |
|
Mark P
2017/01/19 23:35:48
You cannot use a UMA_HISTOGRAM macro with a not-st
mrefaat
2017/01/20 19:14:59
From histogram_macros.h: // All of these macros mu
Mark P
2017/01/20 19:40:05
You cannot use a StringPrintf here. From histogra
mrefaat
2017/01/24 19:57:19
Thanks for the advice, will update that
| |
| 71 "DesktopIOSPromotion.%s.CompletionTime", | |
| 72 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), | |
| 73 delta.InHours()); | |
| 74 } else { | |
| 75 if ((1 << i) & targeted_entrypoints) | |
| 76 UMA_HISTOGRAM_ENUMERATION(kNoSMSIOSSigninReasonHistogram, i, | |
|
Mark P
2017/01/19 23:35:48
I know this histogram isn't yet documented. Yet,
mrefaat
2017/01/20 19:14:59
Acknowledged.
| |
| 77 kMaxEntryPoints); | |
| 78 } | |
| 79 } | |
| 80 prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true); | |
| 81 } | |
| 82 } | |
| 83 } | |
| OLD | NEW |