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. 4 5 #ifndef COMPONENTS_METRICS_COMPONENT_METRICS_PROVIDER_H_ 6 #define COMPONENTS_METRICS_COMPONENT_METRICS_PROVIDER_H_ 7 8 #include <vector> 9 10 #include "components/metrics/metrics_provider.h" 11 #include "third_party/metrics_proto/system_profile.pb.h" 12 13 namespace component_updater { 14 struct ComponentInfo; 15 } 16 17 namespace metrics { 18 19 class SystemProfileProto; 20 21 // A delegate that returns a list of components that are loaded in the 22 // system. 23 class ComponentMetricsProviderDelegate { 24 public: 25 ComponentMetricsProviderDelegate() = default; 26 virtual ~ComponentMetricsProviderDelegate() = default; 27 28 virtual std::vector<component_updater::ComponentInfo> GetComponents() = 0; 29 }; 30 31 // Stores and loads system information to prefs for stability logs. 32 class ComponentMetricsProvider : public MetricsProvider { 33 public: 34 explicit ComponentMetricsProvider( 35 std::unique_ptr<ComponentMetricsProviderDelegate> 36 components_info_delegate); 37 38 ComponentMetricsProvider(const ComponentMetricsProvider&) = delete; 39 ComponentMetricsProvider& operator=(const ComponentMetricsProvider&) = delete; 40 41 ~ComponentMetricsProvider() override; 42 43 // MetricsProvider: 44 void ProvideSystemProfileMetrics( 45 SystemProfileProto* system_profile_proto) override; 46 47 static SystemProfileProto_ComponentId CrxIdToComponentId( 48 const std::string& app_id); 49 50 static uint32_t HashCohortId(const std::string& cohort_id); 51 52 private: 53 std::unique_ptr<ComponentMetricsProviderDelegate> components_info_delegate_; 54 }; 55 56 } // namespace metrics 57 58 #endif // COMPONENTS_METRICS_COMPONENT_METRICS_PROVIDER_H_ 59