Chromium Code Reviews| Index: chrome/browser/password_manager/password_manager_metrics_util.cc |
| diff --git a/chrome/browser/password_manager/password_manager_metrics_util.cc b/chrome/browser/password_manager/password_manager_metrics_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70b3bcd59f38736140df930fe3aee03083794925 |
| --- /dev/null |
| +++ b/chrome/browser/password_manager/password_manager_metrics_util.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/password_manager/password_manager_metrics_util.h" |
| + |
| +#include "base/strings/string_util.h" |
| + |
| +namespace password_manager_metrics_util { |
| + |
| +std::string IsDomainNameMonitored(const std::string& url_host) { |
| + 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
|
| + "google.com", |
| + "yahoo.com", |
| + "baidu.com", |
| + "wikipedia.org", |
| + "linkedin.com", |
| + "twitter.com", |
| + "live.com", |
| + "amazon.com", |
| + }; |
| + const size_t kMonitoredDomainNameLength = arraysize(kMonitoredDomainName); |
| + |
| + std::string domain_name; |
| + for (std::string::size_type i = 0; i < kMonitoredDomainNameLength; ++i) { |
| + size_t point_position = |
| + url_host.size() - strlen(kMonitoredDomainName[i]) - 1; |
| + if (url_host == kMonitoredDomainName[i] || |
| + (EndsWith(url_host, kMonitoredDomainName[i], true) && |
| + url_host[point_position] == '.')) { |
| + domain_name = kMonitoredDomainName[i]; |
| + return domain_name; |
| + } |
| + } |
| + 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.
|
| +} |
| + |
| +void LogUMAHistogramEnumeration(const std::string& name, |
| + int sample, |
| + int boundary_value) { |
| + DCHECK_LT(sample, boundary_value); |
| + |
| + // Note: This leaks memory, which is expected behavior. |
| + base::HistogramBase* histogram = |
| + base::LinearHistogram::FactoryGet( |
| + name, |
| + 1, |
| + boundary_value, |
| + boundary_value + 1, |
| + base::HistogramBase::kUmaTargetedHistogramFlag); |
| + histogram->Add(sample); |
| +} |
| + |
| +void LogUMAHistogramTimes(const std::string& name, |
| + const base::TimeDelta& duration) { |
| + // Note: This leaks memory, which is expected behavior. |
| + base::HistogramBase* histogram = |
| + base::Histogram::FactoryTimeGet( |
| + name, |
| + base::TimeDelta::FromMilliseconds(1), |
| + base::TimeDelta::FromSeconds(10), |
| + 50, |
| + base::HistogramBase::kUmaTargetedHistogramFlag); |
| + histogram->AddTime(duration); |
| +} |
| + |
| +void LogUMAHistogramCount(const std::string& name, int sample) { |
| + // Note: This leaks memory, which is expected behavior. |
| + base::HistogramBase* histogram = |
| + base::Histogram::FactoryGet( |
| + name, |
| + 1, |
| + 1000000, |
| + 50, |
| + base::HistogramBase::kUmaTargetedHistogramFlag); |
| + histogram->Add(sample); |
| +} |
| + |
| +void LogUMAHistogramBoolean(const std::string& name, bool sample) { |
| + // Note: This leaks memory, which is expected behavior. |
| + base::HistogramBase* histogram = |
| + base::BooleanHistogram::FactoryGet( |
| + name, |
| + base::Histogram::kNoFlags); |
| + histogram->AddBoolean(sample); |
| +} |
| + |
| +} // namespace password_manager_metrics_util |