From fc1efcd291dcff399d7e74a6ed57ccc2a7609436 Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Wed, 22 Dec 2021 05:47:02 +0000 Subject: [PATCH] Bug 1745063 - Don't send SetOffline IPC to socket process in nsIOService::Observe, r=necko-reviewers,valentin Differential Revision: https://phabricator.services.mozilla.com/D133371 --- netwerk/base/nsIOService.cpp | 31 +++++++++++++++---------------- netwerk/base/nsIOService.h | 2 ++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index e2100a8f8e04..89f30b196b9e 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -1215,7 +1215,10 @@ nsIOService::GetOffline(bool* offline) { } NS_IMETHODIMP -nsIOService::SetOffline(bool offline) { +nsIOService::SetOffline(bool offline) { return SetOfflineInternal(offline); } + +nsresult nsIOService::SetOfflineInternal(bool offline, + bool notifySocketProcess) { LOG(("nsIOService::SetOffline offline=%d\n", offline)); // When someone wants to go online (!offline) after we got XPCOM shutdown // throw ERROR_NOT_AVAILABLE to prevent return to online state. @@ -1244,7 +1247,7 @@ nsIOService::SetOffline(bool offline) { NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, offline ? u"true" : u"false"); } - if (SocketProcessReady()) { + if (SocketProcessReady() && notifySocketProcess) { Unused << mSocketProcess->GetActor()->SendSetOffline(offline); } } @@ -1578,6 +1581,13 @@ void nsIOService::SetHttpHandlerAlreadyShutingDown() { NS_IMETHODIMP nsIOService::Observe(nsISupports* subject, const char* topic, const char16_t* data) { + if (UseSocketProcess() && SocketProcessReady() && + mObserverTopicForSocketProcess.Contains(nsDependentCString(topic))) { + nsCString topicStr(topic); + nsString dataStr(data); + Unused << mSocketProcess->GetActor()->SendNotifyObserver(topicStr, dataStr); + } + if (!strcmp(topic, kProfileChangeNetTeardownTopic)) { if (!mHttpHandlerAlreadyShutingDown) { mNetTearingDownStarted = PR_IntervalNow(); @@ -1585,12 +1595,12 @@ nsIOService::Observe(nsISupports* subject, const char* topic, mHttpHandlerAlreadyShutingDown = false; if (!mOffline) { mOfflineForProfileChange = true; - SetOffline(true); + SetOfflineInternal(true, false); } } else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) { if (mOfflineForProfileChange) { mOfflineForProfileChange = false; - SetOffline(false); + SetOfflineInternal(false, false); } } else if (!strcmp(topic, kProfileDoChange)) { if (data && u"startup"_ns.Equals(data)) { @@ -1620,7 +1630,7 @@ nsIOService::Observe(nsISupports* subject, const char* topic, } mHttpHandlerAlreadyShutingDown = false; - SetOffline(true); + SetOfflineInternal(true, false); if (mCaptivePortalService) { static_cast(mCaptivePortalService.get())->Stop(); @@ -1648,17 +1658,6 @@ nsIOService::Observe(nsISupports* subject, const char* topic, NS_DispatchToMainThread(wakeupNotifier); } - if (UseSocketProcess() && - mObserverTopicForSocketProcess.Contains(nsDependentCString(topic))) { - nsCString topicStr(topic); - nsString dataStr(data); - auto sendObserver = [topicStr, dataStr]() { - Unused << gIOService->mSocketProcess->GetActor()->SendNotifyObserver( - topicStr, dataStr); - }; - CallOrWaitForSocketProcess(sendObserver); - } - return NS_OK; } diff --git a/netwerk/base/nsIOService.h b/netwerk/base/nsIOService.h index 0a8623faaf1a..723dc7afca15 100644 --- a/netwerk/base/nsIOService.h +++ b/netwerk/base/nsIOService.h @@ -199,6 +199,8 @@ class nsIOService final : public nsIIOService, void DestroySocketProcess(); + nsresult SetOfflineInternal(bool offline, bool notifySocketProcess = true); + private: mozilla::Atomic mOffline{true}; mozilla::Atomic mOfflineForProfileChange{false};