Chromium Code Reviews| Index: ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm |
| diff --git a/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a9627185a64565eef4e0d4ee2bd5a3e6f28040f |
| --- /dev/null |
| +++ b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.h" |
| + |
| +#include <memory> |
| + |
| +#include "base/metrics/histogram_macros.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "base/time/time.h" |
| +#include "components/browser_sync/profile_sync_service.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "ios/chrome/browser/desktop_promotion/histogram_macros.h" |
| +#include "ios/chrome/browser/pref_names.h" |
| + |
| +namespace { |
| + |
| +const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
|
Mark P
2017/01/26 23:47:24
Please put a warning here, as discussed.
mrefaat
2017/01/27 18:29:42
Done.
|
| + "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| + "HistoryPage", |
| +}; |
| +} |
| + |
| +DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( |
| + PrefService* pref_service, |
| + browser_sync::ProfileSyncService* sync_service) |
| + : pref_service_(pref_service), sync_service_(sync_service) { |
| + DCHECK(pref_service_); |
| + DCHECK(sync_service_); |
| + sync_service_->AddObserver(this); |
| +} |
| + |
| +DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { |
| + sync_service_->RemoveObserver(this); |
| +} |
| + |
| +void DesktopPromotionSyncObserver::OnStateChanged() { |
| + if (desktop_metrics_logger_initiated_ || |
| + !sync_service_->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { |
| + return; |
| + } |
| + |
| + desktop_metrics_logger_initiated_ = true; |
| + bool done_logging = |
| + pref_service_->GetBoolean(prefs::kDesktopIOSPromotionDone); |
| + double last_impression = |
| + pref_service_->GetDouble(prefs::kDesktopIOSPromotionLastImpression); |
| + base::TimeDelta delta = |
| + base::Time::Now() - base::Time::FromDoubleT(last_impression); |
| + if (done_logging || delta.InDays() >= 7) { |
| + return; |
| + } |
| + |
| + // This user have seen the promotion in the last 7 days so it may be a |
| + // reason of the installation. |
| + int sms_entrypoint = |
| + pref_service_->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); |
| + int shown_entrypoints = |
| + pref_service_->GetInteger(prefs::kDesktopIOSPromotionShownEntryPoints); |
| + |
| + // Entry points are represented on the preference by integers [1..4]. |
| + // TODO(681885): Add reference to the Entry point Constants defined in the |
|
Mark P
2017/01/26 23:47:24
fwiw, I don't think I've ever see TODO with bug nu
mrefaat
2017/01/27 18:29:42
i should have done it crbut.com/bug number
i was
|
| + // desktop code side. |
| + int entrypoint_prefixes_count = |
| + arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); |
| + for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { |
| + if (sms_entrypoint == i) { |
| + UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason", |
| + i, entrypoint_prefixes_count + 1); |
| + UMA_HISTOGRAM_COUNT_1000_NO_CACHE( |
|
Mark P
2017/01/26 23:47:24
A new header file to define a series of three macr
mrefaat
2017/01/27 18:29:42
removed it.
|
| + base::StringPrintf( |
| + "DesktopIOSPromotion.%s.CompletionTime", |
| + kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), |
| + MAX(0, delta.InHours())); |
|
Mark P
2017/01/27 17:35:01
BTW, where are you getting MAX from? I normally s
mrefaat
2017/01/27 18:29:42
replaced by std:max - MAX is predifned in Foundati
|
| + } else { |
| + // If the user saw this promotion type, log that it could be a reason |
| + // for the signin. |
| + if ((1 << i) & shown_entrypoints) |
| + UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason", |
| + i, entrypoint_prefixes_count + 1); |
| + } |
| + } |
| + pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| +} |