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