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..21fe67d10e0b9f25e5b0c12a568a87973bbcba40 |
| --- /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/basictypes.h" |
| +#include "base/metrics/histogram.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/time/time.h" |
| +#include "url/gurl.h" |
| + |
| +namespace password_manager_metrics_util { |
| + |
| +std::string IsDomainNameMonitored(const std::string& url_host) { |
| + const char* const kMonitoredDomainName[] = { |
| + "google.com", |
| + "yahoo.com", |
| + "baidu.com", |
| + "wikipedia.org", |
| + "linkedin.com", |
| + "twitter.com", |
| + "live.com", |
| + "amazon.com", |
| + }; |
| + const size_t kMonitoredDomainNameLength = arraysize(kMonitoredDomainName); |
| + |
| + DLOG(INFO) << url_host; |
|
Ilya Sherman
2013/09/03 22:25:21
Please remove this logging code prior to committin
|
| + GURL url(url_host); |
| + for (size_t i = 0; i < kMonitoredDomainNameLength; ++i) { |
| + std::string domain = kMonitoredDomainName[i]; |
| + if (url.DomainIs(domain.c_str())) |
| + return domain; |
| + } |
| + return std::string(); |
| +} |
| + |
| +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 |