--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -582,16 +582,35 @@ NS_IMPL_ISUPPORTS(nsSocketTransportServi
nsISocketTransportService,
nsIRoutedSocketTransportService,
nsIEventTarget,
nsIThreadObserver,
nsIRunnable,
nsPISocketTransportService,
nsIObserver)
+static const char* gCallbackPrefs[] = {
+ SEND_BUFFER_PREF,
+ KEEPALIVE_ENABLED_PREF,
+ KEEPALIVE_IDLE_TIME_PREF,
+ KEEPALIVE_RETRY_INTERVAL_PREF,
+ KEEPALIVE_PROBE_COUNT_PREF,
+ MAX_TIME_BETWEEN_TWO_POLLS,
+ TELEMETRY_PREF,
+ MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN,
+ POLLABLE_EVENT_TIMEOUT,
+ nullptr,
+};
+
+/* static */ void
+nsSocketTransportService::PrefCallback(const char* aPref, nsSocketTransportService* aSelf)
+{
+ aSelf->UpdatePrefs();
+}
+
// called from main thread only
NS_IMETHODIMP
nsSocketTransportService::Init()
{
if (!NS_IsMainThread()) {
NS_ERROR("wrong thread");
return NS_ERROR_UNEXPECTED;
}
@@ -607,28 +626,17 @@ nsSocketTransportService::Init()
if (NS_FAILED(rv)) return rv;
{
MutexAutoLock lock(mLock);
// Install our mThread, protecting against concurrent readers
thread.swap(mThread);
}
- nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
- if (tmpPrefService) {
- tmpPrefService->AddObserver(SEND_BUFFER_PREF, this, false);
- tmpPrefService->AddObserver(KEEPALIVE_ENABLED_PREF, this, false);
- tmpPrefService->AddObserver(KEEPALIVE_IDLE_TIME_PREF, this, false);
- tmpPrefService->AddObserver(KEEPALIVE_RETRY_INTERVAL_PREF, this, false);
- tmpPrefService->AddObserver(KEEPALIVE_PROBE_COUNT_PREF, this, false);
- tmpPrefService->AddObserver(MAX_TIME_BETWEEN_TWO_POLLS, this, false);
- tmpPrefService->AddObserver(TELEMETRY_PREF, this, false);
- tmpPrefService->AddObserver(MAX_TIME_FOR_PR_CLOSE_DURING_SHUTDOWN, this, false);
- tmpPrefService->AddObserver(POLLABLE_EVENT_TIMEOUT, this, false);
- }
+ Preferences::RegisterCallbacks(PrefCallback, gCallbackPrefs, this);
UpdatePrefs();
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
if (obsSvc) {
obsSvc->AddObserver(this, "profile-initial-state", false);
obsSvc->AddObserver(this, "last-pb-context-exited", false);
obsSvc->AddObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC, true);
obsSvc->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
@@ -686,19 +694,17 @@ nsSocketTransportService::ShutdownThread
mThread->Shutdown();
{
MutexAutoLock lock(mLock);
// Drop our reference to mThread and make sure that any concurrent
// readers are excluded
mThread = nullptr;
}
- nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
- if (tmpPrefService)
- tmpPrefService->RemoveObserver(SEND_BUFFER_PREF, this);
+ Preferences::UnregisterCallbacks(PrefCallback, gCallbackPrefs, this);
nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
if (obsSvc) {
obsSvc->RemoveObserver(this, "profile-initial-state");
obsSvc->RemoveObserver(this, "last-pb-context-exited");
obsSvc->RemoveObserver(this, NS_WIDGET_SLEEP_OBSERVER_TOPIC);
obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC);
obsSvc->RemoveObserver(this, "xpcom-shutdown-threads");
@@ -1434,21 +1440,16 @@ nsSocketTransportService::NotifyKeepaliv
NS_IMETHODIMP
nsSocketTransportService::Observe(nsISupports *subject,
const char *topic,
const char16_t *data)
{
SOCKET_LOG(("nsSocketTransportService::Observe topic=%s", topic));
- if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
- UpdatePrefs();
- return NS_OK;
- }
-
if (!strcmp(topic, "profile-initial-state")) {
if (!Preferences::GetBool(IO_ACTIVITY_ENABLED_PREF, false)) {
return NS_OK;
}
return net::IOActivityMonitor::Init();
}
if (!strcmp(topic, "last-pb-context-exited")) {