Bug 960709 - Part 4: Use HealthRecorder.isEnabled to make StubbedHealthRecorder use more efficient. r=rnewman
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 04 Feb 2014 19:41:29 -0800
changeset 166824 229735e9e5ab855c2a941ce7f449fea9fd80d49d
parent 166823 236794ee5dd49a88ad80c5113b9aabb5e228bd24
child 166825 50c164585e255921e0f28f4e4dd929e7d94cb717
push id4842
push usermichael.l.comella@gmail.com
push dateWed, 05 Feb 2014 03:41:25 +0000
treeherderfx-team@50c164585e25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs960709
milestone30.0a1
Bug 960709 - Part 4: Use HealthRecorder.isEnabled to make StubbedHealthRecorder use more efficient. r=rnewman
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/health/BrowserHealthRecorder.java
mobile/android/base/health/HealthRecorder.java
mobile/android/base/health/StubbedHealthRecorder.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -2589,17 +2589,17 @@ abstract public class BrowserApp extends
     }
 
     @Override
     protected HealthRecorder createHealthRecorder(final Context context,
                                                   final String profilePath,
                                                   final EventDispatcher dispatcher,
                                                   final String osLocale,
                                                   final String appLocale,
-                                                  SessionInformation previousSession) {
+                                                  final SessionInformation previousSession) {
         return new BrowserHealthRecorder(context,
                                          profilePath,
                                          dispatcher,
                                          osLocale,
                                          appLocale,
                                          previousSession);
     }
 }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2112,17 +2112,17 @@ public abstract class GeckoApp
         if (SmsManager.getInstance() != null) {
             SmsManager.getInstance().stop();
             if (isFinishing())
                 SmsManager.getInstance().shutdown();
         }
 
         final HealthRecorder rec = mHealthRecorder;
         mHealthRecorder = null;
-        if (rec != null) {
+        if (rec != null && rec.isEnabled()) {
             // Closing a BrowserHealthRecorder could incur a write.
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
                 public void run() {
                     rec.close();
                 }
             });
         }
@@ -2829,13 +2829,13 @@ public abstract class GeckoApp
         });
     }
 
     protected HealthRecorder createHealthRecorder(final Context context,
                                                   final String profilePath,
                                                   final EventDispatcher dispatcher,
                                                   final String osLocale,
                                                   final String appLocale,
-                                                  SessionInformation previousSession) {
+                                                  final SessionInformation previousSession) {
         // GeckoApp does not need to record any health information - return a stub.
         return new StubbedHealthRecorder();
     }
 }
--- a/mobile/android/base/health/BrowserHealthRecorder.java
+++ b/mobile/android/base/health/BrowserHealthRecorder.java
@@ -163,16 +163,20 @@ public class BrowserHealthRecorder imple
         this.profileCache = new ProfileInformationCache(profilePath);
         try {
             this.initialize(context, profilePath, osLocale, appLocale);
         } catch (Exception e) {
             Log.e(LOG_TAG, "Exception initializing.", e);
         }
     }
 
+    public boolean isEnabled() {
+        return true;
+    }
+
     /**
      * Shut down database connections, unregister event listeners, and perform
      * provider-specific uninitialization.
      */
     public synchronized void close() {
         switch (this.state) {
             case CLOSED:
                 Log.w(LOG_TAG, "Ignoring attempt to double-close closed BrowserHealthRecorder.");
--- a/mobile/android/base/health/HealthRecorder.java
+++ b/mobile/android/base/health/HealthRecorder.java
@@ -8,16 +8,21 @@ package org.mozilla.gecko.health;
 import android.content.SharedPreferences;
 
 import org.json.JSONObject;
 
 /**
  * HealthRecorder is an interface into the Firefox Health Report storage system.
  */
 public interface HealthRecorder {
+    /**
+     * Returns whether the Health Recorder is actively recording events.
+     */
+    public boolean isEnabled();
+
     public void setCurrentSession(SessionInformation session);
     public void checkForOrphanSessions();
 
     public void recordGeckoStartupTime(long duration);
     public void recordJavaStartupTime(long duration);
     public void recordSearch(final String engineID, final String location);
     public void recordSessionEnd(String reason, SharedPreferences.Editor editor);
     public void recordSessionEnd(String reason, SharedPreferences.Editor editor, final int environment);
--- a/mobile/android/base/health/StubbedHealthRecorder.java
+++ b/mobile/android/base/health/StubbedHealthRecorder.java
@@ -9,16 +9,18 @@ import android.content.SharedPreferences
 
 import org.json.JSONObject;
 
 /**
  * StubbedHealthRecorder is an implementation of HealthRecorder that does (you guessed it!)
  * nothing.
  */
 public class StubbedHealthRecorder implements HealthRecorder {
+    public boolean isEnabled() { return false; }
+
     public void setCurrentSession(SessionInformation session) { }
     public void checkForOrphanSessions() { }
 
     public void recordGeckoStartupTime(long duration) { }
     public void recordJavaStartupTime(long duration) { }
     public void recordSearch(final String engineID, final String location) { }
     public void recordSessionEnd(String reason, SharedPreferences.Editor editor) { }
     public void recordSessionEnd(String reason, SharedPreferences.Editor editor, final int environment) { }