зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1600309 - P3: Avoid observing duplicate topics, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D134905
This commit is contained in:
Родитель
769849b41a
Коммит
d4ad673efa
|
@ -277,13 +277,13 @@ nsresult nsIOService::Init() {
|
|||
gCallbackPrefs, this);
|
||||
PrefsChanged();
|
||||
|
||||
mSocketProcessTopicBlackList.Insert(
|
||||
mSocketProcessTopicBlockedList.Insert(
|
||||
nsLiteralCString(NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID));
|
||||
mSocketProcessTopicBlackList.Insert(
|
||||
mSocketProcessTopicBlockedList.Insert(
|
||||
nsLiteralCString(NS_XPCOM_SHUTDOWN_OBSERVER_ID));
|
||||
mSocketProcessTopicBlackList.Insert("xpcom-shutdown-threads"_ns);
|
||||
mSocketProcessTopicBlackList.Insert("profile-do-change"_ns);
|
||||
mSocketProcessTopicBlackList.Insert("network:socket-process-crashed"_ns);
|
||||
mSocketProcessTopicBlockedList.Insert("xpcom-shutdown-threads"_ns);
|
||||
mSocketProcessTopicBlockedList.Insert("profile-do-change"_ns);
|
||||
mSocketProcessTopicBlockedList.Insert("network:socket-process-crashed"_ns);
|
||||
|
||||
// Register for profile change notifications
|
||||
mObserverService = services::GetObserverService();
|
||||
|
@ -333,12 +333,19 @@ nsIOService::AddObserver(nsIObserver* aObserver, const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString topic(aTopic);
|
||||
// This happens when AddObserver() is called by nsIOService::Init(). We don't
|
||||
// want to add nsIOService again.
|
||||
if (SameCOMIdentity(aObserver, static_cast<nsIObserver*>(this))) {
|
||||
mIOServiceTopicList.Insert(topic);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!UseSocketProcess()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString topic(aTopic);
|
||||
if (mSocketProcessTopicBlackList.Contains(topic)) {
|
||||
if (mSocketProcessTopicBlockedList.Contains(topic)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -349,10 +356,9 @@ nsIOService::AddObserver(nsIObserver* aObserver, const char* aTopic,
|
|||
|
||||
mObserverTopicForSocketProcess.Insert(topic);
|
||||
|
||||
// This happens when AddObserver() is called by nsIOService::Init(). We don't
|
||||
// want to add nsIOService again.
|
||||
if (SameCOMIdentity(aObserver, static_cast<nsIObserver*>(this))) {
|
||||
return NS_OK;
|
||||
// Avoid registering duplicate topics.
|
||||
if (mIOServiceTopicList.Contains(topic)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return mObserverService->AddObserver(this, aTopic, true);
|
||||
|
|
|
@ -261,7 +261,9 @@ class nsIOService final : public nsIIOService,
|
|||
nsTHashSet<nsCString> mObserverTopicForSocketProcess;
|
||||
// Some noticications (e.g., NS_XPCOM_SHUTDOWN_OBSERVER_ID) are triggered in
|
||||
// socket process, so we should not send the notifications again.
|
||||
nsTHashSet<nsCString> mSocketProcessTopicBlackList;
|
||||
nsTHashSet<nsCString> mSocketProcessTopicBlockedList;
|
||||
// Used to store the topics that are already observed by IOService.
|
||||
nsTHashSet<nsCString> mIOServiceTopicList;
|
||||
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче