Bug 1563996 - [Attempt 2] Make consoleservice.logcat a static pref. r=erahm
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 09 Jul 2019 20:59:59 +1000
changeset 482048 4483006a672e1b3018c6235d71a90183daa0ffc5
parent 482047 76891ad847748c7c8734925f93c8f00be4c73a39
child 482049 6e5088fb8fd6ac3ad4956ec3f623b525f4cdd81a
child 482126 2b165cf536ba4b59a58eacd86c82b173377e264c
push id36267
push useraciure@mozilla.com
push dateWed, 10 Jul 2019 09:42:20 +0000
treeherdermozilla-central@6e5088fb8fd6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1563996
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1563996 - [Attempt 2] Make consoleservice.logcat a static pref. r=erahm Differential Revision: https://phabricator.services.mozilla.com/D37203
mobile/android/app/mobile.js
modules/libpref/init/StaticPrefList.h
xpcom/base/nsConsoleService.cpp
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -776,23 +776,16 @@ pref("layout.accessiblecaret.script_chan
 
 // Optionally provide haptic feedback on longPress selection events.
 pref("layout.accessiblecaret.hapticfeedback", true);
 
 // Initial text selection on long-press is enhanced to provide
 // a smarter phone-number selection for direct-dial ActionBar action.
 pref("layout.accessiblecaret.extend_selection_for_phone_number", true);
 
-// Disable sending console to logcat on release builds.
-#ifdef RELEASE_OR_BETA
-pref("consoleservice.logcat", false);
-#else
-pref("consoleservice.logcat", true);
-#endif
-
 pref("browser.tabs.showAudioPlayingIcon", true);
 
 pref("dom.serviceWorkers.enabled", true);
 
 // Allow service workers to open windows for a longer period after a notification
 // click on mobile.  This is to account for some devices being quite slow.
 pref("dom.serviceWorkers.disable_open_click_delay", 5000);
 
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1050,16 +1050,30 @@ VARCACHE_PREF(
   Live,
   "clipboard.autocopy",
   clipboard_autocopy,
   bool, PREF_VALUE
 )
 #undef PREF_VALUE
 
 //---------------------------------------------------------------------------
+// Prefs starting with "consoleservice."
+//---------------------------------------------------------------------------
+
+#if defined(ANDROID)
+// Disable sending console to logcat on release builds.
+VARCACHE_PREF(
+  Live,
+  "consoleservice.logcat",
+   consoleservice_logcat,
+  RelaxedAtomicBool, NOT_IN_RELEASE_OR_BETA_VALUE
+)
+#endif
+
+//---------------------------------------------------------------------------
 // Prefs starting with "device."
 //---------------------------------------------------------------------------
 
 // Is support for the device sensors API enabled?
 VARCACHE_PREF(
   Live,
   "device.sensors.enabled",
   device_sensors_enabled,
--- a/xpcom/base/nsConsoleService.cpp
+++ b/xpcom/base/nsConsoleService.cpp
@@ -22,16 +22,17 @@
 #include "nsIObserverService.h"
 #include "nsPrintfCString.h"
 #include "nsProxyRelease.h"
 #include "nsIScriptError.h"
 #include "nsISupportsPrimitives.h"
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/SystemGroup.h"
 
 #if defined(ANDROID)
 #  include <android/log.h>
 #  include "mozilla/dom/ContentChild.h"
 #endif
 #ifdef XP_WIN
 #  include <windows.h>
@@ -52,19 +53,16 @@ NS_IMPL_CLASSINFO(nsConsoleService, null
 NS_IMPL_QUERY_INTERFACE_CI(nsConsoleService, nsIConsoleService, nsIObserver)
 NS_IMPL_CI_INTERFACE_GETTER(nsConsoleService, nsIConsoleService, nsIObserver)
 
 static const bool gLoggingEnabled = true;
 static const bool gLoggingBuffered = true;
 #ifdef XP_WIN
 static bool gLoggingToDebugger = true;
 #endif  // XP_WIN
-#if defined(ANDROID)
-static bool gLoggingLogcat = false;
-#endif  // defined(ANDROID)
 
 nsConsoleService::MessageElement::~MessageElement() {}
 
 nsConsoleService::nsConsoleService()
     : mCurrentSize(0),
       mDeliveringMessage(false),
       mLock("nsConsoleService.mLock") {
   // XXX grab this from a pref!
@@ -133,26 +131,16 @@ nsConsoleService::~nsConsoleService() {
 }
 
 class AddConsolePrefWatchers : public Runnable {
  public:
   explicit AddConsolePrefWatchers(nsConsoleService* aConsole)
       : mozilla::Runnable("AddConsolePrefWatchers"), mConsole(aConsole) {}
 
   NS_IMETHOD Run() override {
-#if defined(ANDROID)
-    Preferences::AddBoolVarCache(&gLoggingLogcat, "consoleservice.logcat",
-#  ifdef RELEASE_OR_BETA
-                                 false
-#  else
-                                 true
-#  endif
-    );
-#endif  // defined(ANDROID)
-
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     MOZ_ASSERT(obs);
     obs->AddObserver(mConsole, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
     obs->AddObserver(mConsole, "inner-window-destroyed", false);
 
     if (!gLoggingBuffered) {
       mConsole->Reset();
     }
@@ -243,17 +231,17 @@ nsresult nsConsoleService::LogMessageWit
   /*
    * Lock while updating buffer, and while taking snapshot of
    * listeners array.
    */
   {
     MutexAutoLock lock(mLock);
 
 #if defined(ANDROID)
-    if (gLoggingLogcat && aOutputMode == OutputToLog) {
+    if (StaticPrefs::consoleservice_logcat() && aOutputMode == OutputToLog) {
       nsCString msg;
       aMessage->ToString(msg);
 
       /** Attempt to use the process name as the log tag. */
       mozilla::dom::ContentChild* child =
           mozilla::dom::ContentChild::GetSingleton();
       nsCString appName;
       if (child) {