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

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: create new file for sync service & move prefs to pref_names.h 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/desktop_promotion/histogram_macros.h"
15 #include "ios/chrome/browser/pref_names.h"
16
17 namespace {
18
19 const char* kDesktopIOSPromotionEntrypointHistogramPrefix[] = {
Mark P 2017/01/26 23:47:24 Please put a warning here, as discussed.
mrefaat 2017/01/27 18:29:42 Done.
20 "SavePasswordsNewBubble", "BookmarksNewBubble", "BookmarksExistingBubble",
21 "HistoryPage",
22 };
23 }
24
25 DesktopPromotionSyncObserver::DesktopPromotionSyncObserver(
26 PrefService* pref_service,
27 browser_sync::ProfileSyncService* sync_service)
28 : pref_service_(pref_service), sync_service_(sync_service) {
29 DCHECK(pref_service_);
30 DCHECK(sync_service_);
31 sync_service_->AddObserver(this);
32 }
33
34 DesktopPromotionSyncObserver::~DesktopPromotionSyncObserver() {
35 sync_service_->RemoveObserver(this);
36 }
37
38 void DesktopPromotionSyncObserver::OnStateChanged() {
39 if (desktop_metrics_logger_initiated_ ||
40 !sync_service_->GetActiveDataTypes().Has(syncer::PRIORITY_PREFERENCES)) {
41 return;
42 }
43
44 desktop_metrics_logger_initiated_ = true;
45 bool done_logging =
46 pref_service_->GetBoolean(prefs::kDesktopIOSPromotionDone);
47 double last_impression =
48 pref_service_->GetDouble(prefs::kDesktopIOSPromotionLastImpression);
49 base::TimeDelta delta =
50 base::Time::Now() - base::Time::FromDoubleT(last_impression);
51 if (done_logging || delta.InDays() >= 7) {
52 return;
53 }
54
55 // This user have seen the promotion in the last 7 days so it may be a
56 // reason of the installation.
57 int sms_entrypoint =
58 pref_service_->GetInteger(prefs::kDesktopIOSPromotionSMSEntryPoint);
59 int shown_entrypoints =
60 pref_service_->GetInteger(prefs::kDesktopIOSPromotionShownEntryPoints);
61
62 // Entry points are represented on the preference by integers [1..4].
63 // TODO(681885): Add reference to the Entry point Constants defined in the
Mark P 2017/01/26 23:47:24 fwiw, I don't think I've ever see TODO with bug nu
mrefaat 2017/01/27 18:29:42 i should have done it crbut.com/bug number i was
64 // desktop code side.
65 int entrypoint_prefixes_count =
66 arraysize(kDesktopIOSPromotionEntrypointHistogramPrefix);
67 for (int i = 1; i < entrypoint_prefixes_count + 1; i++) {
68 if (sms_entrypoint == i) {
69 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.SMSSent.IOSSigninReason",
70 i, entrypoint_prefixes_count + 1);
71 UMA_HISTOGRAM_COUNT_1000_NO_CACHE(
Mark P 2017/01/26 23:47:24 A new header file to define a series of three macr
mrefaat 2017/01/27 18:29:42 removed it.
72 base::StringPrintf(
73 "DesktopIOSPromotion.%s.CompletionTime",
74 kDesktopIOSPromotionEntrypointHistogramPrefix[i - 1]),
75 MAX(0, delta.InHours()));
Mark P 2017/01/27 17:35:01 BTW, where are you getting MAX from? I normally s
mrefaat 2017/01/27 18:29:42 replaced by std:max - MAX is predifned in Foundati
76 } else {
77 // If the user saw this promotion type, log that it could be a reason
78 // for the signin.
79 if ((1 << i) & shown_entrypoints)
80 UMA_HISTOGRAM_ENUMERATION("DesktopIOSPromotion.NoSMS.IOSSigninReason",
81 i, entrypoint_prefixes_count + 1);
82 }
83 }
84 pref_service_->SetBoolean(prefs::kDesktopIOSPromotionDone, true);
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698