Re-land "Add stats to distinguish android renderer crashes."

This CL is a precursor to expanding Clank stability scope
to all OOM protected renderers that crash while Chrome is
in the foreground.

The difference in scope is effectively the number of renderers
that crash as its corresponding tabs are all backgrounded.
This transition time is one second before the OOM protection
is dropped. Most, if not all, such renderer crashes are due
to the Android OOM killer. Overall difference in proposed
stability stats will not be much different, and will be easily
seen with the new histogram.

Expanding scope allows us to have native record which of
the renderer crashes actually results in a minidump file
being generated, thus demystifying whether the renderer
was OOM killed or actually crashed. This native stat can
be made more robust in the future, but this CL paves the
foundation, assuming Tab.RendererExitStatus is comparable
to Tab.RendererCrashStatus.

When the renderer is cleanly shutdown, there are no details
and no need to record any stats. Thus we skip stat recording
for NOTIFICATION_RENDERER_PROCESS_TERMINATED.

BUG=510327,560813

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

Cr-Commit-Position: refs/heads/master@{#362511}


CrOS-Libchrome-Original-Commit: 273fee6d7f3ab923ba539c52c2a35a20844bdca4
diff --git a/base/android/application_status_listener.cc b/base/android/application_status_listener.cc
index 5aee781..a139268 100644
--- a/base/android/application_status_listener.cc
+++ b/base/android/application_status_listener.cc
@@ -65,6 +65,12 @@
                            state);
 }
 
+// static
+ApplicationState ApplicationStatusListener::GetState() {
+  return static_cast<ApplicationState>(
+      Java_ApplicationStatus_getStateForApplication(AttachCurrentThread()));
+}
+
 static void OnApplicationStateChange(JNIEnv* env,
                                      const JavaParamRef<jclass>& clazz,
                                      jint new_state) {
diff --git a/base/android/application_status_listener.h b/base/android/application_status_listener.h
index 30048b2..866ec8b 100644
--- a/base/android/application_status_listener.h
+++ b/base/android/application_status_listener.h
@@ -27,6 +27,7 @@
 // A Java counterpart will be generated for this enum.
 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base
 enum ApplicationState {
+  APPLICATION_STATE_UNKNOWN = 0,
   APPLICATION_STATE_HAS_RUNNING_ACTIVITIES = 1,
   APPLICATION_STATE_HAS_PAUSED_ACTIVITIES = 2,
   APPLICATION_STATE_HAS_STOPPED_ACTIVITIES = 3,
@@ -73,6 +74,9 @@
   // Internal use only: must be public to be called from JNI and unit tests.
   static void NotifyApplicationStateChange(ApplicationState state);
 
+  // Expose jni call for ApplicationStatus.getStateForApplication.
+  static ApplicationState GetState();
+
  private:
   void Notify(ApplicationState state);
 
diff --git a/base/android/java/src/org/chromium/base/ApplicationStatus.java b/base/android/java/src/org/chromium/base/ApplicationStatus.java
index d6da142..6895256 100644
--- a/base/android/java/src/org/chromium/base/ApplicationStatus.java
+++ b/base/android/java/src/org/chromium/base/ApplicationStatus.java
@@ -309,6 +309,7 @@
     /**
      * @return The state of the application (see {@link ApplicationState}).
      */
+    @CalledByNative
     public static int getStateForApplication() {
         synchronized (sCachedApplicationStateLock) {
             if (sCachedApplicationState == null) {