Bug 1320087 - Make the captive portal report UNKNOWN when the wifi is down r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 09 Jan 2017 16:07:03 +0100
changeset 328530 eabf0117673e41abf14e13a46b5be5f9aadcc3a0
parent 328529 be756f2f53a530db44f0b3796acc4a3624ca4b00
child 328531 e038230119a50d99d696e9a47faf8db32bbeb0af
push id85465
push uservalentin.gosu@gmail.com
push dateMon, 09 Jan 2017 15:07:20 +0000
treeherdermozilla-inbound@eabf0117673e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1320087
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1320087 - Make the captive portal report UNKNOWN when the wifi is down r=bagder * Start/Stop the captive portal service in nsIOService::SetConnectivityInternal * Set the captive portal state to UNKNOWN when stopping it. MozReview-Commit-ID: 5dude1F4lNb
netwerk/base/CaptivePortalService.cpp
netwerk/base/nsIOService.cpp
--- a/netwerk/base/CaptivePortalService.cpp
+++ b/netwerk/base/CaptivePortalService.cpp
@@ -131,16 +131,17 @@ CaptivePortalService::Start()
     // Doesn't do anything if called in the content process.
     return NS_OK;
   }
 
   if (mStarted) {
     return NS_OK;
   }
 
+  MOZ_ASSERT(mState == UNKNOWN, "Initial state should be UNKNOWN");
   mStarted = true;
   mEverBeenCaptive = false;
 
   // Get the delay prefs
   Preferences::GetUint("network.captive-portal-service.minInterval", &mMinInterval);
   Preferences::GetUint("network.captive-portal-service.maxInterval", &mMaxInterval);
   Preferences::GetFloat("network.captive-portal-service.backoffFactor", &mBackoffFactor);
 
@@ -175,16 +176,19 @@ CaptivePortalService::Stop()
   }
   mTimer = nullptr;
   mRequestInProgress = false;
   mStarted = false;
   if (mCaptivePortalDetector) {
     mCaptivePortalDetector->Abort(kInterfaceName);
   }
   mCaptivePortalDetector = nullptr;
+
+  // Clear the state in case anyone queries the state while detection is off.
+  mState = UNKNOWN;
   return NS_OK;
 }
 
 void
 CaptivePortalService::SetStateInChild(int32_t aState)
 {
   // This should only be called in the content process, from ContentChild.cpp
   // in order to mirror the captive portal state set in the chrome process.
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -1145,16 +1145,25 @@ nsIOService::SetConnectivityInternal(boo
         return NS_OK;
     }
     mConnectivity = aConnectivity;
 
     // This is used for PR_Connect PR_Close telemetry so it is important that
     // we have statistic about network change event even if we are offline.
     mLastConnectivityChange = PR_IntervalNow();
 
+    if (mCaptivePortalService) {
+        if (aConnectivity && !xpc::AreNonLocalConnectionsDisabled()) {
+            // This will also trigger a captive portal check for the new network
+            static_cast<CaptivePortalService*>(mCaptivePortalService.get())->Start();
+        } else {
+            static_cast<CaptivePortalService*>(mCaptivePortalService.get())->Stop();
+        }
+    }
+
     nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
     if (!observerService) {
         return NS_OK;
     }
     // This notification sends the connectivity to the child processes
     if (XRE_IsParentProcess()) {
         observerService->NotifyObservers(nullptr,
             NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC, aConnectivity ?
@@ -1612,18 +1621,16 @@ nsIOService::OnNetworkLinkEvent(const ch
     bool isUp = true;
     if (!strcmp(data, NS_NETWORK_LINK_DATA_CHANGED)) {
         mLastNetworkLinkChange = PR_IntervalNow();
         // CHANGED means UP/DOWN didn't change
         return NS_OK;
     } else if (!strcmp(data, NS_NETWORK_LINK_DATA_DOWN)) {
         isUp = false;
     } else if (!strcmp(data, NS_NETWORK_LINK_DATA_UP)) {
-        // Interface is up. Triggering a captive portal recheck.
-        RecheckCaptivePortal();
         isUp = true;
     } else if (!strcmp(data, NS_NETWORK_LINK_DATA_UNKNOWN)) {
         nsresult rv = mNetworkLinkService->GetIsLinkUp(&isUp);
         NS_ENSURE_SUCCESS(rv, rv);
     } else {
         NS_WARNING("Unhandled network event!");
         return NS_OK;
     }