Bug 1320087 - Make the captive portal report UNKNOWN when the wifi is down r=bagder a=jcristau
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 09 Jan 2017 16:07:03 +0100
changeset 353570 b618acd89350d190d057ad8a42d9f370731073f7
parent 353569 eb0973de87ee755ca04ef794ed279b1717f2da51
child 353571 248982f8164bb10174a161011addbdc131cafdff
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder, jcristau
bugs1320087
milestone52.0a2
Bug 1320087 - Make the captive portal report UNKNOWN when the wifi is down r=bagder a=jcristau * 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;
     }