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_macros.h" | |
| 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/desktop_promotion/desktop_promotion_prefs.h" | |
| 15 #include "ios/chrome/browser/desktop_promotion/histogram_macros.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { | |
| 20 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", | |
| 21 "HistoryPage"}; | |
|
sdefresne
2017/01/26 17:03:25
Can you put a comma after "HistoryPage" so that cl
mrefaat
2017/01/26 23:34:12
Done.
| |
| 22 } | |
| 23 | |
| 24 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( | |
| 25 PrefService* pref_service, | |
| 26 browser_sync::ProfileSyncService* sync_service) | |
| 27 : pref_service_(pref_service), sync_service_(sync_service) { | |
| 28 DCHECK(pref_service_); | |
| 29 DCHECK(sync_service_); | |
| 30 sync_service_->AddObserver(this); | |
| 31 } | |
| 32 | |
| 33 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { | |
| 34 sync_service_->RemoveObserver(this); | |
| 35 } | |
| 36 | |
| 37 void DesktopPromotionSyncObserver::OnStateChanged() { | |
| 38 if (desktop_metrics_logger_initiated_ || | |
| 39 !sync_service_->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { | |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 desktop_metrics_logger_initiated_ = true; | |
| 44 bool done_logging = | |
| 45 pref_service_->GetBoolean(prefs::kDesktopIOSPromotionDone); | |
| 46 double last_impression = | |
| 47 pref_service_->GetDouble(prefs::kDesktopIOSPromotionLastImpression); | |
| 48 base::TimeDelta delta = | |
| 49 base::Time::Now() - base::Time::FromDoubleT(last_impression); | |
| 50 if (done_logging || delta.InDays() >= 7) { | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 // This user have seen the promotion in the last 7 days so it may be a | |
| 55 // reason of the installation. | |
| 56 int sms_entrypoint = | |
| 57 pref_service_->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); | |
| 58 int targeted_entrypoints = | |
| 59 pref_service_->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints); | |
| 60 | |
| 61 // Entry points are represented on the preference by integers [1..4]. | |
|
Mark P
2017/01/26 18:55:15
Where is the meaning of these entry points defined
mrefaat
2017/01/26 23:34:12
The meaning will be set on the desktop side code,
| |
| 62 int entrypoint_prefixes_count = | |
| 63 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); | |
| 64 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { | |
| 65 if (sms_entrypoint == i) { | |
| 66 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason", | |
| 67 i, entrypoint_prefixes_count + 1); | |
| 68 UMA_HISTOGRAM_COUNT_1000_NO_CACHE( | |
|
Mark P
2017/01/26 18:55:15
Please don't use histogram macros from chromecast/
mrefaat
2017/01/26 23:34:12
These are not chromecast macros' - i defined anoth
| |
| 69 base::StringPrintf( | |
| 70 "DesktopIOSPromotion.%s.CompletionTime", | |
| 71 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), | |
| 72 delta.InHours()); | |
|
Mark P
2017/01/26 18:55:15
Consider explicitly emitting something (0?) if thi
mrefaat
2017/01/26 23:34:12
Acknowledged.
| |
| 73 } else { | |
| 74 // If the user saw this promotion type, log that it could be a reason | |
| 75 // for the signin. | |
| 76 if ((1 << i) & targeted_entrypoints) | |
| 77 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason", | |
| 78 i, entrypoint_prefixes_count + 1); | |
| 79 } | |
| 80 } | |
| 81 pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true); | |
| 82 } | |
| OLD | NEW |