| 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" |
| 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; |
| 22 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
| 23 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| 24 "HistoryPage"}; |
| 25 const char kSMSSentIOSSigninReasonHistogram[] = |
| 26 "DesktopIOSPromotion.SMSSent.IOSSigninReason"; |
| 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( |
| 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, |
| 77 kMaxEntryPoints); |
| 78 } |
| 79 } |
| 80 prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| 81 } |
| 82 } |
| 83 } |
| OLD | NEW |