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

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: 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.
64 bool ShouldFilterPart(const std::string& str) {
65 if (str.empty())
66 return false;
67 // Special case for "360" (used by Norton) and "365" (used by Kaspersky).
68 if (str == "365" || str == "360")
69 return false;
70 for (const auto ch : str) {
71 if (ch == '.')
72 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.
73 if (ch != '_' && !isdigit(ch))
74 return false;
75 }
76 return true;
77 }
78
60 bool ShouldReportFullNames() { 79 bool ShouldReportFullNames() {
61 // The expectation is that this will be disabled for the majority of users, 80 // 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 81 // 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 82 // a large percentage of hashes collected on these channels that are not
64 // resolved to names previously collected on Canary channel. 83 // resolved to names previously collected on Canary channel.
65 bool enabled = base::FeatureList::IsEnabled( 84 bool enabled = base::FeatureList::IsEnabled(
66 AntiVirusMetricsProvider::kReportNamesFeature); 85 AntiVirusMetricsProvider::kReportNamesFeature);
67 86
68 if (chrome::GetChannel() == version_info::Channel::CANARY) 87 if (chrome::GetChannel() == version_info::Channel::CANARY)
69 return true; 88 return true;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 197
179 MaybeAddUnregisteredAntiVirusProducts(&av_products); 198 MaybeAddUnregisteredAntiVirusProducts(&av_products);
180 199
181 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result", 200 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result",
182 result, 201 result,
183 RESULT_COUNT); 202 RESULT_COUNT);
184 203
185 return av_products; 204 return av_products;
186 } 205 }
187 206
207 std::string AntiVirusMetricsProvider::TrimVersionOfAvProductName(
208 const std::string& av_product) {
209 auto av_product_parts = base::SplitString(
210 av_product, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
211
212 if (av_product_parts.size() >= 2) {
213 // Skipping first element, remove any that look like version numbers.
214 av_product_parts.erase(
215 std::remove_if(av_product_parts.begin() + 1, av_product_parts.end(),
216 ShouldFilterPart),
217 av_product_parts.end());
218 }
219
220 return base::JoinString(av_product_parts, " ");
221 }
222
188 void AntiVirusMetricsProvider::GotAntiVirusProducts( 223 void AntiVirusMetricsProvider::GotAntiVirusProducts(
189 const base::Closure& done_callback, 224 const base::Closure& done_callback,
190 const std::vector<AvProduct>& av_products) { 225 const std::vector<AvProduct>& av_products) {
191 DCHECK(thread_checker_.CalledOnValidThread()); 226 DCHECK(thread_checker_.CalledOnValidThread());
192 av_products_ = av_products; 227 av_products_ = av_products;
193 done_callback.Run(); 228 done_callback.Run();
194 } 229 }
195 230
196 // static 231 // static
197 AntiVirusMetricsProvider::ResultCode 232 AntiVirusMetricsProvider::ResultCode
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 std::string product_name("Trusteer Endpoint Protection"); 501 std::string product_name("Trusteer Endpoint Protection");
467 if (ShouldReportFullNames()) { 502 if (ShouldReportFullNames()) {
468 av_product.set_product_name(product_name); 503 av_product.set_product_name(product_name);
469 av_product.set_product_version(product_version); 504 av_product.set_product_version(product_version);
470 } 505 }
471 av_product.set_product_name_hash(metrics::HashName(product_name)); 506 av_product.set_product_name_hash(metrics::HashName(product_name));
472 av_product.set_product_version_hash(metrics::HashName(product_version)); 507 av_product.set_product_version_hash(metrics::HashName(product_version));
473 508
474 products->push_back(av_product); 509 products->push_back(av_product);
475 } 510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698