From 1db94d70f6c2f726060f3de04a692f2f5c1a75a9 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Wed, 7 Nov 2001 04:26:19 +0000 Subject: [PATCH] Bug 104020 - send out notification after SetOffline has completed, respond to profile change notifications. r=dougt/sr=darin --- netwerk/base/src/nsIOService.cpp | 39 ++++++++++++++++++++++++++------ netwerk/base/src/nsIOService.h | 3 ++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 61077aea0ad..529f34ad211 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -138,10 +138,14 @@ PRInt16 gBadPortList[] = { 0, // This MUST be zero so that we can populating the array }; +static const char kProfileChangeNetTeardownTopic[] = "profile-change-net-teardown"; +static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore"; + //////////////////////////////////////////////////////////////////////////////// nsIOService::nsIOService() - : mOffline(PR_FALSE) + : mOffline(PR_FALSE), + mOfflineForProfileChange(PR_FALSE) { NS_INIT_REFCNT(); } @@ -219,7 +223,16 @@ nsIOService::Init() pbi->AddObserver(PORT_PREF_PREFIX, this, PR_TRUE); PrefsChanged(prefBranch); } - + + // Register for profile change notifications + nsCOMPtr observerService = + do_GetService("@mozilla.org/observer-service;1"); + NS_ASSERTION(observerService, "Failed to get observer service"); + if (observerService) { + observerService->AddObserver(this, kProfileChangeNetTeardownTopic, PR_TRUE); + observerService->AddObserver(this, kProfileChangeNetRestoreTopic, PR_TRUE); + } + return NS_OK; } @@ -791,11 +804,6 @@ nsIOService::SetOffline(PRBool offline) nsresult rv1 = NS_OK; nsresult rv2 = NS_OK; if (offline) { - // don't care if notification fails - if (observerService) - (void)observerService->NotifyObservers(NS_STATIC_CAST(nsIIOService *, this), - "network:offline-status-changed", - NS_LITERAL_STRING("offline").get()); mOffline = PR_TRUE; // indicate we're trying to shutdown // be sure to try and shutdown both (even if the first fails) if (mDNSService) @@ -805,6 +813,11 @@ nsIOService::SetOffline(PRBool offline) if (NS_FAILED(rv1)) return rv1; if (NS_FAILED(rv2)) return rv2; + // don't care if notification fails + if (observerService) + (void)observerService->NotifyObservers(NS_STATIC_CAST(nsIIOService *, this), + "network:offline-status-changed", + NS_LITERAL_STRING("offline").get()); } else if (!offline && mOffline) { // go online @@ -997,5 +1010,17 @@ nsIOService::Observe(nsISupports *subject, if (prefBranch) PrefsChanged(prefBranch, NS_ConvertUCS2toUTF8(data).get()); } + else if (!nsCRT::strcmp(topic, kProfileChangeNetTeardownTopic)) { + if (!mOffline) { + SetOffline(PR_TRUE); + mOfflineForProfileChange = PR_TRUE; + } + } + else if (!nsCRT::strcmp(topic, kProfileChangeNetRestoreTopic)) { + if (mOfflineForProfileChange) { + SetOffline(PR_FALSE); + mOfflineForProfileChange = PR_FALSE; + } + } return NS_OK; } diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index bc3b9423f0c..79477c73941 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -104,7 +104,8 @@ protected: void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool remove); protected: - PRBool mOffline; + PRPackedBool mOffline; + PRPackedBool mOfflineForProfileChange; nsCOMPtr mSocketTransportService; nsCOMPtr mFileTransportService; nsCOMPtr mDNSService;