Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/browser/metrics/antivirus_metrics_provider_win.cc

Issue 2631583002: Trim version and extraneus parts from AntiVirus product names. (Closed)
Patch Set: tweak algorithm. add comment. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/antivirus_metrics_provider_win.h" 5 #include "chrome/browser/metrics/antivirus_metrics_provider_win.h"
6 6
7 #include <iwscapi.h> 7 #include <iwscapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <wbemidl.h> 9 #include <wbemidl.h>
10 #include <windows.h> 10 #include <windows.h>
11 #include <wscapi.h> 11 #include <wscapi.h>
12 12
13 #include <algorithm>
13 #include <string> 14 #include <string>
14 15
15 #include "base/bind.h" 16 #include "base/bind.h"
16 #include "base/callback.h" 17 #include "base/callback.h"
17 #include "base/feature_list.h" 18 #include "base/feature_list.h"
18 #include "base/file_version_info_win.h" 19 #include "base/file_version_info_win.h"
19 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
20 #include "base/files/file_util.h" 21 #include "base/files/file_util.h"
21 #include "base/metrics/field_trial.h" 22 #include "base/metrics/field_trial.h"
22 #include "base/metrics/histogram_macros.h" 23 #include "base/metrics/histogram_macros.h"
23 #include "base/path_service.h" 24 #include "base/path_service.h"
25 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
25 #include "base/strings/sys_string_conversions.h" 27 #include "base/strings/sys_string_conversions.h"
26 #include "base/task_runner_util.h" 28 #include "base/task_runner_util.h"
27 #include "base/threading/thread_restrictions.h" 29 #include "base/threading/thread_restrictions.h"
28 #include "base/version.h" 30 #include "base/version.h"
29 #include "base/win/scoped_bstr.h" 31 #include "base/win/scoped_bstr.h"
30 #include "base/win/scoped_com_initializer.h" 32 #include "base/win/scoped_com_initializer.h"
31 #include "base/win/scoped_comptr.h" 33 #include "base/win/scoped_comptr.h"
32 #include "base/win/scoped_variant.h" 34 #include "base/win/scoped_variant.h"
33 #include "base/win/windows_version.h" 35 #include "base/win/windows_version.h"
(...skipping 16 matching lines...) Expand all
50 uint8_t definition_state : 4; // 1 = Out of date, 0 = Up to date. 52 uint8_t definition_state : 4; // 1 = Out of date, 0 = Up to date.
51 uint8_t unknown_2 : 4; 53 uint8_t unknown_2 : 4;
52 uint8_t security_state : 4; // 0 = Inactive, 1 = Active, 2 = Snoozed. 54 uint8_t security_state : 4; // 0 = Inactive, 1 = Active, 2 = Snoozed.
53 uint8_t security_provider; // matches WSC_SECURITY_PROVIDER in wscapi.h. 55 uint8_t security_provider; // matches WSC_SECURITY_PROVIDER in wscapi.h.
54 uint8_t unknown_3; 56 uint8_t unknown_3;
55 }; 57 };
56 #pragma pack(pop) 58 #pragma pack(pop)
57 59
58 static_assert(sizeof(PRODUCT_STATE) == 4, "Wrong packing!"); 60 static_assert(sizeof(PRODUCT_STATE) == 4, "Wrong packing!");
59 61
62 // Filter any part of a product string that looks like it might be a version
63 // number. Returns true if the part should be removed from the product name.
64 bool ShouldFilterPart(const std::string& str) {
65 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.
66 return false;
67 // Special case for "360" (used by Norton), "365" (used by Kaspersky) and
68 // "NOD32" (used by ESET).
69 if (str == "365" || str == "360" || str == "NOD32")
70 return false;
71 for (const auto ch : str) {
72 if (isdigit(ch))
73 return true;
74 }
75 return false;
76 }
77
60 bool ShouldReportFullNames() { 78 bool ShouldReportFullNames() {
61 // The expectation is that this will be disabled for the majority of users, 79 // The expectation is that this will be disabled for the majority of users,
62 // but this allows a small group to be enabled on other channels if there are 80 // but this allows a small group to be enabled on other channels if there are
63 // a large percentage of hashes collected on these channels that are not 81 // a large percentage of hashes collected on these channels that are not
64 // resolved to names previously collected on Canary channel. 82 // resolved to names previously collected on Canary channel.
65 bool enabled = base::FeatureList::IsEnabled( 83 bool enabled = base::FeatureList::IsEnabled(
66 AntiVirusMetricsProvider::kReportNamesFeature); 84 AntiVirusMetricsProvider::kReportNamesFeature);
67 85
68 if (chrome::GetChannel() == version_info::Channel::CANARY) 86 if (chrome::GetChannel() == version_info::Channel::CANARY)
69 return true; 87 return true;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 196
179 MaybeAddUnregisteredAntiVirusProducts(&av_products); 197 MaybeAddUnregisteredAntiVirusProducts(&av_products);
180 198
181 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result", 199 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result",
182 result, 200 result,
183 RESULT_COUNT); 201 RESULT_COUNT);
184 202
185 return av_products; 203 return av_products;
186 } 204 }
187 205
206 std::string AntiVirusMetricsProvider::TrimVersionOfAvProductName(
207 const std::string& av_product) {
208 auto av_product_parts = base::SplitString(
209 av_product, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
210
211 if (av_product_parts.size() >= 2) {
212 // Skipping first element, remove any that look like version numbers.
213 av_product_parts.erase(
214 std::remove_if(av_product_parts.begin() + 1, av_product_parts.end(),
215 ShouldFilterPart),
216 av_product_parts.end());
217 }
218
219 return base::JoinString(av_product_parts, " ");
220 }
221
188 void AntiVirusMetricsProvider::GotAntiVirusProducts( 222 void AntiVirusMetricsProvider::GotAntiVirusProducts(
189 const base::Closure& done_callback, 223 const base::Closure& done_callback,
190 const std::vector<AvProduct>& av_products) { 224 const std::vector<AvProduct>& av_products) {
191 DCHECK(thread_checker_.CalledOnValidThread()); 225 DCHECK(thread_checker_.CalledOnValidThread());
192 av_products_ = av_products; 226 av_products_ = av_products;
193 done_callback.Run(); 227 done_callback.Run();
194 } 228 }
195 229
196 // static 230 // static
197 AntiVirusMetricsProvider::ResultCode 231 AntiVirusMetricsProvider::ResultCode
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 std::string product_name("Trusteer Endpoint Protection"); 500 std::string product_name("Trusteer Endpoint Protection");
467 if (ShouldReportFullNames()) { 501 if (ShouldReportFullNames()) {
468 av_product.set_product_name(product_name); 502 av_product.set_product_name(product_name);
469 av_product.set_product_version(product_version); 503 av_product.set_product_version(product_version);
470 } 504 }
471 av_product.set_product_name_hash(metrics::HashName(product_name)); 505 av_product.set_product_name_hash(metrics::HashName(product_name));
472 av_product.set_product_version_hash(metrics::HashName(product_version)); 506 av_product.set_product_version_hash(metrics::HashName(product_version));
473 507
474 products->push_back(av_product); 508 products->push_back(av_product);
475 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698