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/strings/string_util.h" | |
8 | |
9 namespace password_manager_metrics_util { | |
10 | |
11 std::string IsDomainNameMonitored(const std::string& url_host) { | |
12 const char* kMonitoredDomainName[] = { | |
Ilya Sherman
2013/08/30 22:34:42
nit: "const char* const"
jdomingos
2013/09/02 09:58:45
Hi Ilya,
I am wondering if the const you want me
Ilya Sherman
2013/09/03 22:25:21
The second const prevents you from writing code li
| |
13 "google.com", | |
14 "yahoo.com", | |
15 "baidu.com", | |
16 "wikipedia.org", | |
17 "linkedin.com", | |
18 "twitter.com", | |
19 "live.com", | |
20 "amazon.com", | |
21 }; | |
22 const size_t kMonitoredDomainNameLength = arraysize(kMonitoredDomainName); | |
23 | |
24 std::string domain_name; | |
25 for (std::string::size_type i = 0; i < kMonitoredDomainNameLength; ++i) { | |
26 size_t point_position = | |
27 url_host.size() - strlen(kMonitoredDomainName[i]) - 1; | |
28 if (url_host == kMonitoredDomainName[i] || | |
29 (EndsWith(url_host, kMonitoredDomainName[i], true) && | |
30 url_host[point_position] == '.')) { | |
31 domain_name = kMonitoredDomainName[i]; | |
32 return domain_name; | |
33 } | |
34 } | |
35 return domain_name; | |
Ilya Sherman
2013/08/30 22:34:42
Please write this as:
GURL url(url_host);
for (si
jdomingos
2013/09/02 09:58:45
Done.
| |
36 } | |
37 | |
38 void LogUMAHistogramEnumeration(const std::string& name, | |
39 int sample, | |
40 int boundary_value) { | |
41 DCHECK_LT(sample, boundary_value); | |
42 | |
43 // Note: This leaks memory, which is expected behavior. | |
44 base::HistogramBase* histogram = | |
45 base::LinearHistogram::FactoryGet( | |
46 name, | |
47 1, | |
48 boundary_value, | |
49 boundary_value + 1, | |
50 base::HistogramBase::kUmaTargetedHistogramFlag); | |
51 histogram->Add(sample); | |
52 } | |
53 | |
54 void LogUMAHistogramTimes(const std::string& name, | |
55 const base::TimeDelta& duration) { | |
56 // Note: This leaks memory, which is expected behavior. | |
57 base::HistogramBase* histogram = | |
58 base::Histogram::FactoryTimeGet( | |
59 name, | |
60 base::TimeDelta::FromMilliseconds(1), | |
61 base::TimeDelta::FromSeconds(10), | |
62 50, | |
63 base::HistogramBase::kUmaTargetedHistogramFlag); | |
64 histogram->AddTime(duration); | |
65 } | |
66 | |
67 void LogUMAHistogramCount(const std::string& name, int sample) { | |
68 // Note: This leaks memory, which is expected behavior. | |
69 base::HistogramBase* histogram = | |
70 base::Histogram::FactoryGet( | |
71 name, | |
72 1, | |
73 1000000, | |
74 50, | |
75 base::HistogramBase::kUmaTargetedHistogramFlag); | |
76 histogram->Add(sample); | |
77 } | |
78 | |
79 void LogUMAHistogramBoolean(const std::string& name, bool sample) { | |
80 // Note: This leaks memory, which is expected behavior. | |
81 base::HistogramBase* histogram = | |
82 base::BooleanHistogram::FactoryGet( | |
83 name, | |
84 base::Histogram::kNoFlags); | |
85 histogram->AddBoolean(sample); | |
86 } | |
87 | |
88 } // namespace password_manager_metrics_util | |
OLD | NEW |