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

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: CL Created 3 years, 11 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.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 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 .
21 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = {
22 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble",
23 "HistoryPage"};
24 const char kSMSSentIOSSigninReasonHistogram[] =
25 "DesktopIOSPromotion.SMSSent.IOSSigninReason";
26 const char kNoSMSIOSSigninReasonHistogram[] =
27 "DesktopIOSPromotion.NoSMS.IOSSigninReason";
28 }
29
30 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver(
31 ios::ChromeBrowserState* browser_state)
32 : browser_state_(browser_state) {
33 browser_sync::ProfileSyncService* sync_service =
34 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
35 sync_service->AddObserver(this);
36 }
37
38 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() {
39 browser_sync::ProfileSyncService* sync_service =
40 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
41 sync_service->RemoveObserver(this);
42 }
43
44 void DesktopPromotionSyncObserver::OnStateChanged() {
45 browser_sync::ProfileSyncService* sync_service =
46 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_);
47 if (!desktop_metrics_logger_initiated_ &&
48 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
49 desktop_metrics_logger_initiated_ = true;
50 PrefService* prefs = browser_state_->GetPrefs();
51 double last_interaction =
52 prefs->GetDouble(prefs::kDesktopIOSPromotionLastInteraction);
53 base::TimeDelta delta =
54 base::Time::Now() - base::Time::FromDoubleT(last_interaction);
55 if (delta.InDays() < 7) {
56 // This user have seen the promotion in the last 7 days so it may be a
57 // reason of the installation.
58 int sms_entrypoint =
59 prefs->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint);
60 int targeted_entrypoints =
61 prefs->GetInteger(prefs::kDesktopIOSPromotionTargetedEntryPoints);
62 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.
63 if (sms_entrypoint == i) {
64 UMA_HISTOGRAM_ENUMERATION(kSMSSentIOSSigninReasonHistogram, i,
65 kMaxEntrypoints);
66 UMA_HISTOGRAM_COUNTS(
67 base::StringPrintf(
68 "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
69 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]),
70 delta.InHours());
71 } else {
72 if ((1 << i) & targeted_entrypoints)
73 UMA_HISTOGRAM_ENUMERATION(kNoSMSIOSSigninReasonHistogram, i,
74 kMaxEntrypoints);
75 }
76 }
77 prefs->SetBoolean(prefs::kDesktopIOSPromotionDone, true);
78 }
79 }
80 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.h ('k') | ios/chrome/browser/prefs/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698