Bug 795711 - 'network.activity.blipIntervalMilliseconds' user pref should be taken into account. r=bz
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 01 Oct 2012 10:43:14 +0100
changeset 108854 c7df097666149a619075bcd0e38efe1b97dd7e72
parent 108853 6727fcb410250a218822a9be2b69cd95d3debfc7
child 108855 e848e64275914fc28575c4addccb137d25dadeda
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersbz
bugs795711
milestone18.0a1
Bug 795711 - 'network.activity.blipIntervalMilliseconds' user pref should be taken into account. r=bz
netwerk/base/src/nsSocketTransportService2.cpp
--- a/netwerk/base/src/nsSocketTransportService2.cpp
+++ b/netwerk/base/src/nsSocketTransportService2.cpp
@@ -14,16 +14,19 @@
 #include "prnetdb.h"
 #include "prerror.h"
 #include "plstr.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIOService.h"
 #include "NetworkActivityMonitor.h"
+#include "nsIObserverService.h"
+#include "mozilla/Services.h"
+#include "mozilla/Preferences.h"
 
 
 // XXX: There is no good header file to put these in. :(
 namespace mozilla { namespace psm {
 
 void InitializeSSLServerCertVerificationThreads();
 void StopSSLServerCertVerificationThreads();
 
@@ -454,28 +457,24 @@ nsSocketTransportService::Init()
         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);
-
-        int32_t blipInterval = 0;
-        rv = tmpPrefService->GetIntPref(BLIB_INTERVAL_PREF, &blipInterval);
-        if (NS_SUCCEEDED(rv) && blipInterval > 0) {
-            rv = mozilla::net::NetworkActivityMonitor::Init(blipInterval);
-            if (NS_FAILED(rv)) {
-                NS_WARNING("Can't initialize NetworkActivityMonitor");
-            }
-        }
     }
     UpdatePrefs();
 
+    nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
+    if (obsSvc) {
+        obsSvc->AddObserver(this, "profile-initial-state", false);
+    }
+
     mInitialized = true;
     return NS_OK;
 }
 
 // called from main thread only
 NS_IMETHODIMP
 nsSocketTransportService::Shutdown()
 {
@@ -508,16 +507,21 @@ nsSocketTransportService::Shutdown()
         // readers are excluded
         mThread = nullptr;
     }
 
     nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (tmpPrefService) 
         tmpPrefService->RemoveObserver(SEND_BUFFER_PREF, this);
 
+    nsCOMPtr<nsIObserverService> obsSvc = services::GetObserverService();
+    if (obsSvc) {
+        obsSvc->RemoveObserver(this, "profile-initial-state");
+    }
+
     mozilla::net::NetworkActivityMonitor::Shutdown();
 
     mInitialized = false;
     mShuttingDown = false;
 
     return NS_OK;
 }
 
@@ -856,16 +860,26 @@ nsSocketTransportService::UpdatePrefs()
 
 NS_IMETHODIMP
 nsSocketTransportService::Observe(nsISupports *subject,
                                   const char *topic,
                                   const PRUnichar *data)
 {
     if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
         UpdatePrefs();
+        return NS_OK;
+    }
+
+    if (!strcmp(topic, "profile-initial-state")) {
+        int32_t blipInterval = Preferences::GetInt(BLIB_INTERVAL_PREF, 0);
+        if (blipInterval <= 0) {
+            return NS_OK;
+        }
+
+        return net::NetworkActivityMonitor::Init(blipInterval);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::GetSendBufferSize(int32_t *value)
 {
     *value = mSendBufferSize;