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