component_metrics_provider.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2017 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. #include "components/metrics/component_metrics_provider.h"
  5. #include "base/containers/fixed_flat_map.h"
  6. #include "base/strings/string_number_conversions.h"
  7. #include "base/strings/string_piece.h"
  8. #include "components/component_updater/component_updater_service.h"
  9. #include "third_party/metrics_proto/system_profile.pb.h"
  10. #include <string>
  11. namespace metrics {
  12. namespace {
  13. SystemProfileProto_ComponentId CrxIdToComponentId(const std::string& app_id) {
  14. static constexpr auto kComponentMap =
  15. base::MakeFixedFlatMap<base::StringPiece,
  16. SystemProfileProto_ComponentId>({
  17. {"khaoiebndkojlmppeemjhbpbandiljpe",
  18. SystemProfileProto_ComponentId_FILE_TYPE_POLICIES},
  19. {"kfoklmclfodeliojeaekpoflbkkhojea",
  20. SystemProfileProto_ComponentId_ORIGIN_TRIALS},
  21. {"llkgjffcdpffmhiakmfcdcblohccpfmo",
  22. SystemProfileProto_ComponentId_ORIGIN_TRIALS}, // Alternate ID
  23. {"mimojjlkmoijpicakmndhoigimigcmbb",
  24. SystemProfileProto_ComponentId_PEPPER_FLASH},
  25. {"ckjlcfmdbdglblbjglepgnoekdnkoklc",
  26. SystemProfileProto_ComponentId_PEPPER_FLASH_CHROMEOS},
  27. {"hnimpnehoodheedghdeeijklkeaacbdc",
  28. SystemProfileProto_ComponentId_PNACL},
  29. {"npdjjkjlcidkjlamlmmdelcjbcpdjocm",
  30. SystemProfileProto_ComponentId_RECOVERY},
  31. {"giekcmmlnklenlaomppkphknjmnnpneh",
  32. SystemProfileProto_ComponentId_SSL_ERROR_ASSISTANT},
  33. {"ojjgnpkioondelmggbekfhllhdaimnho",
  34. SystemProfileProto_ComponentId_STH_SET},
  35. {"hfnkpimlhhgieaddgfemjhofmfblmnib",
  36. SystemProfileProto_ComponentId_CRL_SET},
  37. {"gcmjkmgdlgnkkcocmoeiminaijmmjnii",
  38. SystemProfileProto_ComponentId_SUBRESOURCE_FILTER},
  39. {"gkmgaooipdjhmangpemjhigmamcehddo",
  40. SystemProfileProto_ComponentId_SW_REPORTER},
  41. {"oimompecagnajdejgnnjijobebaeigek",
  42. SystemProfileProto_ComponentId_WIDEVINE_CDM},
  43. {"bjbdkfoakgmkndalgpadobhgbhhoanho",
  44. SystemProfileProto_ComponentId_EPSON_INKJET_PRINTER_ESCPR},
  45. {"ojnjgapiepgciobpecnafnoeaegllfld",
  46. SystemProfileProto_ComponentId_CROS_TERMINA},
  47. {"gncenodapghbnkfkoognegdnjoeegmkp",
  48. SystemProfileProto_ComponentId_STAR_CUPS_DRIVER},
  49. {"gelhpeofhffbaeegmemklllhfdifagmb",
  50. SystemProfileProto_ComponentId_SPEECH_SYNTHESIS_SV_SE},
  51. {"lmelglejhemejginpboagddgdfbepgmp",
  52. SystemProfileProto_ComponentId_OPTIMIZATION_HINTS},
  53. {"fookoiellkocclipolgaceabajejjcnp",
  54. SystemProfileProto_ComponentId_DOWNLOADABLE_STRINGS},
  55. {"cjfkbpdpjpdldhclahpfgnlhpodlpnba",
  56. SystemProfileProto_ComponentId_VR_ASSETS},
  57. {"gjpajnddmedjmcklfflllocelehklffm",
  58. SystemProfileProto_ComponentId_RTANALYTICS_LIGHT},
  59. {"mjdmdobabdmfcbaakcaadileafkmifen",
  60. SystemProfileProto_ComponentId_RTANALYTICS_FULL},
  61. {"fhbeibbmaepakgdkkmjgldjajgpkkhfj",
  62. SystemProfileProto_ComponentId_CELLULAR},
  63. {"ojhpjlocmbogdgmfpkhlaaeamibhnphh",
  64. SystemProfileProto_ComponentId_ZXCVBN_DATA},
  65. {"aemllinfpjdgcldgaelcgakpjmaekbai",
  66. SystemProfileProto_ComponentId_WEBVIEW_APPS_PACKAGE_NAMES_ALLOWLIST},
  67. });
  68. const auto* result = kComponentMap.find(app_id);
  69. if (result == kComponentMap.end())
  70. return SystemProfileProto_ComponentId_UNKNOWN;
  71. return result->second;
  72. }
  73. // Extract the first 32 bits of a fingerprint string, excluding the fingerprint
  74. // format specifier - see the fingerprint format specification at
  75. // https://github.com/google/omaha/blob/master/doc/ServerProtocolV3.md
  76. uint32_t Trim(const std::string& fp) {
  77. const auto len_prefix = fp.find(".");
  78. if (len_prefix == std::string::npos)
  79. return 0;
  80. uint32_t result = 0;
  81. if (base::HexStringToUInt(fp.substr(len_prefix + 1, 8), &result))
  82. return result;
  83. return 0;
  84. }
  85. } // namespace
  86. ComponentMetricsProvider::ComponentMetricsProvider(
  87. std::unique_ptr<ComponentMetricsProviderDelegate> components_info_delegate)
  88. : components_info_delegate_(std::move(components_info_delegate)) {}
  89. ComponentMetricsProvider::~ComponentMetricsProvider() = default;
  90. void ComponentMetricsProvider::ProvideSystemProfileMetrics(
  91. SystemProfileProto* system_profile) {
  92. for (const auto& component : components_info_delegate_->GetComponents()) {
  93. const auto id = CrxIdToComponentId(component.id);
  94. // Ignore any unknown components - in practice these are the
  95. // SupervisedUserWhitelists, which we do not want to transmit to UMA or
  96. // Crash.
  97. if (id == SystemProfileProto_ComponentId_UNKNOWN)
  98. continue;
  99. auto* proto = system_profile->add_chrome_component();
  100. proto->set_component_id(id);
  101. proto->set_version(component.version.GetString());
  102. proto->set_omaha_fingerprint(Trim(component.fingerprint));
  103. }
  104. }
  105. } // namespace metrics