Bug 1448220 - Convert all network predictor VarCache prefs to the new StaticPrefList form. r=hurley
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 16 Mar 2018 13:26:04 +1100
changeset 773643 a7ebb62677a6e8ecff0d86953c4c36c27f78a35c
parent 773642 dea16926510733a02d98073d3a64bf7279462b99
child 773644 1c8dd93fbeb071dcc9f54eae22b19da1fc0f4f90
push id104266
push userbmo:hsivonen@hsivonen.fi
push dateWed, 28 Mar 2018 07:33:03 +0000
reviewershurley
bugs1448220
milestone61.0a1
Bug 1448220 - Convert all network predictor VarCache prefs to the new StaticPrefList form. r=hurley MozReview-Commit-ID: JiPbv84btDc
modules/libpref/init/StaticPrefList.h
modules/libpref/init/all.js
netwerk/base/Predictor.cpp
netwerk/base/Predictor.h
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -108,16 +108,138 @@ VARCACHE_PREF(
 // - true: They are allow to present http auth. dialog
 // - false: They are not allow to present http auth. dialog.
 VARCACHE_PREF(
   "network.auth.non-web-content-triggered-resources-http-auth-allow",
    network_auth_non_web_content_triggered_resources_http_auth_allow,
   bool, false
 )
 
+// Enables the predictive service.
+VARCACHE_PREF(
+  "network.predictor.enabled",
+   network_predictor_enabled,
+  bool, true
+)
+
+VARCACHE_PREF(
+  "network.predictor.enable-hover-on-ssl",
+   network_predictor_enable_hover_on_ssl,
+  bool, false
+)
+
+VARCACHE_PREF(
+  "network.predictor.enable-prefetch",
+   network_predictor_enable_prefetch,
+  bool, false
+)
+
+VARCACHE_PREF(
+  "network.predictor.page-degradation.day",
+   network_predictor_page_degradation_day,
+  int32_t, 0
+)
+VARCACHE_PREF(
+  "network.predictor.page-degradation.week",
+   network_predictor_page_degradation_week,
+  int32_t, 5
+)
+VARCACHE_PREF(
+  "network.predictor.page-degradation.month",
+   network_predictor_page_degradation_month,
+  int32_t, 10
+)
+VARCACHE_PREF(
+  "network.predictor.page-degradation.year",
+   network_predictor_page_degradation_year,
+  int32_t, 25
+)
+VARCACHE_PREF(
+  "network.predictor.page-degradation.max",
+   network_predictor_page_degradation_max,
+  int32_t, 50
+)
+
+VARCACHE_PREF(
+  "network.predictor.subresource-degradation.day",
+   network_predictor_subresource_degradation_day,
+  int32_t, 1
+)
+VARCACHE_PREF(
+  "network.predictor.subresource-degradation.week",
+   network_predictor_subresource_degradation_week,
+  int32_t, 10
+)
+VARCACHE_PREF(
+  "network.predictor.subresource-degradation.month",
+   network_predictor_subresource_degradation_month,
+  int32_t, 25
+)
+VARCACHE_PREF(
+  "network.predictor.subresource-degradation.year",
+   network_predictor_subresource_degradation_year,
+  int32_t, 50
+)
+VARCACHE_PREF(
+  "network.predictor.subresource-degradation.max",
+   network_predictor_subresource_degradation_max,
+  int32_t, 100
+)
+
+VARCACHE_PREF(
+  "network.predictor.prefetch-rolling-load-count",
+   network_predictor_prefetch_rolling_load_count,
+  int32_t, 10
+)
+
+VARCACHE_PREF(
+  "network.predictor.prefetch-min-confidence",
+   network_predictor_prefetch_min_confidence,
+  int32_t, 100
+)
+VARCACHE_PREF(
+  "network.predictor.preconnect-min-confidence",
+   network_predictor_preconnect_min_confidence,
+  int32_t, 90
+)
+VARCACHE_PREF(
+  "network.predictor.preresolve-min-confidence",
+   network_predictor_preresolve_min_confidence,
+  int32_t, 60
+)
+
+VARCACHE_PREF(
+  "network.predictor.prefetch-force-valid-for",
+   network_predictor_prefetch_force_valid_for,
+  int32_t, 10
+)
+
+VARCACHE_PREF(
+  "network.predictor.max-resources-per-entry",
+   network_predictor_max_resources_per_entry,
+  int32_t, 100
+)
+
+// This is selected in concert with max-resources-per-entry to keep memory
+// usage low-ish. The default of the combo of the two is ~50k.
+VARCACHE_PREF(
+  "network.predictor.max-uri-length",
+   network_predictor_max_uri_length,
+  uint32_t, 500
+)
+
+PREF("network.predictor.cleaned-up", bool, false)
+
+// A testing flag.
+VARCACHE_PREF(
+  "network.predictor.doing-tests",
+   network_predictor_doing_tests,
+  bool, false
+)
+
 //---------------------------------------------------------------------------
 // Preferences prefs
 //---------------------------------------------------------------------------
 
 PREF("preferences.allow.omt-write", bool, true)
 
 //---------------------------------------------------------------------------
 // End of prefs
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2168,39 +2168,16 @@ pref("network.ftp.idleConnectionTimeout"
 pref("network.dir.format", 2);
 
 // enables the prefetch service (i.e., prefetching of <link rel="next"> and
 // <link rel="prefetch"> URLs).
 pref("network.prefetch-next", true);
 // enables the preloading (i.e., preloading of <link rel="preload"> URLs).
 pref("network.preload", false);
 
-// enables the predictive service
-pref("network.predictor.enabled", true);
-pref("network.predictor.enable-hover-on-ssl", false);
-pref("network.predictor.enable-prefetch", false);
-pref("network.predictor.page-degradation.day", 0);
-pref("network.predictor.page-degradation.week", 5);
-pref("network.predictor.page-degradation.month", 10);
-pref("network.predictor.page-degradation.year", 25);
-pref("network.predictor.page-degradation.max", 50);
-pref("network.predictor.subresource-degradation.day", 1);
-pref("network.predictor.subresource-degradation.week", 10);
-pref("network.predictor.subresource-degradation.month", 25);
-pref("network.predictor.subresource-degradation.year", 50);
-pref("network.predictor.subresource-degradation.max", 100);
-pref("network.predictor.prefetch-rolling-load-count", 10);
-pref("network.predictor.prefetch-min-confidence", 100);
-pref("network.predictor.preconnect-min-confidence", 90);
-pref("network.predictor.preresolve-min-confidence", 60);
-pref("network.predictor.prefetch-force-valid-for", 10);
-pref("network.predictor.max-resources-per-entry", 100);
-pref("network.predictor.max-uri-length", 500);
-pref("network.predictor.cleaned-up", false);
-
 // The following prefs pertain to the negotiate-auth extension (see bug 17578),
 // which provides transparent Kerberos or NTLM authentication using the SPNEGO
 // protocol.  Each pref is a comma-separated list of keys, where each key has
 // the format:
 //   [scheme "://"] [host [":" port]]
 // For example, "foo.com" would match "http://www.foo.com/bar", etc.
 
 // Force less-secure NTLMv1 when needed (NTLMv2 is the default).
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -33,16 +33,17 @@
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Logging.h"
 
 #include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/Telemetry.h"
 
 #include "mozilla/net/NeckoCommon.h"
 #include "mozilla/net/NeckoParent.h"
 
 #include "LoadContextInfo.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "SerializedLoadContext.h"
@@ -68,81 +69,16 @@ static LazyLogModule gPredictorLog("Netw
   do { \
     if (NS_FAILED(_rv)) { \
       return; \
     } \
   } while (0)
 
 #define NOW_IN_SECONDS() static_cast<uint32_t>(PR_Now() / PR_USEC_PER_SEC)
 
-
-static const char PREDICTOR_ENABLED_PREF[] = "network.predictor.enabled";
-static const char PREDICTOR_SSL_HOVER_PREF[] = "network.predictor.enable-hover-on-ssl";
-static const char PREDICTOR_PREFETCH_PREF[] = "network.predictor.enable-prefetch";
-
-static const char PREDICTOR_PAGE_DELTA_DAY_PREF[] =
-  "network.predictor.page-degradation.day";
-static const int32_t PREDICTOR_PAGE_DELTA_DAY_DEFAULT = 0;
-static const char PREDICTOR_PAGE_DELTA_WEEK_PREF[] =
-  "network.predictor.page-degradation.week";
-static const int32_t PREDICTOR_PAGE_DELTA_WEEK_DEFAULT = 5;
-static const char PREDICTOR_PAGE_DELTA_MONTH_PREF[] =
-  "network.predictor.page-degradation.month";
-static const int32_t PREDICTOR_PAGE_DELTA_MONTH_DEFAULT = 10;
-static const char PREDICTOR_PAGE_DELTA_YEAR_PREF[] =
-  "network.predictor.page-degradation.year";
-static const int32_t PREDICTOR_PAGE_DELTA_YEAR_DEFAULT = 25;
-static const char PREDICTOR_PAGE_DELTA_MAX_PREF[] =
-  "network.predictor.page-degradation.max";
-static const int32_t PREDICTOR_PAGE_DELTA_MAX_DEFAULT = 50;
-static const char PREDICTOR_SUB_DELTA_DAY_PREF[] =
-  "network.predictor.subresource-degradation.day";
-static const int32_t PREDICTOR_SUB_DELTA_DAY_DEFAULT = 1;
-static const char PREDICTOR_SUB_DELTA_WEEK_PREF[] =
-  "network.predictor.subresource-degradation.week";
-static const int32_t PREDICTOR_SUB_DELTA_WEEK_DEFAULT = 10;
-static const char PREDICTOR_SUB_DELTA_MONTH_PREF[] =
-  "network.predictor.subresource-degradation.month";
-static const int32_t PREDICTOR_SUB_DELTA_MONTH_DEFAULT = 25;
-static const char PREDICTOR_SUB_DELTA_YEAR_PREF[] =
-  "network.predictor.subresource-degradation.year";
-static const int32_t PREDICTOR_SUB_DELTA_YEAR_DEFAULT = 50;
-static const char PREDICTOR_SUB_DELTA_MAX_PREF[] =
-  "network.predictor.subresource-degradation.max";
-static const int32_t PREDICTOR_SUB_DELTA_MAX_DEFAULT = 100;
-
-static const char PREDICTOR_PREFETCH_ROLLING_LOAD_PREF[] =
-  "network.predictor.prefetch-rolling-load-count";
-static const int32_t PREFETCH_ROLLING_LOAD_DEFAULT = 10;
-static const char PREDICTOR_PREFETCH_MIN_PREF[] =
-  "network.predictor.prefetch-min-confidence";
-static const int32_t PREFETCH_MIN_DEFAULT = 100;
-static const char PREDICTOR_PRECONNECT_MIN_PREF[] =
-  "network.predictor.preconnect-min-confidence";
-static const int32_t PRECONNECT_MIN_DEFAULT = 90;
-static const char PREDICTOR_PRERESOLVE_MIN_PREF[] =
-  "network.predictor.preresolve-min-confidence";
-static const int32_t PRERESOLVE_MIN_DEFAULT = 60;
-
-static const char PREDICTOR_PREFETCH_FORCE_VALID_PREF[] =
-  "network.predictor.prefetch-force-valid-for";
-static const int32_t PREFETCH_FORCE_VALID_DEFAULT = 10;
-
-static const char PREDICTOR_MAX_RESOURCES_PREF[] =
-  "network.predictor.max-resources-per-entry";
-static const uint32_t PREDICTOR_MAX_RESOURCES_DEFAULT = 100;
-
-// This is selected in concert with max-resources-per-entry to keep memory usage
-// low-ish. The default of the combo of the two is ~50k
-static const char PREDICTOR_MAX_URI_LENGTH_PREF[] =
-  "network.predictor.max-uri-length";
-static const uint32_t PREDICTOR_MAX_URI_LENGTH_DEFAULT = 500;
-
-static const char PREDICTOR_DOING_TESTS_PREF[] = "network.predictor.doing-tests";
-
 static const char PREDICTOR_CLEANED_UP_PREF[] = "network.predictor.cleaned-up";
 
 // All these time values are in sec
 static const uint32_t ONE_DAY = 86400U;
 static const uint32_t ONE_WEEK = 7U * ONE_DAY;
 static const uint32_t ONE_MONTH = 30U * ONE_DAY;
 static const uint32_t ONE_YEAR = 365U * ONE_DAY;
 
@@ -324,38 +260,17 @@ NS_IMPL_ISUPPORTS(Predictor,
                   nsIObserver,
                   nsISpeculativeConnectionOverrider,
                   nsIInterfaceRequestor,
                   nsICacheEntryMetaDataVisitor,
                   nsINetworkPredictorVerifier)
 
 Predictor::Predictor()
   :mInitialized(false)
-  ,mEnabled(true)
-  ,mEnableHoverOnSSL(false)
-  ,mEnablePrefetch(true)
-  ,mPageDegradationDay(PREDICTOR_PAGE_DELTA_DAY_DEFAULT)
-  ,mPageDegradationWeek(PREDICTOR_PAGE_DELTA_WEEK_DEFAULT)
-  ,mPageDegradationMonth(PREDICTOR_PAGE_DELTA_MONTH_DEFAULT)
-  ,mPageDegradationYear(PREDICTOR_PAGE_DELTA_YEAR_DEFAULT)
-  ,mPageDegradationMax(PREDICTOR_PAGE_DELTA_MAX_DEFAULT)
-  ,mSubresourceDegradationDay(PREDICTOR_SUB_DELTA_DAY_DEFAULT)
-  ,mSubresourceDegradationWeek(PREDICTOR_SUB_DELTA_WEEK_DEFAULT)
-  ,mSubresourceDegradationMonth(PREDICTOR_SUB_DELTA_MONTH_DEFAULT)
-  ,mSubresourceDegradationYear(PREDICTOR_SUB_DELTA_YEAR_DEFAULT)
-  ,mSubresourceDegradationMax(PREDICTOR_SUB_DELTA_MAX_DEFAULT)
-  ,mPrefetchRollingLoadCount(PREFETCH_ROLLING_LOAD_DEFAULT)
-  ,mPrefetchMinConfidence(PREFETCH_MIN_DEFAULT)
-  ,mPreconnectMinConfidence(PRECONNECT_MIN_DEFAULT)
-  ,mPreresolveMinConfidence(PRERESOLVE_MIN_DEFAULT)
-  ,mPrefetchForceValidFor(PREFETCH_FORCE_VALID_DEFAULT)
-  ,mMaxResourcesPerEntry(PREDICTOR_MAX_RESOURCES_DEFAULT)
   ,mStartupCount(1)
-  ,mMaxURILength(PREDICTOR_MAX_URI_LENGTH_DEFAULT)
-  ,mDoingTests(false)
 {
   MOZ_ASSERT(!sSelf, "multiple Predictor instances!");
   sSelf = this;
 }
 
 Predictor::~Predictor()
 {
   if (mInitialized)
@@ -376,80 +291,18 @@ Predictor::InstallObserver()
     mozilla::services::GetObserverService();
   if (!obs) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  Preferences::AddBoolVarCache(&mEnabled, PREDICTOR_ENABLED_PREF, true);
-  Preferences::AddBoolVarCache(&mEnableHoverOnSSL,
-                               PREDICTOR_SSL_HOVER_PREF, false);
-  Preferences::AddBoolVarCache(&mEnablePrefetch, PREDICTOR_PREFETCH_PREF, true);
-  Preferences::AddIntVarCache(&mPageDegradationDay,
-                              PREDICTOR_PAGE_DELTA_DAY_PREF,
-                              PREDICTOR_PAGE_DELTA_DAY_DEFAULT);
-  Preferences::AddIntVarCache(&mPageDegradationWeek,
-                              PREDICTOR_PAGE_DELTA_WEEK_PREF,
-                              PREDICTOR_PAGE_DELTA_WEEK_DEFAULT);
-  Preferences::AddIntVarCache(&mPageDegradationMonth,
-                              PREDICTOR_PAGE_DELTA_MONTH_PREF,
-                              PREDICTOR_PAGE_DELTA_MONTH_DEFAULT);
-  Preferences::AddIntVarCache(&mPageDegradationYear,
-                              PREDICTOR_PAGE_DELTA_YEAR_PREF,
-                              PREDICTOR_PAGE_DELTA_YEAR_DEFAULT);
-  Preferences::AddIntVarCache(&mPageDegradationMax,
-                              PREDICTOR_PAGE_DELTA_MAX_PREF,
-                              PREDICTOR_PAGE_DELTA_MAX_DEFAULT);
-
-  Preferences::AddIntVarCache(&mSubresourceDegradationDay,
-                              PREDICTOR_SUB_DELTA_DAY_PREF,
-                              PREDICTOR_SUB_DELTA_DAY_DEFAULT);
-  Preferences::AddIntVarCache(&mSubresourceDegradationWeek,
-                              PREDICTOR_SUB_DELTA_WEEK_PREF,
-                              PREDICTOR_SUB_DELTA_WEEK_DEFAULT);
-  Preferences::AddIntVarCache(&mSubresourceDegradationMonth,
-                              PREDICTOR_SUB_DELTA_MONTH_PREF,
-                              PREDICTOR_SUB_DELTA_MONTH_DEFAULT);
-  Preferences::AddIntVarCache(&mSubresourceDegradationYear,
-                              PREDICTOR_SUB_DELTA_YEAR_PREF,
-                              PREDICTOR_SUB_DELTA_YEAR_DEFAULT);
-  Preferences::AddIntVarCache(&mSubresourceDegradationMax,
-                              PREDICTOR_SUB_DELTA_MAX_PREF,
-                              PREDICTOR_SUB_DELTA_MAX_DEFAULT);
-
-  Preferences::AddIntVarCache(&mPrefetchRollingLoadCount,
-                              PREDICTOR_PREFETCH_ROLLING_LOAD_PREF,
-                              PREFETCH_ROLLING_LOAD_DEFAULT);
-  Preferences::AddIntVarCache(&mPrefetchMinConfidence,
-                              PREDICTOR_PREFETCH_MIN_PREF,
-                              PREFETCH_MIN_DEFAULT);
-  Preferences::AddIntVarCache(&mPreconnectMinConfidence,
-                              PREDICTOR_PRECONNECT_MIN_PREF,
-                              PRECONNECT_MIN_DEFAULT);
-  Preferences::AddIntVarCache(&mPreresolveMinConfidence,
-                              PREDICTOR_PRERESOLVE_MIN_PREF,
-                              PRERESOLVE_MIN_DEFAULT);
-
-  Preferences::AddIntVarCache(&mPrefetchForceValidFor,
-                              PREDICTOR_PREFETCH_FORCE_VALID_PREF,
-                              PREFETCH_FORCE_VALID_DEFAULT);
-
-  Preferences::AddIntVarCache(&mMaxResourcesPerEntry,
-                              PREDICTOR_MAX_RESOURCES_PREF,
-                              PREDICTOR_MAX_RESOURCES_DEFAULT);
-
   mCleanedUp = Preferences::GetBool(PREDICTOR_CLEANED_UP_PREF, false);
 
-  Preferences::AddUintVarCache(&mMaxURILength, PREDICTOR_MAX_URI_LENGTH_PREF,
-                               PREDICTOR_MAX_URI_LENGTH_DEFAULT);
-
-  Preferences::AddBoolVarCache(&mDoingTests, PREDICTOR_DOING_TESTS_PREF, false);
-
   if (!mCleanedUp) {
     NS_NewTimerWithObserver(getter_AddRefs(mCleanupTimer),
                             this, 60 * 1000, nsITimer::TYPE_ONE_SHOT);
   }
 
   return rv;
 }
 
@@ -732,17 +585,17 @@ private:
 
 } // namespace
 
 void
 Predictor::MaybeCleanupOldDBFiles()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!mEnabled || mCleanedUp) {
+  if (!StaticPrefs::network_predictor_enabled() || mCleanedUp) {
     return;
   }
 
   mCleanedUp = true;
 
   // This is used for cleaning up junk left over from the old backend
   // built on top of sqlite, if necessary.
   nsCOMPtr<nsIFile> dbFile;
@@ -861,17 +714,17 @@ Predictor::PredictNative(nsIURI *targetU
 
   PREDICTOR_LOG(("    called on parent process"));
 
   if (!mInitialized) {
     PREDICTOR_LOG(("    not initialized"));
     return NS_OK;
   }
 
-  if (!mEnabled) {
+  if (!StaticPrefs::network_predictor_enabled()) {
     PREDICTOR_LOG(("    not enabled"));
     return NS_OK;
   }
 
   if (originAttributes.mPrivateBrowsingId > 0) {
     // Don't want to do anything in PB mode
     PREDICTOR_LOG(("    in PB mode"));
     return NS_OK;
@@ -1026,17 +879,17 @@ Predictor::PredictForLink(nsIURI *target
   MOZ_ASSERT(NS_IsMainThread());
 
   PREDICTOR_LOG(("Predictor::PredictForLink"));
   if (!mSpeculativeService) {
     PREDICTOR_LOG(("    missing speculative service"));
     return;
   }
 
-  if (!mEnableHoverOnSSL) {
+  if (!StaticPrefs::network_predictor_enable_hover_on_ssl()) {
     bool isSSL = false;
     sourceURI->SchemeIs("https", &isSSL);
     if (isSSL) {
       // We don't want to predict from an HTTPS page, to avoid info leakage
       PREDICTOR_LOG(("    Not predicting for link hover - on an SSL page"));
       return;
     }
   }
@@ -1147,25 +1000,30 @@ Predictor::PredictForStartup(nsICacheEnt
 int32_t
 Predictor::CalculateGlobalDegradation(uint32_t lastLoad)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   int32_t globalDegradation;
   uint32_t delta = NOW_IN_SECONDS() - lastLoad;
   if (delta < ONE_DAY) {
-    globalDegradation = mPageDegradationDay;
+    globalDegradation =
+      StaticPrefs::network_predictor_page_degradation_day();
   } else if (delta < ONE_WEEK) {
-    globalDegradation = mPageDegradationWeek;
+    globalDegradation =
+      StaticPrefs::network_predictor_page_degradation_week();
   } else if (delta < ONE_MONTH) {
-    globalDegradation = mPageDegradationMonth;
+    globalDegradation =
+      StaticPrefs::network_predictor_page_degradation_month();
   } else if (delta < ONE_YEAR) {
-    globalDegradation = mPageDegradationYear;
+    globalDegradation =
+      StaticPrefs::network_predictor_page_degradation_year();
   } else {
-    globalDegradation = mPageDegradationMax;
+    globalDegradation =
+      StaticPrefs::network_predictor_page_degradation_max();
   }
 
   Telemetry::Accumulate(Telemetry::PREDICTOR_GLOBAL_DEGRADATION,
                         globalDegradation);
   return globalDegradation;
 }
 
 // This calculates our overall confidence that a particular subresource will be
@@ -1196,34 +1054,40 @@ Predictor::CalculateConfidence(uint32_t 
 
   int32_t baseConfidence = (hitCount * 100) / hitsPossible;
   int32_t maxConfidence = 100;
   int32_t confidenceDegradation = 0;
 
   if (lastHit < lastPossible) {
     // We didn't load this subresource the last time this top-level load was
     // performed, so let's not bother preconnecting (at the very least).
-    maxConfidence = mPreconnectMinConfidence - 1;
+    maxConfidence =
+      StaticPrefs::network_predictor_preconnect_min_confidence() - 1;
 
     // Now calculate how much we want to degrade our confidence based on how
     // long it's been between the last time we did this top-level load and the
     // last time this top-level load included this subresource.
     PRTime delta = lastPossible - lastHit;
     if (delta == 0) {
       confidenceDegradation = 0;
     } else if (delta < ONE_DAY) {
-      confidenceDegradation = mSubresourceDegradationDay;
+      confidenceDegradation =
+        StaticPrefs::network_predictor_subresource_degradation_day();
     } else if (delta < ONE_WEEK) {
-      confidenceDegradation = mSubresourceDegradationWeek;
+      confidenceDegradation =
+        StaticPrefs::network_predictor_subresource_degradation_week();
     } else if (delta < ONE_MONTH) {
-      confidenceDegradation = mSubresourceDegradationMonth;
+      confidenceDegradation =
+        StaticPrefs::network_predictor_subresource_degradation_month();
     } else if (delta < ONE_YEAR) {
-      confidenceDegradation = mSubresourceDegradationYear;
+      confidenceDegradation =
+        StaticPrefs::network_predictor_subresource_degradation_year();
     } else {
-      confidenceDegradation = mSubresourceDegradationMax;
+      confidenceDegradation =
+        StaticPrefs::network_predictor_subresource_degradation_max();
       maxConfidence = 0;
     }
   }
 
   // Calculate our confidence and clamp it to between 0 and maxConfidence
   // (<= 100)
   int32_t confidence = baseConfidence - confidenceDegradation - globalDegradation;
   confidence = std::max(confidence, 0);
@@ -1270,35 +1134,36 @@ Predictor::UpdateRollingLoadCount(nsICac
   uint32_t newFlags = (flags & kFlagsMask) | rollingLoadCount;
 
   // Finally, update the metadata on the cache entry.
   nsAutoCString newValue;
   MakeMetadataEntry(hitCount, lastHit, newFlags, newValue);
   entry->SetMetaDataElement(key, newValue.BeginReading());
 }
 
-void
-Predictor::SanitizePrefs()
+uint32_t
+Predictor::ClampedPrefetchRollingLoadCount()
 {
-  if (mPrefetchRollingLoadCount < 0) {
-    mPrefetchRollingLoadCount = 0;
-  } else if (mPrefetchRollingLoadCount > kMaxPrefetchRollingLoadCount) {
-    mPrefetchRollingLoadCount = kMaxPrefetchRollingLoadCount;
+  int32_t n = StaticPrefs::network_predictor_prefetch_rolling_load_count();
+  if (n < 0) {
+    return 0;
   }
+  if (n > kMaxPrefetchRollingLoadCount) {
+    return kMaxPrefetchRollingLoadCount;
+  }
+  return n;
 }
 
 void
 Predictor::CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
                                 uint32_t lastLoad, uint32_t loadCount,
                                 int32_t globalDegradation, bool fullUri)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  SanitizePrefs();
-
   // Since the visitor gets called under a cache lock, all we do there is get
   // copies of the keys/values we care about, and then do the real work here
   entry->VisitMetaData(this);
   nsTArray<nsCString> keysToOperateOn, valuesToOperateOn;
   keysToOperateOn.SwapElements(mKeysToOperateOn);
   valuesToOperateOn.SwapElements(mValuesToOperateOn);
 
   MOZ_ASSERT(keysToOperateOn.Length() == valuesToOperateOn.Length());
@@ -1336,17 +1201,18 @@ Predictor::CalculatePredictions(nsICache
       PREDICTOR_LOG(("    forcing non-cacheability - no referrer"));
       if (flags & FLAG_PREFETCHABLE) {
         // This only applies if we had somehow otherwise marked this
         // prefetchable.
         reason = NO_REFERRER;
       }
       flags &= ~FLAG_PREFETCHABLE;
     } else {
-      uint32_t expectedRollingLoadCount = (1 << mPrefetchRollingLoadCount) - 1;
+      uint32_t expectedRollingLoadCount =
+        (1 << ClampedPrefetchRollingLoadCount()) - 1;
       expectedRollingLoadCount <<= kRollingLoadOffset;
       if ((flags & expectedRollingLoadCount) != expectedRollingLoadCount) {
         PREDICTOR_LOG(("    forcing non-cacheability - missed a load"));
         if (flags & FLAG_PREFETCHABLE) {
           // This only applies if we had somehow otherwise marked this
           // prefetchable.
           reason = MISSED_A_LOAD;
         }
@@ -1364,31 +1230,34 @@ Predictor::CalculatePredictions(nsICache
 void
 Predictor::SetupPrediction(int32_t confidence, uint32_t flags,
                            const nsCString &uri,
                            PrefetchIgnoreReason earlyReason)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsresult rv = NS_OK;
-  PREDICTOR_LOG(("SetupPrediction mEnablePrefetch=%d mPrefetchMinConfidence=%d "
-                 "mPreconnectMinConfidence=%d mPreresolveMinConfidence=%d "
-                 "flags=%d confidence=%d uri=%s", mEnablePrefetch,
-                 mPrefetchMinConfidence, mPreconnectMinConfidence,
-                 mPreresolveMinConfidence, flags, confidence, uri.get()));
+  PREDICTOR_LOG(("SetupPrediction enable-prefetch=%d prefetch-min-confidence=%d "
+                 "preconnect-min-confidence=%d preresolve-min-confidence=%d "
+                 "flags=%d confidence=%d uri=%s",
+                 StaticPrefs::network_predictor_enable_prefetch(),
+                 StaticPrefs::network_predictor_prefetch_min_confidence(),
+                 StaticPrefs::network_predictor_preconnect_min_confidence(),
+                 StaticPrefs::network_predictor_preresolve_min_confidence(),
+                 flags, confidence, uri.get()));
 
   bool prefetchOk = !!(flags & FLAG_PREFETCHABLE);
   PrefetchIgnoreReason reason = earlyReason;
-  if (prefetchOk && !mEnablePrefetch) {
+  if (prefetchOk && !StaticPrefs::network_predictor_enable_prefetch()) {
     prefetchOk = false;
     reason = PREFETCH_DISABLED;
-  } else if (prefetchOk && !mPrefetchRollingLoadCount &&
-             confidence < mPrefetchMinConfidence) {
+  } else if (prefetchOk && !ClampedPrefetchRollingLoadCount() &&
+             confidence < StaticPrefs::network_predictor_prefetch_min_confidence()) {
     prefetchOk = false;
-    if (!mPrefetchRollingLoadCount) {
+    if (!ClampedPrefetchRollingLoadCount()) {
       reason = PREFETCH_DISABLED_VIA_COUNT;
     } else {
       reason = CONFIDENCE_TOO_LOW;
     }
   }
 
   // prefetchOk == false and reason == PREFETCH_OK indicates that the reason
   // we aren't prefetching this item is because it was marked un-prefetchable in
@@ -1401,24 +1270,26 @@ Predictor::SetupPrediction(int32_t confi
 
   if (prefetchOk) {
     nsCOMPtr<nsIURI> prefetchURI;
     rv = NS_NewURI(getter_AddRefs(prefetchURI), uri, nullptr, nullptr,
                    mIOService);
     if (NS_SUCCEEDED(rv)) {
       mPrefetches.AppendElement(prefetchURI);
     }
-  } else if (confidence >= mPreconnectMinConfidence) {
+  } else if (confidence >=
+             StaticPrefs::network_predictor_preconnect_min_confidence()) {
     nsCOMPtr<nsIURI> preconnectURI;
     rv = NS_NewURI(getter_AddRefs(preconnectURI), uri, nullptr, nullptr,
                    mIOService);
     if (NS_SUCCEEDED(rv)) {
       mPreconnects.AppendElement(preconnectURI);
     }
-  } else if (confidence >= mPreresolveMinConfidence) {
+  } else if (confidence >=
+             StaticPrefs::network_predictor_preresolve_min_confidence()) {
     nsCOMPtr<nsIURI> preresolveURI;
     rv = NS_NewURI(getter_AddRefs(preresolveURI), uri, nullptr, nullptr,
                    mIOService);
     if (NS_SUCCEEDED(rv)) {
       mPreresolves.AppendElement(preresolveURI);
     }
   }
 
@@ -1614,17 +1485,17 @@ Predictor::LearnNative(nsIURI *targetURI
 
   PREDICTOR_LOG(("    called on parent process"));
 
   if (!mInitialized) {
     PREDICTOR_LOG(("    not initialized"));
     return NS_OK;
   }
 
-  if (!mEnabled) {
+  if (!StaticPrefs::network_predictor_enabled()) {
     PREDICTOR_LOG(("    not enabled"));
     return NS_OK;
   }
 
   if (originAttributes.mPrivateBrowsingId > 0) {
     // Don't want to do anything in PB mode
     PREDICTOR_LOG(("    in PB mode"));
     return NS_OK;
@@ -1788,20 +1659,19 @@ Predictor::LearnInternal(PredictorLearnR
   switch (reason) {
     case nsINetworkPredictor::LEARN_LOAD_TOPLEVEL:
       // This case only exists to be used during tests - code outside the
       // predictor tests should NEVER call Learn with LEARN_LOAD_TOPLEVEL.
       // The predictor xpcshell test needs this branch, however, because we
       // have no real page loads in xpcshell, and this is how we fake it up
       // so that all the work that normally happens behind the scenes in a
       // page load can be done for testing purposes.
-      if (fullUri && mDoingTests) {
+      if (fullUri && StaticPrefs::network_predictor_doing_tests()) {
         PREDICTOR_LOG(("    WARNING - updating rolling load count. "
                        "If you see this outside tests, you did it wrong"));
-        SanitizePrefs();
 
         // Since the visitor gets called under a cache lock, all we do there is get
         // copies of the keys/values we care about, and then do the real work here
         entry->VisitMetaData(this);
         nsTArray<nsCString> keysToOperateOn, valuesToOperateOn;
         keysToOperateOn.SwapElements(mKeysToOperateOn);
         valuesToOperateOn.SwapElements(mValuesToOperateOn);
 
@@ -1860,17 +1730,17 @@ Predictor::SpaceCleaner::OnMetaDataEleme
     // Couldn't parse this one, just get rid of it
     nsCString nsKey;
     nsKey.AssignASCII(key);
     mLongKeysToDelete.AppendElement(nsKey);
     return NS_OK;
   }
 
   uint32_t uriLength = uri.Length();
-  if (uriLength > mPredictor->mMaxURILength) {
+  if (uriLength > StaticPrefs::network_predictor_max_uri_length()) {
     // Default to getting rid of URIs that are too long and were put in before
     // we had our limit on URI length, in order to free up some space.
     nsCString nsKey;
     nsKey.AssignASCII(key);
     mLongKeysToDelete.AppendElement(nsKey);
     return NS_OK;
   }
 
@@ -1913,17 +1783,17 @@ Predictor::LearnForSubresource(nsICacheE
   rv = entry->GetFetchCount(&loadCount);
   RETURN_IF_FAILED(rv);
 
   nsCString key;
   key.AssignLiteral(META_DATA_PREFIX);
   nsCString uri;
   targetURI->GetAsciiSpec(uri);
   key.Append(uri);
-  if (uri.Length() > mMaxURILength) {
+  if (uri.Length() > StaticPrefs::network_predictor_max_uri_length()) {
     // We do this to conserve space/prevent OOMs
     PREDICTOR_LOG(("    uri too long!"));
     entry->SetMetaDataElement(key.BeginReading(), nullptr);
     return;
   }
 
   nsCString value;
   rv = entry->GetMetaDataElement(key.BeginReading(), getter_Copies(value));
@@ -1938,17 +1808,18 @@ Predictor::LearnForSubresource(nsICacheE
   if (isNewResource) {
     // This is a new addition
     PREDICTOR_LOG(("    new resource"));
     nsCString s;
     rv = entry->GetMetaDataElement(RESOURCE_META_DATA, getter_Copies(s));
     if (NS_SUCCEEDED(rv)) {
       resourceCount = atoi(s.BeginReading());
     }
-    if (resourceCount >= mMaxResourcesPerEntry) {
+    if (resourceCount >=
+        StaticPrefs::network_predictor_max_resources_per_entry()) {
       RefPtr<Predictor::SpaceCleaner> cleaner =
         new Predictor::SpaceCleaner(this);
       entry->VisitMetaData(cleaner);
       cleaner->Finalize(entry);
     } else {
       ++resourceCount;
     }
     nsAutoCString count;
@@ -2101,17 +1972,17 @@ Predictor::Reset()
 
   PREDICTOR_LOG(("    called on parent process"));
 
   if (!mInitialized) {
     PREDICTOR_LOG(("    not initialized"));
     return NS_OK;
   }
 
-  if (!mEnabled) {
+  if (!StaticPrefs::network_predictor_enabled()) {
     PREDICTOR_LOG(("    not enabled"));
     return NS_OK;
   }
 
   RefPtr<Predictor::Resetter> reset = new Predictor::Resetter(this);
   PREDICTOR_LOG(("    created a resetter"));
   mCacheStorageService->AsyncVisitAllStorages(reset, true);
   PREDICTOR_LOG(("    Cache async launched, returning now"));
@@ -2576,19 +2447,21 @@ Predictor::PrefetchListener::OnStopReque
     PREDICTOR_LOG(("    Could not get caching channel!"));
     return NS_ERROR_UNEXPECTED;
   }
 
   nsresult rv = NS_OK;
   uint32_t httpStatus;
   rv = httpChannel->GetResponseStatus(&httpStatus);
   if (NS_SUCCEEDED(rv) && httpStatus == 200) {
-    rv = cachingChannel->ForceCacheEntryValidFor(mPredictor->mPrefetchForceValidFor);
+    rv = cachingChannel->ForceCacheEntryValidFor(
+           StaticPrefs::network_predictor_prefetch_force_valid_for());
     PREDICTOR_LOG(("    forcing entry valid for %d seconds rv=%" PRIX32,
-                   mPredictor->mPrefetchForceValidFor, static_cast<uint32_t>(rv)));
+                   StaticPrefs::network_predictor_prefetch_force_valid_for(),
+                   static_cast<uint32_t>(rv)));
   } else {
     rv = cachingChannel->ForceCacheEntryValidFor(0);
     PREDICTOR_LOG(("    removing any forced validity rv=%" PRIX32,
                    static_cast<uint32_t>(rv)));
   }
 
   nsAutoCString reqName;
   rv = aRequest->GetName(reqName);
@@ -2674,17 +2547,17 @@ Predictor::UpdateCacheabilityInternal(ns
 
   nsresult rv;
 
   if (!mInitialized) {
     PREDICTOR_LOG(("    not initialized"));
     return;
   }
 
-  if (!mEnabled) {
+  if (!StaticPrefs::network_predictor_enabled()) {
     PREDICTOR_LOG(("    not enabled"));
     return;
   }
 
   nsCOMPtr<nsICacheStorage> cacheDiskStorage;
 
   RefPtr<LoadContextInfo> lci =
     new LoadContextInfo(false, originAttributes);
--- a/netwerk/base/Predictor.h
+++ b/netwerk/base/Predictor.h
@@ -440,74 +440,45 @@ private:
   // sourceURI and targetURI are the same as the arguments to Learn
   // and httpStatus is the status code we got while loading targetURI.
   void UpdateCacheabilityInternal(nsIURI *sourceURI, nsIURI *targetURI,
                                   uint32_t httpStatus, const nsCString &method,
                                   const OriginAttributes& originAttributes,
                                   bool isTracking, bool couldVary,
                                   bool isNoStore);
 
-  // Make sure our prefs are in their expected range of values
-  void SanitizePrefs();
+  // Gets the pref value and clamps it within the acceptable range.
+  uint32_t ClampedPrefetchRollingLoadCount();
 
   // Our state
   bool mInitialized;
 
-  bool mEnabled;
-  bool mEnableHoverOnSSL;
-  bool mEnablePrefetch;
-
-  int32_t mPageDegradationDay;
-  int32_t mPageDegradationWeek;
-  int32_t mPageDegradationMonth;
-  int32_t mPageDegradationYear;
-  int32_t mPageDegradationMax;
-
-  int32_t mSubresourceDegradationDay;
-  int32_t mSubresourceDegradationWeek;
-  int32_t mSubresourceDegradationMonth;
-  int32_t mSubresourceDegradationYear;
-  int32_t mSubresourceDegradationMax;
-
-  int32_t mPrefetchRollingLoadCount;
-  int32_t mPrefetchMinConfidence;
-  int32_t mPreconnectMinConfidence;
-  int32_t mPreresolveMinConfidence;
-
-  int32_t mPrefetchForceValidFor;
-
-  int32_t mMaxResourcesPerEntry;
-
   bool mCleanedUp;
   nsCOMPtr<nsITimer> mCleanupTimer;
 
   nsTArray<nsCString> mKeysToOperateOn;
   nsTArray<nsCString> mValuesToOperateOn;
 
   nsCOMPtr<nsICacheStorageService> mCacheStorageService;
 
   nsCOMPtr<nsIIOService> mIOService;
   nsCOMPtr<nsISpeculativeConnect> mSpeculativeService;
 
   nsCOMPtr<nsIURI> mStartupURI;
   uint32_t mStartupTime;
   uint32_t mLastStartupTime;
   int32_t mStartupCount;
 
-  uint32_t mMaxURILength;
-
   nsCOMPtr<nsIDNSService> mDnsService;
 
   RefPtr<DNSListener> mDNSListener;
 
   nsTArray<nsCOMPtr<nsIURI>> mPrefetches;
   nsTArray<nsCOMPtr<nsIURI>> mPreconnects;
   nsTArray<nsCOMPtr<nsIURI>> mPreresolves;
 
-  bool mDoingTests;
-
   static Predictor *sSelf;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_Predictor_h