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..48eff69dcdb4c06352fc3e882ac34603ced8b54e |
| --- /dev/null |
| +++ b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm |
| @@ -0,0 +1,82 @@ |
| +// 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/desktop_promotion_prefs.h" |
| +#include "ios/chrome/browser/desktop_promotion/histogram_macros.h" |
| + |
| +namespace { |
| + |
| +const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
| + "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| + "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.
|
| +} |
| + |
| +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 targeted_entrypoints = |
| + pref_service_->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints); |
| + |
| + // 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,
|
| + 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 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
|
| + base::StringPrintf( |
| + "DesktopIOSPromotion.%s.CompletionTime", |
| + kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), |
| + 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.
|
| + } else { |
| + // If the user saw this promotion type, log that it could be a reason |
| + // for the signin. |
| + if ((1 << i) & targeted_entrypoints) |
| + UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason", |
| + i, entrypoint_prefixes_count + 1); |
| + } |
| + } |
| + pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| +} |