Android: Unify android gpu crash counts

Use stability.gpu_crash_count in the system_profile proto to track gpu
crash metrics rather than a variety of changing gpu histograms.

This new proto value is only used on Android starting in M71 and tracks
the same value as the histogram:
  "Stability.Android.ProcessedCrashCounts.All GPU process crashes"

Thus this unifies our gpu metrics across stability proto, UMA histogram,
and crash reports, since these all count the number of crashes with a
valid crash dump (note that crash reports only include the number that
are successfully processed and uploaded, so should be slightly reduced).

Bug: 839017
Change-Id: If836b4fc8c8390ce008b7089a773af0b26ea6c10
Reviewed-on: https://chromium-review.googlesource.com/1228546
Commit-Queue: Ramin Halavati <[email protected]>
Reviewed-by: Ramin Halavati <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Cr-Commit-Position: refs/heads/master@{#591947}
diff --git a/chrome/browser/metrics/chrome_stability_metrics_provider.cc b/chrome/browser/metrics/chrome_stability_metrics_provider.cc
index 8598527..f1717960 100644
--- a/chrome/browser/metrics/chrome_stability_metrics_provider.cc
+++ b/chrome/browser/metrics/chrome_stability_metrics_provider.cc
@@ -168,6 +168,10 @@
               kRendererForegroundVisibleSubframeCrash)) {
     helper_.IncreaseRendererCrashCount();
   }
+  if (reported_counts.count(crash_reporter::CrashMetricsReporter::
+                                ProcessedCrashCounts::kGpuCrashAll)) {
+    helper_.IncreaseGpuCrashCount();
+  }
 }
 
 #endif  // defined(OS_ANDROID)
diff --git a/chrome/browser/prefs/pref_service_incognito_whitelist.cc b/chrome/browser/prefs/pref_service_incognito_whitelist.cc
index d54b8bc..667fd9b 100644
--- a/chrome/browser/prefs/pref_service_incognito_whitelist.cc
+++ b/chrome/browser/prefs/pref_service_incognito_whitelist.cc
@@ -97,6 +97,7 @@
     metrics::prefs::kStabilityExtensionRendererFailedLaunchCount,
     metrics::prefs::kStabilityExtensionRendererLaunchCount,
     metrics::prefs::kStabilityGmsCoreVersion,
+    metrics::prefs::kStabilityGpuCrashCount,
     metrics::prefs::kStabilityIncompleteSessionEndCount,
     metrics::prefs::kStabilityLaunchCount,
     metrics::prefs::kStabilityPageLoadCount,
diff --git a/components/metrics/metrics_pref_names.cc b/components/metrics/metrics_pref_names.cc
index 2bf002fe..a7a79c8 100644
--- a/components/metrics/metrics_pref_names.cc
+++ b/components/metrics/metrics_pref_names.cc
@@ -147,6 +147,11 @@
 const char kStabilityGmsCoreVersion[] =
     "user_experience_metrics.stability.gms_core_version";
 
+// Number of times a gpu process crashed since the last report. Currently only
+// recorded on Android.
+const char kStabilityGpuCrashCount[] =
+    "user_experience_metrics.stability.gpu_crash_count";
+
 // Number of times the session end did not complete.
 const char kStabilityIncompleteSessionEndCount[] =
     "user_experience_metrics.stability.incomplete_session_end_count";
diff --git a/components/metrics/metrics_pref_names.h b/components/metrics/metrics_pref_names.h
index 468dad8..9901968 100644
--- a/components/metrics/metrics_pref_names.h
+++ b/components/metrics/metrics_pref_names.h
@@ -49,6 +49,7 @@
 extern const char kStabilityExtensionRendererFailedLaunchCount[];
 extern const char kStabilityExtensionRendererLaunchCount[];
 extern const char kStabilityGmsCoreVersion[];
+extern const char kStabilityGpuCrashCount[];
 extern const char kStabilityIncompleteSessionEndCount[];
 extern const char kStabilityLaunchCount[];
 extern const char kStabilityPageLoadCount[];
diff --git a/components/metrics/stability_metrics_helper.cc b/components/metrics/stability_metrics_helper.cc
index 517fc71..97f962e 100644
--- a/components/metrics/stability_metrics_helper.cc
+++ b/components/metrics/stability_metrics_helper.cc
@@ -105,6 +105,12 @@
     local_state_->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
   }
 
+  count = local_state_->GetInteger(prefs::kStabilityGpuCrashCount);
+  if (count) {
+    stability_proto->set_gpu_crash_count(count);
+    local_state_->SetInteger(prefs::kStabilityGpuCrashCount, 0);
+  }
+
   count = local_state_->GetInteger(prefs::kStabilityRendererCrashCount);
   if (count) {
     stability_proto->set_renderer_crash_count(count);
@@ -160,6 +166,7 @@
   local_state_->SetInteger(prefs::kStabilityExtensionRendererFailedLaunchCount,
                            0);
   local_state_->SetInteger(prefs::kStabilityExtensionRendererLaunchCount, 0);
+  local_state_->SetInteger(prefs::kStabilityGpuCrashCount, 0);
   local_state_->SetInteger(prefs::kStabilityPageLoadCount, 0);
   local_state_->SetInteger(prefs::kStabilityRendererCrashCount, 0);
   local_state_->SetInteger(prefs::kStabilityRendererFailedLaunchCount, 0);
@@ -176,6 +183,7 @@
       prefs::kStabilityExtensionRendererFailedLaunchCount, 0);
   registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererLaunchCount,
                                 0);
+  registry->RegisterIntegerPref(prefs::kStabilityGpuCrashCount, 0);
   registry->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
   registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
   registry->RegisterIntegerPref(prefs::kStabilityRendererFailedLaunchCount, 0);
@@ -189,6 +197,10 @@
   IncrementPrefValue(prefs::kStabilityRendererCrashCount);
 }
 
+void StabilityMetricsHelper::IncreaseGpuCrashCount() {
+  IncrementPrefValue(prefs::kStabilityGpuCrashCount);
+}
+
 void StabilityMetricsHelper::BrowserUtilityProcessLaunched(
     const std::string& metrics_name) {
   uint32_t hash = variations::HashName(metrics_name);
diff --git a/components/metrics/stability_metrics_helper.h b/components/metrics/stability_metrics_helper.h
index 5a22882a..e99f998c 100644
--- a/components/metrics/stability_metrics_helper.h
+++ b/components/metrics/stability_metrics_helper.h
@@ -61,6 +61,12 @@
   // Increments the RendererCrash pref.
   void IncreaseRendererCrashCount();
 
+  // Increments the GpuCrash pref.
+  // Note: This is currently only used on Android. If you want to call this on
+  // another platform, server-side processing code needs to be updated for that
+  // platform to use the new data. Server-side currently assumes Android-only.
+  void IncreaseGpuCrashCount();
+
  private:
   // Increments an Integer pref value specified by |path|.
   void IncrementPrefValue(const char* path);
diff --git a/third_party/metrics_proto/README.chromium b/third_party/metrics_proto/README.chromium
index 278729f..7e4c5c58 100644
--- a/third_party/metrics_proto/README.chromium
+++ b/third_party/metrics_proto/README.chromium
@@ -1,8 +1,8 @@
 Name: Metrics Protos
 Short Name: metrics_proto
 URL: This is the canonical public repository
-Version: 212805537
-Date: 2018/09/13 UTC
+Version: 213296457
+Date: 2018/09/17 UTC
 License: BSD
 Security Critical: Yes
 
diff --git a/third_party/metrics_proto/system_profile.proto b/third_party/metrics_proto/system_profile.proto
index bf85071..a76bc10 100644
--- a/third_party/metrics_proto/system_profile.proto
+++ b/third_party/metrics_proto/system_profile.proto
@@ -381,7 +381,7 @@
         // for example "Dummynet".
         optional string device_name = 3;
 
-        // The list of vendor-specific OUIs (Organziationally Unqiue
+        // The list of vendor-specific OUIs (Organizationally Unique
         // Identifiers). These are provided by the vendor through WPS
         // (Wireless Provisioning Service) information elements, which
         // identifies the content of the element.
@@ -500,7 +500,7 @@
   // Figures that can be used to generate application stability metrics.
   // All values are counts of events since the last time that these
   // values were reported.
-  // Next tag: 31
+  // Next tag: 32
   message Stability {
     // Total amount of time that the program was running, in seconds,
     // since the last time a log was recorded, as measured using a client-side
@@ -534,6 +534,9 @@
 
     // Number of non-renderer child process crashes.
     optional int32 child_process_crash_count = 6;
+    // Number of gpu crashes that generate a crash dump. Currently only used by
+    // Android Chrome starting with M71.
+    optional int32 gpu_crash_count = 31;
 
     // Number of times the browser has crashed while logged in as the "other
     // user" (guest) account.