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..b1432209705b01f4714208b205c2aa80efd8f305 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,23 @@ 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. |
| +bool ShouldFilterPart(const std::string& str) { |
| + if (str.empty()) |
| + return false; |
| + // Special case for "360" (used by Norton) and "365" (used by Kaspersky). |
| + if (str == "365" || str == "360") |
| + return false; |
| + for (const auto ch : str) { |
| + if (ch == '.') |
| + return true; |
|
rkaplow
2017/01/12 23:18:56
shouldn't this not return right away? i.e. this wo
Will Harris
2017/01/12 23:23:59
this was specifically to handle stuff like
"nProt
Will Harris
2017/01/12 23:27:05
hmm turns out this algorithm doesn't handle "nProt
Will Harris
2017/01/12 23:39:06
Done.
|
| + if (ch != '_' && !isdigit(ch)) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| 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 +204,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) { |