Bug 1449064 - Convert html.* prefs to StaticPrefs. r=hsivonen draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 27 Mar 2018 11:59:48 +1100
changeset 772833 816104c2889492253431dfb0b31d4c8b518ac7f2
parent 772832 ac90ee72b6024f4e964413b1c4874ce55ff83112
child 772834 f66722544f93e63e447de28ddc19381e64db4de6
push id104063
push usernnethercote@mozilla.com
push dateTue, 27 Mar 2018 01:04:54 +0000
reviewershsivonen
bugs1449064
milestone61.0a1
Bug 1449064 - Convert html.* prefs to StaticPrefs. r=hsivonen MozReview-Commit-ID: 7sBOuzBJ1Pa
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
parser/html/nsHtml5Module.cpp
parser/html/nsHtml5Module.h
parser/html/nsHtml5StreamParser.cpp
parser/html/nsHtml5StreamParser.h
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -107,16 +107,44 @@ VARCACHE_PREF(
 
 VARCACHE_PREF(
   "gfx.font_rendering.opentype_svg.enabled",
    gfx_font_rendering_opentype_svg_enabled,
   bool, true
 )
 
 //---------------------------------------------------------------------------
+// HTML5 parser prefs
+//---------------------------------------------------------------------------
+
+// Toggle which thread the HTML5 parser uses for stream parsing.
+VARCACHE_PREF(
+  "html5.offmainthread",
+   html5_offmainthread,
+  bool, true
+)
+
+// Time in milliseconds between the time a network buffer is seen and the timer
+// firing when the timer hasn't fired previously in this parse in the
+// off-the-main-thread HTML5 parser.
+VARCACHE_PREF(
+  "html5.flushtimer.initialdelay",
+   html5_flushtimer_initialdelay,
+  int32_t, 120
+)
+
+// Time in milliseconds between the time a network buffer is seen and the timer
+// firing when the timer has already fired previously in this parse.
+VARCACHE_PREF(
+  "html5.flushtimer.subsequentdelay",
+   html5_flushtimer_subsequentdelay,
+  int32_t, 120
+)
+
+//---------------------------------------------------------------------------
 // Layout prefs
 //---------------------------------------------------------------------------
 
 // Is support for the font-display @font-face descriptor enabled?
 VARCACHE_PREF(
   "layout.css.font-display.enabled",
    layout_css_font_display_enabled,
   bool, true
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4915,26 +4915,16 @@ pref("device.sensors.ambientLight.enable
 #else
 pref("device.sensors.proximity.enabled", true);
 pref("device.sensors.ambientLight.enabled", true);
 #endif
 
 // Enable/Disable the device storage API for content
 pref("device.storage.enabled", false);
 
-// Toggle which thread the HTML5 parser uses for stream parsing
-pref("html5.offmainthread", true);
-// Time in milliseconds between the time a network buffer is seen and the
-// timer firing when the timer hasn't fired previously in this parse in the
-// off-the-main-thread HTML5 parser.
-pref("html5.flushtimer.initialdelay", 120);
-// Time in milliseconds between the time a network buffer is seen and the
-// timer firing when the timer has already fired previously in this parse.
-pref("html5.flushtimer.subsequentdelay", 120);
-
 // Push/Pop/Replace State prefs
 pref("browser.history.maxStateObjectSize", 655360);
 
 pref("browser.meta_refresh_when_inactive.disabled", false);
 
 // XPInstall prefs
 pref("xpinstall.whitelist.required", true);
 // Only Firefox requires add-on signatures
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -1,50 +1,48 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsHtml5Module.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
+#include "mozilla/StaticPrefs.h"
 #include "nsHtml5AttributeName.h"
 #include "nsHtml5ElementName.h"
 #include "nsHtml5HtmlAttributes.h"
 #include "nsHtml5NamedCharacters.h"
 #include "nsHtml5Portability.h"
 #include "nsHtml5StackNode.h"
 #include "nsHtml5Tokenizer.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5UTF16Buffer.h"
 #include "nsIObserverService.h"
 #include "nsIServiceManager.h"
 
 using namespace mozilla;
 
 // static
-bool nsHtml5Module::sOffMainThread = true;
 nsIThread* nsHtml5Module::sStreamParserThread = nullptr;
 nsIThread* nsHtml5Module::sMainThread = nullptr;
 
 // static
 void
 nsHtml5Module::InitializeStatics()
 {
-  Preferences::AddBoolVarCache(&sOffMainThread, "html5.offmainthread");
   nsHtml5AttributeName::initializeStatics();
   nsHtml5ElementName::initializeStatics();
   nsHtml5HtmlAttributes::initializeStatics();
   nsHtml5NamedCharacters::initializeStatics();
   nsHtml5Portability::initializeStatics();
   nsHtml5StackNode::initializeStatics();
   nsHtml5Tokenizer::initializeStatics();
   nsHtml5TreeBuilder::initializeStatics();
   nsHtml5UTF16Buffer::initializeStatics();
-  nsHtml5StreamParser::InitializeStatics();
   nsHtml5TreeOpExecutor::InitializeStatics();
 #ifdef DEBUG
   sNsHtml5ModuleInitialized = true;
 #endif
 }
 
 // static
 void
@@ -113,17 +111,17 @@ private:
 };
 
 NS_IMPL_ISUPPORTS(nsHtml5ParserThreadTerminator, nsIObserver)
 
 // static
 nsIThread*
 nsHtml5Module::GetStreamParserThread()
 {
-  if (sOffMainThread) {
+  if (StaticPrefs::html5_offmainthread()) {
     if (!sStreamParserThread) {
       NS_NewNamedThread("HTML5 Parser", &sStreamParserThread);
       NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
       nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
       NS_ASSERTION(os, "do_GetService failed");
       os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread),
                       "xpcom-shutdown-threads",
                       false);
--- a/parser/html/nsHtml5Module.h
+++ b/parser/html/nsHtml5Module.h
@@ -15,17 +15,16 @@ public:
   static void ReleaseStatics();
   static already_AddRefed<nsIParser> NewHtml5Parser();
   static nsresult Initialize(nsIParser* aParser,
                              nsIDocument* aDoc,
                              nsIURI* aURI,
                              nsISupports* aContainer,
                              nsIChannel* aChannel);
   static nsIThread* GetStreamParserThread();
-  static bool sOffMainThread;
 
 private:
 #ifdef DEBUG
   static bool sNsHtml5ModuleInitialized;
 #endif
   static nsIThread* sStreamParserThread;
   static nsIThread* sMainThread;
 };
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -14,16 +14,17 @@
 #include "nsHtml5Parser.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5AtomTable.h"
 #include "nsHtml5Module.h"
 #include "nsHtml5StreamParserPtr.h"
 #include "nsIDocShell.h"
 #include "nsIScriptError.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/SystemGroup.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "nsHtml5Highlighter.h"
 #include "expat_config.h"
 #include "expat.h"
 #include "nsINestedURI.h"
 #include "nsCharsetSource.h"
 #include "nsIWyciwygChannel.h"
@@ -31,29 +32,16 @@
 #include "nsPrintfCString.h"
 #include "nsNetUtil.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/SchedulerGroup.h"
 #include "nsJSEnvironment.h"
 
 using namespace mozilla;
 
-int32_t nsHtml5StreamParser::sTimerInitialDelay = 120;
-int32_t nsHtml5StreamParser::sTimerSubsequentDelay = 120;
-
-// static
-void
-nsHtml5StreamParser::InitializeStatics()
-{
-  Preferences::AddIntVarCache(&sTimerInitialDelay,
-                              "html5.flushtimer.initialdelay");
-  Preferences::AddIntVarCache(&sTimerSubsequentDelay,
-                              "html5.flushtimer.subsequentdelay");
-}
-
 /*
  * Note that nsHtml5StreamParser implements cycle collecting AddRef and
  * Release. Therefore, nsHtml5StreamParser must never be refcounted from
  * the parser thread!
  *
  * To work around this limitation, runnables posted by the main thread to the
  * parser thread hold their reference to the stream parser in an
  * nsHtml5StreamParserPtr. Upon creation, nsHtml5StreamParserPtr addrefs the
@@ -1199,17 +1187,18 @@ nsHtml5StreamParser::DoDataAvailable(con
     return;
   }
 
   {
     mozilla::MutexAutoLock flushTimerLock(mFlushTimerMutex);
     mFlushTimer->InitWithNamedFuncCallback(
       nsHtml5StreamParser::TimerCallback,
       static_cast<void*>(this),
-      mFlushTimerEverFired ? sTimerInitialDelay : sTimerSubsequentDelay,
+      mFlushTimerEverFired ? StaticPrefs::html5_flushtimer_initialdelay()
+                           : StaticPrefs::html5_flushtimer_subsequentdelay(),
       nsITimer::TYPE_ONE_SHOT,
       "nsHtml5StreamParser::DoDataAvailable");
   }
   mFlushTimerArmed = true;
 }
 
 class nsHtml5DataAvailable : public Runnable
 {
--- a/parser/html/nsHtml5StreamParser.h
+++ b/parser/html/nsHtml5StreamParser.h
@@ -117,18 +117,16 @@ class nsHtml5StreamParser final : public
   friend class nsHtml5TimerKungFu;
   friend class nsHtml5StreamParserPtr;
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHtml5StreamParser,
                                            nsICharsetDetectionObserver)
 
-  static void InitializeStatics();
-
   nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
                       nsHtml5Parser* aOwner,
                       eParserMode aMode);
 
   // Methods that nsHtml5StreamListener calls
   nsresult CheckListenerChain();
 
   nsresult OnStartRequest(nsIRequest* aRequest, nsISupports* aContext);
@@ -575,25 +573,11 @@ private:
    * False initially and true after the timer has fired at least once.
    */
   bool mFlushTimerEverFired;
 
   /**
    * Whether the parser is doing a normal parse, view source or plain text.
    */
   eParserMode mMode;
-
-  /**
-   * The pref html5.flushtimer.initialdelay: Time in milliseconds between
-   * the time a network buffer is seen and the timer firing when the
-   * timer hasn't fired previously in this parse.
-   */
-  static int32_t sTimerInitialDelay;
-
-  /**
-   * The pref html5.flushtimer.subsequentdelay: Time in milliseconds between
-   * the time a network buffer is seen and the timer firing when the
-   * timer has already fired previously in this parse.
-   */
-  static int32_t sTimerSubsequentDelay;
 };
 
 #endif // nsHtml5StreamParser_h