Introduce a MetricsProvider interface.

Also, introduces a way to register MetricsProviders
on MetricsService.

BUG=374229
[email protected]

Review URL: https://codereview.chromium.org/296483004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271652 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index f35b5f5..0041bc4 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -38,6 +38,7 @@
 #include "chrome/common/chrome_version_info.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/installer/util/google_update_settings.h"
+#include "components/metrics/metrics_provider.h"
 #include "components/metrics/proto/omnibox_event.pb.h"
 #include "components/metrics/proto/profiler_event.pb.h"
 #include "components/metrics/proto/system_profile.pb.h"
@@ -448,8 +449,10 @@
   return g_version_extension.Get();
 }
 
-void MetricsLog::RecordStabilityMetrics(base::TimeDelta incremental_uptime,
-                                        base::TimeDelta uptime) {
+void MetricsLog::RecordStabilityMetrics(
+    const std::vector<metrics::MetricsProvider*>& metrics_providers,
+    base::TimeDelta incremental_uptime,
+    base::TimeDelta uptime) {
   DCHECK(!locked());
   DCHECK(HasEnvironment());
   DCHECK(!HasStabilityMetrics());
@@ -470,6 +473,11 @@
   // uma log upload, just as we send histogram data.
   WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
 
+  SystemProfileProto::Stability* stability =
+      uma_proto()->mutable_system_profile()->mutable_stability();
+  for (size_t i = 0; i < metrics_providers.size(); ++i)
+    metrics_providers[i]->ProvideStabilityMetrics(stability);
+
   // Omit some stats unless this is the initial stability log.
   if (log_type() != INITIAL_STABILITY_LOG)
     return;
@@ -492,8 +500,6 @@
 
   // TODO(jar): The following are all optional, so we *could* optimize them for
   // values of zero (and not include them).
-  SystemProfileProto::Stability* stability =
-      uma_proto()->mutable_system_profile()->mutable_stability();
   stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
   stability->set_breakpad_registration_success_count(
       breakpad_registration_success_count);
@@ -503,6 +509,12 @@
   stability->set_debugger_not_present_count(debugger_not_present_count);
 }
 
+void MetricsLog::RecordGeneralMetrics(
+    const std::vector<metrics::MetricsProvider*>& metrics_providers) {
+  for (size_t i = 0; i < metrics_providers.size(); ++i)
+    metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
+}
+
 PrefService* MetricsLog::GetPrefService() {
   return g_browser_process->local_state();
 }
@@ -689,6 +701,7 @@
 }
 
 void MetricsLog::RecordEnvironment(
+    const std::vector<metrics::MetricsProvider*>& metrics_providers,
     const std::vector<content::WebPluginInfo>& plugin_list,
     const GoogleUpdateMetrics& google_update_metrics,
     const std::vector<variations::ActiveGroupId>& synthetic_trials) {
@@ -795,6 +808,9 @@
   metrics_log_chromeos_->LogChromeOSMetrics();
 #endif  // OS_CHROMEOS
 
+  for (size_t i = 0; i < metrics_providers.size(); ++i)
+    metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
+
   std::string serialied_system_profile;
   std::string base64_system_profile;
   if (system_profile->SerializeToString(&serialied_system_profile)) {