Bug 1134596 - Add network.offline-mirrors-connectivity pref to preserve previous behaviour r=honzab
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 26 Mar 2015 13:19:47 +0200
changeset 273474 bacbc07f3ad74573999ae392bb2bbc6adc365904
parent 273473 6fb1d54708024088aaffb1bba631fb1bb6bd1ab4
child 273475 d2a6230fee214ad5f23c1b9474ab96875865642a
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1134596
milestone40.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 1134596 - Add network.offline-mirrors-connectivity pref to preserve previous behaviour r=honzab
modules/libpref/init/all.js
netwerk/base/nsIOService.cpp
netwerk/base/nsIOService.h
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1163,16 +1163,21 @@ pref("network.protocol-handler.external.
 pref("network.protocol-handler.expose-all", true);
 
 // Warning for about:networking page
 pref("network.warnOnAboutNetworking", true);
 
 // Example: make IMAP an exposed protocol
 // pref("network.protocol-handler.expose.imap", true);
 
+// Whether IOService.connectivity and NS_IsOffline depends on connectivity status
+pref("network.manage-offline-status", false);
+// If set to true, IOService.offline depends on IOService.connectivity
+pref("network.offline-mirrors-connectivity", true);
+
 // <http>
 pref("network.http.version", "1.1");      // default
 // pref("network.http.version", "1.0");   // uncomment this out in case of problems
 // pref("network.http.version", "0.9");   // it'll work too if you're crazy
 // keep-alive option is effectively obsolete. Nevertheless it'll work with
 // some older 1.0 servers:
 
 pref("network.http.proxy.version", "1.1");    // default
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -54,16 +54,17 @@
 
 using namespace mozilla;
 using mozilla::net::IsNeckoChild;
 
 #define PORT_PREF_PREFIX           "network.security.ports."
 #define PORT_PREF(x)               PORT_PREF_PREFIX x
 #define AUTODIAL_PREF              "network.autodial-helper.enabled"
 #define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status"
+#define OFFLINE_MIRRORS_CONNECTIVITY "network.offline-mirrors-connectivity"
 
 // Nb: these have been misnomers since bug 715770 removed the buffer cache.
 // "network.segment.count" and "network.segment.size" would be better names,
 // but the old names are still used to preserve backward compatibility.
 #define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count"
 #define NECKO_BUFFER_CACHE_SIZE_PREF  "network.buffer.cache.size"
 #define NETWORK_NOTIFY_CHANGED_PREF   "network.notify.changed"
 
@@ -155,16 +156,17 @@ NS_IMPL_ISUPPORTS(nsAppOfflineInfo, nsIA
 
 ////////////////////////////////////////////////////////////////////////////////
 
 nsIOService::nsIOService()
     : mOffline(true)
     , mOfflineForProfileChange(false)
     , mManageLinkStatus(false)
     , mConnectivity(true)
+    , mOfflineMirrorsConnectivity(true)
     , mSettingOffline(false)
     , mSetOfflineValue(false)
     , mShutdown(false)
     , mNetworkLinkServiceInitialized(false)
     , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
     , mAutoDialEnabled(false)
     , mNetworkNotifyChanged(true)
     , mPreviousWifiState(-1)
@@ -222,16 +224,17 @@ nsIOService::Init()
         observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
         observerService->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
         observerService->AddObserver(this, kNetworkActiveChanged, true);
     }
     else
         NS_WARNING("failed to get observer service");
 
     Preferences::AddBoolVarCache(&sTelemetryEnabled, "toolkit.telemetry.enabled", false);
+    Preferences::AddBoolVarCache(&mOfflineMirrorsConnectivity, OFFLINE_MIRRORS_CONNECTIVITY, true);
 
     gIOService = this;
 
     InitializeNetworkLinkService();
 
     return NS_OK;
 }
 
@@ -867,17 +870,21 @@ nsIOService::IsLinkUp()
     }
 
     return isLinkUp;
 }
 
 NS_IMETHODIMP
 nsIOService::GetOffline(bool *offline)
 {
-    *offline = mOffline;
+    if (mOfflineMirrorsConnectivity) {
+        *offline = mOffline || !mConnectivity;
+    } else {
+        *offline = mOffline;
+    }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsIOService::SetOffline(bool offline)
 {
     // When someone wants to go online (!offline) after we got XPCOM shutdown
     // throw ERROR_NOT_AVAILABLE to prevent return to online state.
--- a/netwerk/base/nsIOService.h
+++ b/netwerk/base/nsIOService.h
@@ -122,16 +122,19 @@ private:
                                                      uint32_t aProxyFlags,
                                                      nsILoadInfo* aLoadInfo,
                                                      nsIChannel** result);
 private:
     bool                                 mOffline;
     bool                                 mOfflineForProfileChange;
     bool                                 mManageLinkStatus;
     bool                                 mConnectivity;
+    // If true, the connectivity state will be mirrored by IOService.offline
+    // meaning if !mConnectivity, GetOffline() will return true
+    bool                                 mOfflineMirrorsConnectivity;
 
     // Used to handle SetOffline() reentrancy.  See the comment in
     // SetOffline() for more details.
     bool                                 mSettingOffline;
     bool                                 mSetOfflineValue;
 
     bool                                 mShutdown;