Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.mm

Issue 2643723004: Add Desktop iOS promotion logging to chrome ios app. (Closed)
Patch Set: Add histogram_macros to desktop_promotion/ Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/desktop_promotion/histogram_macros.h"
17 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
18
19 namespace {
20
21 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = {
22 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble",
23 "HistoryPage"};
24 }
25
26 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver(
27 ios::ChromeBrowserState* browser_state)
28 : browser_state_(browser_state) {
29 browser_sync::ProfileSyncService* sync_service =
sdefresne 2017/01/25 09:52:52 Unless there is no other way around passing the se
mrefaat1 2017/01/26 16:51:19 Acknowledged.
30 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
31 sync_service->AddObserver(this);
32 }
33
34 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() {
35 browser_sync::ProfileSyncService* sync_service =
36 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
37 sync_service->RemoveObserver(this);
38 }
39
40 void DesktopPromotionSyncObserver::OnStateChanged() {
41 browser_sync::ProfileSyncService* sync_service =
42 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
43 if (!desktop_metrics_logger_initiated_ &&
sdefresne 2017/01/25 09:58:22 Unrelated to KeyedService, I think you should swap
mrefaat1 2017/01/26 16:51:19 Acknowledged.
44 sync_service->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) {
45 desktop_metrics_logger_initiated_ = true;
46 PrefService* prefs = browser_state_->GetPrefs();
47 bool done_logging = prefs->GetBoolean(prefs::kDesktopIOSPromotionDone);
48 double last_impression =
49 prefs->GetDouble(prefs::kDesktopIOSPromotionLastImpression);
50 base::TimeDelta delta =
51 base::Time::Now() - base::Time::FromDoubleT(last_impression);
52 if (!done_logging && delta.InDays() < 7) {
53 // This user have seen the promotion in the last 7 days so it may be a
54 // reason of the installation.
55 int sms_entrypoint =
56 prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint);
57 int targeted_entrypoints =
58 prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints);
59
60 // Entry points are represented on the preference by integers [1..4].
61 int entrypoint_prefixes_count =
62 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix);
63 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) {
64 if (sms_entrypoint == i) {
65 UMA_HISTOGRAM_ENUMERATION(
66 "DesktopIOSPromotion.SMSSent.IOSSigninReason", i,
67 entrypoint_prefixes_count + 1);
68 UMA_HISTOGRAM_COUNT_1000_NO_CACHE(
69 base::StringPrintf(
70 "DesktopIOSPromotion.%s.CompletionTime",
71 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]),
72 delta.InHours());
73 } else {
74 // If the user saw this promotion type, log that it could be a reason
75 // for the signin.
76 if ((1 << i) & targeted_entrypoints)
77 UMA_HISTOGRAM_ENUMERATION(
78 "DesktopIOSPromotion.NoSMS.IOSSigninReason", i,
79 entrypoint_prefixes_count + 1);
80 }
81 }
82 prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true);
83 }
84 }
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698