blob: 5395716b247d4fc0d705c39486758279ffcf9a59 [file] [log] [blame]
wfhc768983fa2016-06-08 16:40:331// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_METRICS_ANTIVIRUS_METRICS_PROVIDER_WIN_H_
6#define CHROME_BROWSER_METRICS_ANTIVIRUS_METRICS_PROVIDER_WIN_H_
7
8#include "components/metrics/metrics_provider.h"
9
10#include <iwscapi.h>
11#include <stddef.h>
12
13#include <string>
14#include <vector>
15
16#include "base/callback_forward.h"
17#include "base/feature_list.h"
18#include "base/gtest_prod_util.h"
19#include "base/macros.h"
20#include "base/memory/weak_ptr.h"
pmonette7b9e7812017-05-18 18:58:0121#include "base/sequence_checker.h"
Steven Holtef9d5ed62017-10-21 02:02:3022#include "third_party/metrics_proto/system_profile.pb.h"
wfhc768983fa2016-06-08 16:40:3323
24// AntiVirusMetricsProvider is responsible for adding antivirus information to
25// the UMA system profile proto.
26class AntiVirusMetricsProvider : public metrics::MetricsProvider {
27 public:
28 static constexpr base::Feature kReportNamesFeature = {
29 "ReportFullAVProductDetails", base::FEATURE_DISABLED_BY_DEFAULT};
30
pmonette7b9e7812017-05-18 18:58:0131 AntiVirusMetricsProvider();
wfhc768983fa2016-06-08 16:40:3332
33 ~AntiVirusMetricsProvider() override;
34
35 // metrics::MetricsDataProvider:
Steven Holte915c99f2017-07-21 23:34:3136 void AsyncInit(const base::Closure& done_callback) override;
wfhc768983fa2016-06-08 16:40:3337 void ProvideSystemProfileMetrics(
38 metrics::SystemProfileProto* system_profile_proto) override;
39
wfhc768983fa2016-06-08 16:40:3340 private:
41 // This enum is reported via a histogram so new values should always be added
42 // at the end.
43 enum ResultCode {
44 RESULT_SUCCESS = 0,
45 RESULT_GENERIC_FAILURE = 1,
46 RESULT_FAILED_TO_INITIALIZE_COM = 2,
47 RESULT_FAILED_TO_CREATE_INSTANCE = 3,
48 RESULT_FAILED_TO_INITIALIZE_PRODUCT_LIST = 4,
49 RESULT_FAILED_TO_GET_PRODUCT_COUNT = 5,
50 RESULT_FAILED_TO_GET_ITEM = 6,
51 RESULT_FAILED_TO_GET_PRODUCT_STATE = 7,
52 RESULT_PRODUCT_STATE_INVALID = 8,
53 RESULT_FAILED_TO_GET_PRODUCT_NAME = 9,
54 RESULT_FAILED_TO_GET_REMEDIATION_PATH = 10,
wfh6813e4f2016-07-01 22:03:4555 RESULT_FAILED_TO_CONNECT_TO_WMI = 11,
56 RESULT_FAILED_TO_SET_SECURITY_BLANKET = 12,
57 RESULT_FAILED_TO_EXEC_WMI_QUERY = 13,
58 RESULT_FAILED_TO_ITERATE_RESULTS = 14,
59 RESULT_WSC_NOT_AVAILABLE = 15,
60 RESULT_COUNT = 16
wfhc768983fa2016-06-08 16:40:3361 };
62
63 typedef metrics::SystemProfileProto::AntiVirusProduct AvProduct;
64
wfh6813e4f2016-07-01 22:03:4565 // Query COM interface IWSCProductList for installed AV products. This
66 // interface is only available on Windows 8 and above.
67 static ResultCode FillAntiVirusProductsFromWSC(
68 std::vector<AvProduct>* products);
wfh4b6a820302016-12-14 21:53:1669
wfh6813e4f2016-07-01 22:03:4570 // Query WMI ROOT\SecurityCenter2 for installed AV products. This interface is
71 // only available on Windows Vista and above.
72 static ResultCode FillAntiVirusProductsFromWMI(
73 std::vector<AvProduct>* products);
wfh4b6a820302016-12-14 21:53:1674
75 // Query local machine configuration for other products that might not be
76 // registered in WMI or Security Center and add them to the product vector.
77 static void MaybeAddUnregisteredAntiVirusProducts(
78 std::vector<AvProduct>* products);
79
Robert Liaoa46c6022017-10-31 18:28:0980 static std::vector<AvProduct> GetAntiVirusProductsOnCOMSTAThread();
wfhc768983fa2016-06-08 16:40:3381
wfhda07d58a2017-01-13 17:27:2882 // Removes anything extraneous from the end of the product name such as
83 // versions, years, or anything containing numbers to make it more constant.
84 static std::string TrimVersionOfAvProductName(const std::string& av_product);
85
wfhc768983fa2016-06-08 16:40:3386 // Called when metrics are done being gathered from the FILE thread.
87 // |done_callback| is the callback that should be called once all metrics are
88 // gathered.
89 void GotAntiVirusProducts(const base::Closure& done_callback,
90 const std::vector<AvProduct>& av_products);
91
wfhc768983fa2016-06-08 16:40:3392 // Information on installed AntiVirus gathered.
93 std::vector<AvProduct> av_products_;
94
pmonette7b9e7812017-05-18 18:58:0195 SEQUENCE_CHECKER(sequence_checker_);
wfhc768983fa2016-06-08 16:40:3396 base::WeakPtrFactory<AntiVirusMetricsProvider> weak_ptr_factory_;
97
wfh6813e4f2016-07-01 22:03:4598 FRIEND_TEST_ALL_PREFIXES(AntiVirusMetricsProviderTest, GetMetricsFullName);
wfhda07d58a2017-01-13 17:27:2899 FRIEND_TEST_ALL_PREFIXES(AntiVirusMetricsProviderSimpleTest,
100 StripProductVersion);
wfh6813e4f2016-07-01 22:03:45101
wfhc768983fa2016-06-08 16:40:33102 DISALLOW_COPY_AND_ASSIGN(AntiVirusMetricsProvider);
103};
104
105#endif // CHROME_BROWSER_METRICS_ANTIVIRUS_METRICS_PROVIDER_WIN_H_