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

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: Minor changes 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/process/process_handle.h"
Ilya Sherman 2013/09/12 04:45:45 nit: No longer needed?
jdomingos 2013/09/12 12:01:01 Done.
10 #include "base/rand_util.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h"
13 #include "base/time/time.h"
Ilya Sherman 2013/09/12 04:45:45 nit: No longer needed?
14 #include "url/gurl.h"
15
16 namespace password_manager_metrics_util {
17
18 namespace {
19
20 // The number of domain group.
Ilya Sherman 2013/09/12 04:45:45 nit: "group" -> "groups"
jdomingos 2013/09/12 12:01:01 Done.
21 const size_t kGroupNumber = 20u;
Ilya Sherman 2013/09/12 04:45:45 nit: "kNumGroups"
jdomingos 2013/09/12 12:01:01 Done.
22
23 } // namespace
24
25 // Contains a monitored domain name and all the group IDs which contain
26 // domain name.
27 struct DomainGroupsPair {
28 const char* const domain_name;
29 const int group_ids[kGroupsPerDomain];
30 };
31
32 unsigned int g_random_group_id = kGroupsPerDomain;
Ilya Sherman 2013/09/12 04:45:45 Please always prefer size_t or one of the uint* ty
Ilya Sherman 2013/09/12 04:45:45 This should be declared in the anonymous namespace
jdomingos 2013/09/12 12:01:01 Done.
jdomingos 2013/09/12 12:01:01 Done.
33
34 // Generate an id in range [0, |kGroupsPerDomain|).
35 // If the |random_group_id| is equal to its initial value (|kGroupsPerDomain|),
36 // the value of |random_id| is not changed.
37 void GenerateRandomId() {
38 // For each session, the user uses only one group for each website.
39 if (g_random_group_id == kGroupsPerDomain)
40 g_random_group_id = base::RandGenerator(kGroupsPerDomain);
41 }
42
43 void SetRandomIdForTesting(unsigned int value) {
44 g_random_group_id = value;
45 }
46
47 std::string AppendGroup(unsigned int group_id) {
48 return "group_" + base::IntToString(group_id);
Ilya Sherman 2013/09/12 04:45:45 Seems like this ought to return an empty string if
jdomingos 2013/09/12 12:01:01 Done.
49 }
Ilya Sherman 2013/09/12 04:45:45 Please make sure that the order of the functions i
jdomingos 2013/09/12 12:01:01 Done.
50
51 unsigned int MonitoredDomainGroupId(const std::string& url_host) {
52 // This array contains each monitored websites together with all ids of
Ilya Sherman 2013/09/12 04:45:45 nit: "websites" -> "website"
jdomingos 2013/09/12 12:01:01 Done.
53 // groups which contain the website. Each website appears |kGroupsPerDomain|
54 // times and every |group_ids| is different. For more information about the
Ilya Sherman 2013/09/12 04:45:45 nit: Possible rephrasing of "Each website appears
jdomingos 2013/09/12 12:01:01 Done.
55 // the algorithm used see http://goo.gl/vUuFd5.
56 static const DomainGroupsPair kDomainMapping[] = {
57 {"google.com", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
58 {"yahoo.com", {1, 2, 3, 4, 5, 11, 12, 13, 14, 15}},
59 {"baidu.com", {1, 2, 3, 4, 6, 7, 11, 12, 16, 17}},
60 {"wikipedia.org", {1, 2, 3, 4, 5, 6, 11, 12, 16, 18}},
61 {"linkedin.com", {1, 6, 8, 11, 13, 14, 15, 16, 17, 19}},
62 {"twitter.com", {5, 6, 7, 8, 9, 11, 13, 17, 19, 20}},
63 {"live.com", {7, 8, 9, 10, 13, 14, 16, 17, 18, 20}},
64 {"amazon.com", {2, 5, 9, 10, 12, 14, 15, 18, 19, 20}},
65 {"ebay.com", {3, 7, 9, 10, 14, 15, 17, 18, 19, 20}},
66 {"tumblr.com", {4, 8, 10, 12, 13, 15, 16, 18, 19, 20}},
67 };
68 const size_t kDomainMappingLength = arraysize(kDomainMapping);
69
70 GenerateRandomId();
71
72 GURL url(url_host);
73 for (size_t i = 0; i < kDomainMappingLength; ++i) {
74 std::string domain = kDomainMapping[i].domain_name;
Ilya Sherman 2013/09/12 04:45:45 nit: Not a big deal, but this seems like an unnece
jdomingos 2013/09/12 12:01:01 Done.
75 if (url.DomainIs(domain.c_str()))
76 return kDomainMapping[i].group_ids[g_random_group_id];
77 }
78 return 0;
79 }
80
81 void LogUMAHistogramEnumeration(const std::string& name,
82 int sample,
83 int boundary_value) {
84 DCHECK_LT(sample, boundary_value);
85
86 // Note: This leaks memory, which is expected behavior.
87 base::HistogramBase* histogram =
88 base::LinearHistogram::FactoryGet(
89 name,
90 1,
91 boundary_value,
92 boundary_value + 1,
93 base::HistogramBase::kUmaTargetedHistogramFlag);
94 histogram->Add(sample);
95 }
96
97 void LogUMAHistogramCounts(const std::string& name, int sample) {
98 // Note: This leaks memory, which is expected behavior.
99 base::HistogramBase* histogram =
100 base::Histogram::FactoryGet(
101 name,
102 1,
103 1000000,
104 kGroupNumber,
105 base::HistogramBase::kUmaTargetedHistogramFlag);
106 histogram->Add(sample);
107 }
108
109 void LogUMAHistogramBoolean(const std::string& name, bool sample) {
110 // Note: This leaks memory, which is expected behavior.
111 base::HistogramBase* histogram =
112 base::BooleanHistogram::FactoryGet(
113 name,
114 base::Histogram::kNoFlags);
115 histogram->AddBoolean(sample);
116 }
117
118 } // namespace password_manager_metrics_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698