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..525cf9ab0dc01ad71870184941787d23331358b7 |
| --- /dev/null |
| +++ b/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm |
| @@ -0,0 +1,80 @@ |
| +// 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.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/browser_state/chrome_browser_state.h" |
| +#include "ios/chrome/browser/desktop_promotion/desktop_promotion_prefs.h" |
| +#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| + |
| +namespace { |
| + |
| +const int kMaxEntrypoints = 5; |
|
pkl (ping after 24h if needed)
2017/01/18 23:47:02
What is the maximum number of entry points?
I'm co
mrefaat1
2017/01/19 05:17:30
Required by uma when logging count/enum .
|
| +const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
| + "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| + "HistoryPage"}; |
| +const char kSMSSentIOSSigninReasonHistogram[] = |
| + "DesktopIOSPromotion.SMSSent.IOSSigninReason"; |
| +const char kNoSMSIOSSigninReasonHistogram[] = |
| + "DesktopIOSPromotion.NoSMS.IOSSigninReason"; |
| +} |
| + |
| +DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( |
| + ios::ChromeBrowserState* browser_state) |
| + : browser_state_(browser_state) { |
| + browser_sync::ProfileSyncService* sync_service = |
| + IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| + sync_service->AddObserver(this); |
| +} |
| + |
| +DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { |
| + browser_sync::ProfileSyncService* sync_service = |
| + IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| + sync_service->RemoveObserver(this); |
| +} |
| + |
| +void DesktopPromotionSyncObserver::OnStateChanged() { |
| + browser_sync::ProfileSyncService* sync_service = |
| + IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| + if (!desktop_metrics_logger_initiated_ && |
| + sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { |
|
pkl (ping after 24h if needed)
2017/01/18 23:47:02
If a user (cold) launches Chrome multiple times du
mrefaat1
2017/01/19 05:17:30
thanks for the case, i should check for the comple
|
| + desktop_metrics_logger_initiated_ = true; |
| + PrefService* prefs = browser_state_->GetPrefs(); |
| + double last_interaction = |
| + prefs->GetDouble(prefs::kDesktopIOSPromotionLastInteraction); |
| + base::TimeDelta delta = |
| + base::Time::Now() - base::Time::FromDoubleT(last_interaction); |
| + if (delta.InDays() < 7) { |
| + // This user have seen the promotion in the last 7 days so it may be a |
| + // reason of the installation. |
| + int sms_entrypoint = |
| + prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); |
| + int targeted_entrypoints = |
| + prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints); |
| + for (int i = 1; i < kMaxEntrypoints; i++) { |
|
pkl (ping after 24h if needed)
2017/01/18 23:47:02
It would be helpful to have a comment explaining w
mrefaat1
2017/01/19 05:17:30
Acknowledged.
|
| + if (sms_entrypoint == i) { |
| + UMA_HISTOGRAM_ENUMERATION(kSMSSentIOSSigninReasonHistogram, i, |
| + kMaxEntrypoints); |
| + UMA_HISTOGRAM_COUNTS( |
| + base::StringPrintf( |
| + "DesktopIOSPromotion.%s.CompletionTime", |
|
pkl (ping after 24h if needed)
2017/01/18 23:47:02
This probably doesn't work. See base/metrics/histo
mrefaat1
2017/01/19 05:17:30
I think runtime constant (not compile time constan
|
| + kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), |
| + delta.InHours()); |
| + } else { |
| + if ((1 << i) & targeted_entrypoints) |
| + UMA_HISTOGRAM_ENUMERATION(kNoSMSIOSSigninReasonHistogram, i, |
| + kMaxEntrypoints); |
| + } |
| + } |
| + prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| + } |
| + } |
| +} |