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

Side by Side Diff: chrome/browser/password_manager/password_manager_metrics_util.cc

Issue 23140005: Added of new UMA signals in order to be able to discover early if the "save password" feature gets … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review 9 Created 7 years, 3 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 2013 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 #include "chrome/browser/password_manager/password_manager_metrics_util.h"
6
7 #include "base/basictypes.h"
8 #include "base/metrics/histogram.h"
9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "base/time/time.h"
13 #include "url/gurl.h"
14
15 namespace password_manager_metrics_util {
16
17 namespace {
18
19 // The number of domain groups.
20 const size_t kNumGroups = 20u;
vabr (Chromium) 2013/09/12 13:40:02 Why not kNumGroups = 2 * kGroupsPerDomain? That wo
jdomingos 2013/09/12 16:33:52 Done.
21
22 size_t g_random_group_id = kGroupsPerDomain;
23
24 } // namespace
25
26 // Contains a monitored domain name and all the group IDs which contain
27 // domain name.
28 struct DomainGroupsPair {
29 const char* const domain_name;
30 const int group_ids[kGroupsPerDomain];
31 };
32
33 unsigned int MonitoredDomainGroupId(const std::string& url_host) {
34 // This array contains each monitored website together with all ids of
35 // groups which contain the website. Each website appears in
36 // |kGroupsPerDomain| groups, and each group includes an equal number of
37 // websites, so that no two websites have the same set of groups that they
38 // belong to. All ids are in the range [1, |kNumGroups|].
39 // For more information about the algorithm used see http://goo.gl/vUuFd5.
40 static const DomainGroupsPair kDomainMapping[] = {
41 {"google.com", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
42 {"yahoo.com", {1, 2, 3, 4, 5, 11, 12, 13, 14, 15}},
43 {"baidu.com", {1, 2, 3, 4, 6, 7, 11, 12, 16, 17}},
44 {"wikipedia.org", {1, 2, 3, 4, 5, 6, 11, 12, 16, 18}},
45 {"linkedin.com", {1, 6, 8, 11, 13, 14, 15, 16, 17, 19}},
46 {"twitter.com", {5, 6, 7, 8, 9, 11, 13, 17, 19, 20}},
47 {"live.com", {7, 8, 9, 10, 13, 14, 16, 17, 18, 20}},
48 {"amazon.com", {2, 5, 9, 10, 12, 14, 15, 18, 19, 20}},
49 {"ebay.com", {3, 7, 9, 10, 14, 15, 17, 18, 19, 20}},
50 {"tumblr.com", {4, 8, 10, 12, 13, 15, 16, 18, 19, 20}},
51 };
52 const size_t kDomainMappingLength = arraysize(kDomainMapping);
53
54 GenerateRandomId();
55
56 GURL url(url_host);
57 for (size_t i = 0; i < kDomainMappingLength; ++i) {
58 if (url.DomainIs(kDomainMapping[i].domain_name))
59 return kDomainMapping[i].group_ids[g_random_group_id];
60 }
61 return 0;
62 }
63
64 void LogUMAHistogramEnumeration(const std::string& name,
65 int sample,
66 int boundary_value) {
67 DCHECK_LT(sample, boundary_value);
68
69 // Note: This leaks memory, which is expected behavior.
70 base::HistogramBase* histogram =
71 base::LinearHistogram::FactoryGet(
72 name,
73 1,
74 boundary_value,
75 boundary_value + 1,
76 base::HistogramBase::kUmaTargetedHistogramFlag);
77 histogram->Add(sample);
78 }
79
80 void LogUMAHistogramCounts(const std::string& name, int sample) {
81 // Note: This leaks memory, which is expected behavior.
82 base::HistogramBase* histogram =
83 base::Histogram::FactoryGet(
84 name,
85 1,
86 1000000,
87 kNumGroups,
88 base::HistogramBase::kUmaTargetedHistogramFlag);
89 histogram->Add(sample);
90 }
91
92 void LogUMAHistogramBoolean(const std::string& name, bool sample) {
93 // Note: This leaks memory, which is expected behavior.
94 base::HistogramBase* histogram =
95 base::BooleanHistogram::FactoryGet(
96 name,
97 base::Histogram::kNoFlags);
98 histogram->AddBoolean(sample);
99 }
100
101 // Generate an id in range [0, |kGroupsPerDomain|).
102 // If the |random_group_id| is equal to its initial value (|kGroupsPerDomain|),
103 // the value of |random_id| is not changed.
104 void GenerateRandomId() {
105 // For each session, the user uses only one group for each website.
106 if (g_random_group_id == kGroupsPerDomain)
107 g_random_group_id = base::RandGenerator(kGroupsPerDomain);
108 }
109
110 void SetRandomIdForTesting(unsigned int value) {
111 g_random_group_id = value;
112 }
113
114 std::string GroupIdToString(unsigned int group_id) {
115 if (group_id > 0 && group_id <= kNumGroups)
116 return "group_" + base::IntToString(group_id);
117 return "";
118 }
119
120 } // namespace password_manager_metrics_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698