From ce15cc25b42a3507adbd9a7af5f4ddc02f1264b0 Mon Sep 17 00:00:00 2001 From: Kristen Wright Date: Mon, 1 Jun 2020 16:57:27 +0000 Subject: [PATCH] Bug 1637708 - Convert the prefs in nsClassifierStreamUpdater to static prefs r=njn Converts `urlclassifier.update.timeout_ms` and `urlclassifier.update.response_timeout_ms` to static prefs and adds the `urlclassifier` header file. Differential Revision: https://phabricator.services.mozilla.com/D76373 --- modules/libpref/init/StaticPrefList.yaml | 16 ++++++++ modules/libpref/init/all.js | 4 -- modules/libpref/moz.build | 1 + .../nsUrlClassifierStreamUpdater.cpp | 38 +++++++------------ 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 7952b3a5335b..63b99e33f69a 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -8914,6 +8914,22 @@ value: 500 mirror: always +#--------------------------------------------------------------------------- +# Prefs starting with "urlclassifier." +#--------------------------------------------------------------------------- + +# Update server response timeout for Safe Browsing. +- name: urlclassifier.update.response_timeout_ms + type: uint32_t + value: 30000 + mirror: always + +# Download update timeout for Safe Browsing. +- name: urlclassifier.update.timeout_ms + type: uint32_t + value: 90000 + mirror: always + #--------------------------------------------------------------------------- # Prefs starting with "view_source." #--------------------------------------------------------------------------- diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index bf600df78ee6..815f932b3e93 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4290,10 +4290,6 @@ pref("urlclassifier.gethashnoise", 4); // Gethash timeout for Safe Browsing pref("urlclassifier.gethash.timeout_ms", 5000); -// Update server response timeout for Safe Browsing -pref("urlclassifier.update.response_timeout_ms", 30000); -// Download update timeout for Safe Browsing -pref("urlclassifier.update.timeout_ms", 90000); // Name of the about: page to display Safe Browsing warnings (bug 399233) pref("urlclassifier.alternate_error_page", "blocked"); diff --git a/modules/libpref/moz.build b/modules/libpref/moz.build index cba0d3f52932..0b5174d5ab20 100644 --- a/modules/libpref/moz.build +++ b/modules/libpref/moz.build @@ -78,6 +78,7 @@ pref_groups = [ 'threads', 'toolkit', 'ui', + 'urlclassifier', 'view_source', 'webgl', 'widget', diff --git a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp index 1f7896738262..b5c0a88d2957 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp @@ -24,6 +24,7 @@ #include "nsIInterfaceRequestor.h" #include "mozilla/LoadContext.h" #include "mozilla/Telemetry.h" +#include "mozilla/StaticPrefs_urlclassifier.h" #include "nsContentUtils.h" #include "nsIURLFormatter.h" #include "Classifier.h" @@ -32,16 +33,10 @@ using namespace mozilla::safebrowsing; using namespace mozilla; -#define DEFAULT_RESPONSE_TIMEOUT_MS 15 * 1000 -#define DEFAULT_TIMEOUT_MS 60 * 1000 -static_assert(DEFAULT_TIMEOUT_MS > DEFAULT_RESPONSE_TIMEOUT_MS, - "General timeout must be greater than reponse timeout"); +#define MIN_TIMEOUT_MS (60 * 1000) static const char* gQuitApplicationMessage = "quit-application"; -static uint32_t sResponseTimeoutMs = DEFAULT_RESPONSE_TIMEOUT_MS; -static uint32_t sTimeoutMs = DEFAULT_TIMEOUT_MS; - // Limit the list file size to 32mb const uint32_t MAX_FILE_SIZE = (32 * 1024 * 1024); @@ -200,33 +195,26 @@ nsresult nsUrlClassifierStreamUpdater::FetchUpdate( mTelemetryClockStart = PR_IntervalNow(); mStreamTable = aStreamTable; - static bool preferencesInitialized = false; - - if (!preferencesInitialized) { - mozilla::Preferences::AddUintVarCache( - &sTimeoutMs, "urlclassifier.update.timeout_ms", DEFAULT_TIMEOUT_MS); - mozilla::Preferences::AddUintVarCache( - &sResponseTimeoutMs, "urlclassifier.update.response_timeout_ms", - DEFAULT_RESPONSE_TIMEOUT_MS); - preferencesInitialized = true; - } - - if (sResponseTimeoutMs > sTimeoutMs) { + if (StaticPrefs::urlclassifier_update_response_timeout_ms() > + StaticPrefs::urlclassifier_update_timeout_ms()) { NS_WARNING( "Safe Browsing response timeout is greater than the general " "timeout. Disabling these update timeouts."); return NS_OK; } MOZ_TRY_VAR(mResponseTimeoutTimer, - NS_NewTimerWithCallback(this, sResponseTimeoutMs, - nsITimer::TYPE_ONE_SHOT)); + NS_NewTimerWithCallback( + this, StaticPrefs::urlclassifier_update_response_timeout_ms(), + nsITimer::TYPE_ONE_SHOT)); - MOZ_TRY_VAR(mTimeoutTimer, NS_NewTimerWithCallback(this, sTimeoutMs, - nsITimer::TYPE_ONE_SHOT)); + MOZ_TRY_VAR(mTimeoutTimer, + NS_NewTimerWithCallback( + this, StaticPrefs::urlclassifier_update_timeout_ms(), + nsITimer::TYPE_ONE_SHOT)); - if (sTimeoutMs < DEFAULT_TIMEOUT_MS) { + if (StaticPrefs::urlclassifier_update_timeout_ms() < MIN_TIMEOUT_MS) { LOG(("Download update timeout %d ms (< %d ms) would be too small", - sTimeoutMs, DEFAULT_TIMEOUT_MS)); + StaticPrefs::urlclassifier_update_timeout_ms(), MIN_TIMEOUT_MS)); } return NS_OK;