| 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/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 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = { |
| 21 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble", |
| 22 "HistoryPage"}; |
| 23 } |
| 24 |
| 25 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver( |
| 26 ios::ChromeBrowserState* browser_state) |
| 27 : browser_state_(browser_state) { |
| 28 browser_sync::ProfileSyncService* sync_service = |
| 29 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| 30 sync_service->AddObserver(this); |
| 31 } |
| 32 |
| 33 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() { |
| 34 browser_sync::ProfileSyncService* sync_service = |
| 35 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| 36 sync_service->RemoveObserver(this); |
| 37 } |
| 38 |
| 39 void DesktopPromotionSyncObserver::OnStateChanged() { |
| 40 browser_sync::ProfileSyncService* sync_service = |
| 41 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| 42 if (!desktop_metrics_logger_initiated_ && |
| 43 sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) { |
| 44 desktop_metrics_logger_initiated_ = true; |
| 45 PrefService* prefs = browser_state_->GetPrefs(); |
| 46 bool done_logging = prefs->GetBoolean(prefs::kDesktopIOSPromotionDone); |
| 47 double last_impression = |
| 48 prefs->GetDouble(prefs::kDesktopIOSPromotionLastImpression); |
| 49 base::TimeDelta delta = |
| 50 base::Time::Now() - base::Time::FromDoubleT(last_impression); |
| 51 if (!done_logging && delta.InDays() < 7) { |
| 52 // This user have seen the promotion in the last 7 days so it may be a |
| 53 // reason of the installation. |
| 54 int sms_entrypoint = |
| 55 prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint); |
| 56 int targeted_entrypoints = |
| 57 prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints); |
| 58 |
| 59 // Entry points are represented on the preference by integers [1..4]. |
| 60 int entrypoint_prefixes_count = |
| 61 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix); |
| 62 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) { |
| 63 if (sms_entrypoint == i) { |
| 64 UMA_HISTOGRAM_ENUMERATION( |
| 65 "DesktopIOSPromotion.SMSSent.IOSSigninReason", i, |
| 66 entrypoint_prefixes_count + 1); |
| 67 UMA_HISTOGRAM_COUNTS( |
| 68 base::StringPrintf( |
| 69 "DesktopIOSPromotion.%s.CompletionTime", |
| 70 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]), |
| 71 delta.InHours()); |
| 72 } else { |
| 73 // If the user saw this promotion type, log that it could be a reason |
| 74 // for the signin. |
| 75 if ((1 << i) & targeted_entrypoints) |
| 76 UMA_HISTOGRAM_ENUMERATION( |
| 77 "DesktopIOSPromotion.NoSMS.IOSSigninReason", i, |
| 78 entrypoint_prefixes_count + 1); |
| 79 } |
| 80 } |
| 81 prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true); |
| 82 } |
| 83 } |
| 84 } |
| OLD | NEW |