1*6777b538SAndroid Build Coastguard Worker // Copyright 2017 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker #include "components/metrics/component_metrics_provider.h"
6*6777b538SAndroid Build Coastguard Worker
7*6777b538SAndroid Build Coastguard Worker #include "base/containers/fixed_flat_map.h"
8*6777b538SAndroid Build Coastguard Worker #include "base/hash/hash.h"
9*6777b538SAndroid Build Coastguard Worker #include "base/strings/string_number_conversions.h"
10*6777b538SAndroid Build Coastguard Worker #include "base/strings/string_piece.h"
11*6777b538SAndroid Build Coastguard Worker #include "components/component_updater/component_updater_service.h"
12*6777b538SAndroid Build Coastguard Worker #include "third_party/metrics_proto/system_profile.pb.h"
13*6777b538SAndroid Build Coastguard Worker
14*6777b538SAndroid Build Coastguard Worker #include <string>
15*6777b538SAndroid Build Coastguard Worker
16*6777b538SAndroid Build Coastguard Worker namespace metrics {
17*6777b538SAndroid Build Coastguard Worker
18*6777b538SAndroid Build Coastguard Worker namespace {
19*6777b538SAndroid Build Coastguard Worker
CrxIdToComponentId(const std::string & app_id)20*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId CrxIdToComponentId(const std::string& app_id) {
21*6777b538SAndroid Build Coastguard Worker static constexpr auto kComponentMap = base::MakeFixedFlatMap<
22*6777b538SAndroid Build Coastguard Worker base::StringPiece, SystemProfileProto_ComponentId>({
23*6777b538SAndroid Build Coastguard Worker {"aagaghndoahmfdbmfnajfklaomcanlnh",
24*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_REAL_TIME_URL_CHECKS_ALLOWLIST},
25*6777b538SAndroid Build Coastguard Worker {"bjbdkfoakgmkndalgpadobhgbhhoanho",
26*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_EPSON_INKJET_PRINTER_ESCPR},
27*6777b538SAndroid Build Coastguard Worker {"cdoopinbipdmaefofkedmagbfmdcjnaa",
28*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CROW_DOMAIN_LIST},
29*6777b538SAndroid Build Coastguard Worker {"cjfkbpdpjpdldhclahpfgnlhpodlpnba",
30*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_VR_ASSETS},
31*6777b538SAndroid Build Coastguard Worker {"ckjlcfmdbdglblbjglepgnoekdnkoklc",
32*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_PEPPER_FLASH_CHROMEOS},
33*6777b538SAndroid Build Coastguard Worker {"cocncanleafgejenidihemfflagifjic",
34*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_COMMERCE_HEURISTICS},
35*6777b538SAndroid Build Coastguard Worker {"copjbmjbojbakpaedmpkhmiplmmehfck",
36*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_INTERVENTION_POLICY_DATABASE},
37*6777b538SAndroid Build Coastguard Worker {"dgeeihjgkpfplghdiaomabiakidhjnnn",
38*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_GROWTH_CAMPAIGNS},
39*6777b538SAndroid Build Coastguard Worker {"dhlpobdgcjafebgbbhjdnapejmpkgiie",
40*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_DESKTOP_SHARING_HUB},
41*6777b538SAndroid Build Coastguard Worker {"eeigpngbgcognadeebkilcpcaedhellh",
42*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_AUTOFILL_STATES},
43*6777b538SAndroid Build Coastguard Worker {"efniojlnjndmcbiieegkicadnoecjjef",
44*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_PKI_METADATA},
45*6777b538SAndroid Build Coastguard Worker {"ehgidpndbllacpjalkiimkbadgjfnnmc",
46*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_THIRD_PARTY_MODULE_LIST},
47*6777b538SAndroid Build Coastguard Worker {"ehpjbaiafkpkmhjocnenjbbhmecnfcjb",
48*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_LACROS_DOGFOOD_STABLE},
49*6777b538SAndroid Build Coastguard Worker {"fellaebeeieagcalnmmpapfioejgihci",
50*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_APP_PROVISIONING},
51*6777b538SAndroid Build Coastguard Worker {"fhbeibbmaepakgdkkmjgldjajgpkkhfj",
52*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CELLULAR},
53*6777b538SAndroid Build Coastguard Worker {"fookoiellkocclipolgaceabajejjcnp",
54*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_DOWNLOADABLE_STRINGS},
55*6777b538SAndroid Build Coastguard Worker {"gcmjkmgdlgnkkcocmoeiminaijmmjnii",
56*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SUBRESOURCE_FILTER},
57*6777b538SAndroid Build Coastguard Worker {"gelhpeofhffbaeegmemklllhfdifagmb",
58*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SPEECH_SYNTHESIS_SV_SE},
59*6777b538SAndroid Build Coastguard Worker {"ggkkehgbnfjpeggfpleeakpidbkibbmn",
60*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CROWD_DENY},
61*6777b538SAndroid Build Coastguard Worker {"ghiclnejioiofblmbphpgbhaojnkempa",
62*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SMART_DIM},
63*6777b538SAndroid Build Coastguard Worker {"giekcmmlnklenlaomppkphknjmnnpneh",
64*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SSL_ERROR_ASSISTANT},
65*6777b538SAndroid Build Coastguard Worker {"gjpajnddmedjmcklfflllocelehklffm",
66*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_RTANALYTICS_LIGHT},
67*6777b538SAndroid Build Coastguard Worker {"gkmgaooipdjhmangpemjhigmamcehddo",
68*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SW_REPORTER},
69*6777b538SAndroid Build Coastguard Worker {"gncenodapghbnkfkoognegdnjoeegmkp",
70*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_STAR_CUPS_DRIVER},
71*6777b538SAndroid Build Coastguard Worker {"goaoclndmgofblfopkopecdpfhljclbd",
72*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_FR_FR},
73*6777b538SAndroid Build Coastguard Worker {"gonpemdgkjcecdgbnaabipppbmgfggbe",
74*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_FIRST_PARTY_SETS},
75*6777b538SAndroid Build Coastguard Worker {"hfnkpimlhhgieaddgfemjhofmfblmnib",
76*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CRL_SET},
77*6777b538SAndroid Build Coastguard Worker {"hkifppleldbgkdlijbdfkdpedggaopda",
78*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_LACROS_DOGFOOD_CANARY},
79*6777b538SAndroid Build Coastguard Worker {"hnfmbeciphpghlfgpjfbcdifbknombnk",
80*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_LACROS_DOGFOOD_BETA},
81*6777b538SAndroid Build Coastguard Worker {"hnimpnehoodheedghdeeijklkeaacbdc",
82*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_PNACL},
83*6777b538SAndroid Build Coastguard Worker {"icnkogojpkfjeajonkmlplionaamopkf", SystemProfileProto_ComponentId_SODA},
84*6777b538SAndroid Build Coastguard Worker {"ihnlcenocehgdaegdmhbidjhnhdchfmm",
85*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_RECOVERY_IMPROVED},
86*6777b538SAndroid Build Coastguard Worker {"imefjhfbkmcmebodilednhmaccmincoa",
87*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CLIENT_SIDE_PHISHING},
88*6777b538SAndroid Build Coastguard Worker {"jamhcnnkihinmdlkakkaopbjbbcngflc",
89*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_HYPHENATION},
90*6777b538SAndroid Build Coastguard Worker {"jclgnikdalajmocbnlgieibfmlejnhmg",
91*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_DE_DE},
92*6777b538SAndroid Build Coastguard Worker {"jdmajdolkmhiifibdijabfojmfjmfkpb",
93*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_DEMO_MODE_RESOURCES},
94*6777b538SAndroid Build Coastguard Worker {"jflhchccmppkfebkiaminageehmchikm",
95*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_THIRD_PARTY_COOKIE_DEPRECATION_METADATA},
96*6777b538SAndroid Build Coastguard Worker {"jflookgnkcckhobaglndicnbbgbonegd",
97*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SAFETY_TIPS},
98*6777b538SAndroid Build Coastguard Worker {"jhefnhlmpagbceldaobdpcjhkknfjohi",
99*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_IT_IT},
100*6777b538SAndroid Build Coastguard Worker {"jkcckmaejhmbhagbcebpejbihcnighdb",
101*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_ES_ES},
102*6777b538SAndroid Build Coastguard Worker {"kdbdaidmledpgkihpopchgmjikgkjclh",
103*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_DESKTOP_SCREENSHOT_EDITOR},
104*6777b538SAndroid Build Coastguard Worker {"kfoklmclfodeliojeaekpoflbkkhojea",
105*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_ORIGIN_TRIALS},
106*6777b538SAndroid Build Coastguard Worker {"khaoiebndkojlmppeemjhbpbandiljpe",
107*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_FILE_TYPE_POLICIES},
108*6777b538SAndroid Build Coastguard Worker {"kiabhabjdbkjdpjbpigfodbdjmbglcoo",
109*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_TRUST_TOKEN_KEY_COMMITMENTS},
110*6777b538SAndroid Build Coastguard Worker {"laoigpblnllgcgjnjnllmfolckpjlhki",
111*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_MEI_PRELOAD},
112*6777b538SAndroid Build Coastguard Worker {"ldobopbhiamakmncndpkeelenhdmgfhk",
113*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_LACROS_DOGFOOD_DEV},
114*6777b538SAndroid Build Coastguard Worker {"lgmfmojpadlamoidaolfpjpjcondabgm",
115*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_DEMO_MODE_APP},
116*6777b538SAndroid Build Coastguard Worker {"llkgjffcdpffmhiakmfcdcblohccpfmo",
117*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_ORIGIN_TRIALS}, // Alternate ID
118*6777b538SAndroid Build Coastguard Worker {"lmelglejhemejginpboagddgdfbepgmp",
119*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_OPTIMIZATION_HINTS},
120*6777b538SAndroid Build Coastguard Worker {"mfhmdacoffpmifoibamicehhklffanao",
121*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SCREEN_AI},
122*6777b538SAndroid Build Coastguard Worker {"mimojjlkmoijpicakmndhoigimigcmbb",
123*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_PEPPER_FLASH},
124*6777b538SAndroid Build Coastguard Worker {"mjdmdobabdmfcbaakcaadileafkmifen",
125*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_RTANALYTICS_FULL},
126*6777b538SAndroid Build Coastguard Worker {"neifaoindggfcjicffkgpmnlppeffabd",
127*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_MEDIA_FOUNDATION_WIDEVINE_CDM},
128*6777b538SAndroid Build Coastguard Worker {"npdjjkjlcidkjlamlmmdelcjbcpdjocm",
129*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_RECOVERY},
130*6777b538SAndroid Build Coastguard Worker {"obedbbhbpmojnkanicioggnmelmoomoc",
131*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_ON_DEVICE_HEAD_SUGGEST},
132*6777b538SAndroid Build Coastguard Worker {"oegebmmcimckjhkhbggblnkjloogjdfg",
133*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_EN_US},
134*6777b538SAndroid Build Coastguard Worker {"oimompecagnajdejgnnjijobebaeigek",
135*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_WIDEVINE_CDM},
136*6777b538SAndroid Build Coastguard Worker {"ojhpjlocmbogdgmfpkhlaaeamibhnphh",
137*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_ZXCVBN_DATA},
138*6777b538SAndroid Build Coastguard Worker {"ojjgnpkioondelmggbekfhllhdaimnho",
139*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_STH_SET},
140*6777b538SAndroid Build Coastguard Worker {"ojnjgapiepgciobpecnafnoeaegllfld",
141*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_CROS_TERMINA},
142*6777b538SAndroid Build Coastguard Worker {"onhpjgkfgajmkkeniaoflicgokpaebfa",
143*6777b538SAndroid Build Coastguard Worker SystemProfileProto_ComponentId_SODA_JA_JP},
144*6777b538SAndroid Build Coastguard Worker });
145*6777b538SAndroid Build Coastguard Worker
146*6777b538SAndroid Build Coastguard Worker const auto result = kComponentMap.find(app_id);
147*6777b538SAndroid Build Coastguard Worker if (result == kComponentMap.end()) {
148*6777b538SAndroid Build Coastguard Worker return SystemProfileProto_ComponentId_UNKNOWN;
149*6777b538SAndroid Build Coastguard Worker }
150*6777b538SAndroid Build Coastguard Worker return result->second;
151*6777b538SAndroid Build Coastguard Worker }
152*6777b538SAndroid Build Coastguard Worker
153*6777b538SAndroid Build Coastguard Worker // Extract the first 32 bits of a fingerprint string, excluding the fingerprint
154*6777b538SAndroid Build Coastguard Worker // format specifier - see the fingerprint format specification at
155*6777b538SAndroid Build Coastguard Worker // https://github.com/google/omaha/blob/master/doc/ServerProtocolV3.md
Trim(const std::string & fp)156*6777b538SAndroid Build Coastguard Worker uint32_t Trim(const std::string& fp) {
157*6777b538SAndroid Build Coastguard Worker const auto len_prefix = fp.find(".");
158*6777b538SAndroid Build Coastguard Worker if (len_prefix == std::string::npos) {
159*6777b538SAndroid Build Coastguard Worker return 0;
160*6777b538SAndroid Build Coastguard Worker }
161*6777b538SAndroid Build Coastguard Worker uint32_t result = 0;
162*6777b538SAndroid Build Coastguard Worker if (base::HexStringToUInt(fp.substr(len_prefix + 1, 8), &result)) {
163*6777b538SAndroid Build Coastguard Worker return result;
164*6777b538SAndroid Build Coastguard Worker }
165*6777b538SAndroid Build Coastguard Worker return 0;
166*6777b538SAndroid Build Coastguard Worker }
167*6777b538SAndroid Build Coastguard Worker
168*6777b538SAndroid Build Coastguard Worker } // namespace
169*6777b538SAndroid Build Coastguard Worker
ComponentMetricsProvider(std::unique_ptr<ComponentMetricsProviderDelegate> components_info_delegate)170*6777b538SAndroid Build Coastguard Worker ComponentMetricsProvider::ComponentMetricsProvider(
171*6777b538SAndroid Build Coastguard Worker std::unique_ptr<ComponentMetricsProviderDelegate> components_info_delegate)
172*6777b538SAndroid Build Coastguard Worker : components_info_delegate_(std::move(components_info_delegate)) {}
173*6777b538SAndroid Build Coastguard Worker
174*6777b538SAndroid Build Coastguard Worker ComponentMetricsProvider::~ComponentMetricsProvider() = default;
175*6777b538SAndroid Build Coastguard Worker
ProvideSystemProfileMetrics(SystemProfileProto * system_profile)176*6777b538SAndroid Build Coastguard Worker void ComponentMetricsProvider::ProvideSystemProfileMetrics(
177*6777b538SAndroid Build Coastguard Worker SystemProfileProto* system_profile) {
178*6777b538SAndroid Build Coastguard Worker for (const auto& component : components_info_delegate_->GetComponents()) {
179*6777b538SAndroid Build Coastguard Worker const auto id = CrxIdToComponentId(component.id);
180*6777b538SAndroid Build Coastguard Worker // Ignore any unknown components - in practice these are the
181*6777b538SAndroid Build Coastguard Worker // SupervisedUserWhitelists, which we do not want to transmit to UMA or
182*6777b538SAndroid Build Coastguard Worker // Crash.
183*6777b538SAndroid Build Coastguard Worker if (id == SystemProfileProto_ComponentId_UNKNOWN) {
184*6777b538SAndroid Build Coastguard Worker continue;
185*6777b538SAndroid Build Coastguard Worker }
186*6777b538SAndroid Build Coastguard Worker auto* proto = system_profile->add_chrome_component();
187*6777b538SAndroid Build Coastguard Worker proto->set_component_id(id);
188*6777b538SAndroid Build Coastguard Worker proto->set_version(component.version.GetString());
189*6777b538SAndroid Build Coastguard Worker proto->set_omaha_fingerprint(Trim(component.fingerprint));
190*6777b538SAndroid Build Coastguard Worker proto->set_cohort_hash(base::PersistentHash(
191*6777b538SAndroid Build Coastguard Worker component.cohort_id.substr(0, component.cohort_id.find_last_of(":"))));
192*6777b538SAndroid Build Coastguard Worker }
193*6777b538SAndroid Build Coastguard Worker }
194*6777b538SAndroid Build Coastguard Worker
195*6777b538SAndroid Build Coastguard Worker } // namespace metrics
196