Chromium Code Reviews| Index: chrome/browser/metrics/antivirus_metrics_provider_win.cc |
| diff --git a/chrome/browser/metrics/antivirus_metrics_provider_win.cc b/chrome/browser/metrics/antivirus_metrics_provider_win.cc |
| index ada7c8a7cb55c818c32112f70b28ed83d687dc03..ddd8a70b45d04dc996f0a73db9651b6882589470 100644 |
| --- a/chrome/browser/metrics/antivirus_metrics_provider_win.cc |
| +++ b/chrome/browser/metrics/antivirus_metrics_provider_win.cc |
| @@ -10,6 +10,7 @@ |
| #include <windows.h> |
| #include <wscapi.h> |
| +#include <algorithm> |
| #include <string> |
| #include "base/bind.h" |
| @@ -21,6 +22,7 @@ |
| #include "base/metrics/field_trial.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/path_service.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/task_runner_util.h" |
| @@ -57,6 +59,22 @@ struct PRODUCT_STATE { |
| static_assert(sizeof(PRODUCT_STATE) == 4, "Wrong packing!"); |
| +// Filter any part of a product string that looks like it might be a version |
| +// number. Returns true if the part should be removed from the product name. |
| +bool ShouldFilterPart(const std::string& str) { |
| + if (str.empty()) |
|
rkaplow
2017/01/12 23:44:27
don't think this is needed
Will Harris
2017/01/12 23:48:13
Done.
|
| + return false; |
| + // Special case for "360" (used by Norton), "365" (used by Kaspersky) and |
| + // "NOD32" (used by ESET). |
| + if (str == "365" || str == "360" || str == "NOD32") |
| + return false; |
| + for (const auto ch : str) { |
| + if (isdigit(ch)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| bool ShouldReportFullNames() { |
| // The expectation is that this will be disabled for the majority of users, |
| // but this allows a small group to be enabled on other channels if there are |
| @@ -185,6 +203,22 @@ AntiVirusMetricsProvider::GetAntiVirusProductsOnFileThread() { |
| return av_products; |
| } |
| +std::string AntiVirusMetricsProvider::TrimVersionOfAvProductName( |
| + const std::string& av_product) { |
| + auto av_product_parts = base::SplitString( |
| + av_product, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| + |
| + if (av_product_parts.size() >= 2) { |
| + // Skipping first element, remove any that look like version numbers. |
| + av_product_parts.erase( |
| + std::remove_if(av_product_parts.begin() + 1, av_product_parts.end(), |
| + ShouldFilterPart), |
| + av_product_parts.end()); |
| + } |
| + |
| + return base::JoinString(av_product_parts, " "); |
| +} |
| + |
| void AntiVirusMetricsProvider::GotAntiVirusProducts( |
| const base::Closure& done_callback, |
| const std::vector<AvProduct>& av_products) { |