OLD | NEW |
---|---|
(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" | |
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" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace password_manager_metrics_util { | |
17 | |
18 // Contains a monitored domain name and all the group IDs which contain | |
19 // domain name. | |
20 struct DomainGroupsPair { | |
21 const char* domain_name; | |
vabr (Chromium)
2013/09/11 17:31:24
nit: const char* const
(Maybe that's what Ilya mea
jdomingos
2013/09/11 19:15:28
Done.
| |
22 const int group_ids[kGroupsPerDomain]; | |
23 }; | |
24 | |
25 static unsigned int random_group_id = kGroupsPerDomain; | |
vabr (Chromium)
2013/09/11 17:31:24
Please prepend "g_" to the variable's name, as the
jdomingos
2013/09/11 19:15:28
Done.
| |
26 | |
27 // Generate an id in range [0, |kGroupsPerDomain|). | |
28 // If the |random_group_id| is equal to its initial value (|kGroupsPerDomain|), | |
29 // the value of |random_id| is not changed. | |
30 void generateRandomId() { | |
31 // For each session, the user uses only one group for each website. | |
32 if (random_group_id == kGroupsPerDomain) | |
33 random_group_id = base::RandGenerator(kGroupsPerDomain); | |
34 } | |
35 | |
36 // Only used in the IsDomainNameMonitoredTest. | |
vabr (Chromium)
2013/09/11 17:31:24
Please remove this comment. It's duplicated, and s
jdomingos
2013/09/11 19:15:28
Done.
| |
37 void setRandomId(unsigned int value) { | |
38 random_group_id = value; | |
39 } | |
40 | |
41 std::string MonitoredDomainGroup(const std::string& url_host) { | |
42 // This array contains each monitored websites together with all id of | |
vabr (Chromium)
2013/09/11 17:31:24
nit: id -> ids
jdomingos
2013/09/11 19:15:28
Done.
| |
43 // groups which contain the website. Each website appears |kGroupsPerDomain| | |
44 // times and every |group_ids| are different. For more information about the | |
vabr (Chromium)
2013/09/11 17:31:24
nit: "every |group_ids| are different" -> "every I
jdomingos
2013/09/11 19:15:28
Done.
| |
45 // the algorithm used see http://goo.gl/vUuFd5. | |
46 static const DomainGroupsPair kDomainMapping[] = { | |
47 {"google.com", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, | |
48 {"yahoo.com", {1, 2, 3, 4, 5, 11, 12, 13, 14, 15}}, | |
49 {"baidu.com", {1, 2, 3, 4, 6, 7, 11, 12, 16, 17}}, | |
50 {"wikipedia.org", {1, 2, 3, 4, 5, 6, 11, 12, 16, 18}}, | |
51 {"linkedin.com", {1, 6, 8, 11, 13, 14, 15, 16, 17, 19}}, | |
52 {"twitter.com", {5, 6, 7, 8, 9, 11, 13, 17, 19, 20}}, | |
53 {"live.com", {7, 8, 9, 10, 13, 14, 16, 17, 18, 20}}, | |
54 {"amazon.com", {2, 5, 9, 10, 12, 14, 15, 18, 19, 20}}, | |
55 {"ebay.com", {3, 7, 9, 10, 14, 15, 17, 18, 19, 20}}, | |
56 {"tumblr.com", {4, 8, 10, 12, 13, 15, 16, 18, 19, 20}}, | |
57 }; | |
58 const size_t kDomainMappingLength = arraysize(kDomainMapping); | |
59 | |
60 generateRandomId(); | |
61 | |
62 GURL url(url_host); | |
63 for (size_t i = 0; i < kDomainMappingLength; ++i) { | |
64 std::string domain = kDomainMapping[i].domain_name; | |
65 if (url.DomainIs(domain.c_str())) { | |
66 return "group_" + base::IntToString( | |
67 kDomainMapping[i].group_ids[random_group_id]); | |
68 } | |
69 } | |
70 return std::string(); | |
71 } | |
72 | |
73 void LogUMAHistogramEnumeration(const std::string& name, | |
74 int sample, | |
75 int boundary_value) { | |
76 DCHECK_LT(sample, boundary_value); | |
77 | |
78 // Note: This leaks memory, which is expected behavior. | |
79 base::HistogramBase* histogram = | |
80 base::LinearHistogram::FactoryGet( | |
81 name, | |
82 1, | |
83 boundary_value, | |
84 boundary_value + 1, | |
85 base::HistogramBase::kUmaTargetedHistogramFlag); | |
86 histogram->Add(sample); | |
87 } | |
88 | |
89 void LogUMAHistogramTimes(const std::string& name, | |
vabr (Chromium)
2013/09/11 17:31:24
Do you still need this function? If not, please re
jdomingos
2013/09/11 19:15:28
Done.
| |
90 const base::TimeDelta& duration) { | |
91 // Note: This leaks memory, which is expected behavior. | |
92 base::HistogramBase* histogram = | |
93 base::Histogram::FactoryTimeGet( | |
94 name, | |
95 base::TimeDelta::FromMilliseconds(1), | |
96 base::TimeDelta::FromSeconds(10), | |
97 50, | |
98 base::HistogramBase::kUmaTargetedHistogramFlag); | |
99 histogram->AddTime(duration); | |
100 } | |
101 | |
102 void LogUMAHistogramCounts(const std::string& name, int sample) { | |
103 // Note: This leaks memory, which is expected behavior. | |
104 base::HistogramBase* histogram = | |
105 base::Histogram::FactoryGet( | |
106 name, | |
107 1, | |
108 1000000, | |
109 kGroupNumber, | |
110 base::HistogramBase::kUmaTargetedHistogramFlag); | |
111 histogram->Add(sample); | |
112 } | |
113 | |
114 void LogUMAHistogramBoolean(const std::string& name, bool sample) { | |
115 // Note: This leaks memory, which is expected behavior. | |
116 base::HistogramBase* histogram = | |
117 base::BooleanHistogram::FactoryGet( | |
118 name, | |
119 base::Histogram::kNoFlags); | |
120 histogram->AddBoolean(sample); | |
121 } | |
122 | |
123 } // namespace password_manager_metrics_util | |
OLD | NEW |