2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-02-22 17:07:21 +03:00
|
|
|
|
|
|
|
#include "nsIObserverService.h"
|
2011-12-09 23:36:17 +04:00
|
|
|
#include "mozilla/Services.h"
|
2018-08-25 08:22:07 +03:00
|
|
|
#include "mozilla/SimpleEnumerator.h"
|
Bug 1600545 - Remove useless inclusions of header files generated from IDL files in modules/, netwerk/, parser/, security/, startupcache/, storage/, toolkit/, tools/, uriloader/, widget/, xpcom/ and xpfe/ r=Ehsan
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55444
--HG--
extra : moz-landing-system : lando
2019-12-06 12:17:57 +03:00
|
|
|
|
|
|
|
#include "nsICategoryManager.h"
|
2006-02-22 17:07:21 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
|
|
|
|
#include "nsXPCOMCID.h"
|
|
|
|
|
|
|
|
#include "nsCategoryCache.h"
|
|
|
|
|
2018-08-25 08:22:07 +03:00
|
|
|
using mozilla::SimpleEnumerator;
|
|
|
|
|
2018-07-24 03:41:06 +03:00
|
|
|
nsCategoryObserver::nsCategoryObserver(const nsACString& aCategory)
|
2013-10-10 16:48:03 +04:00
|
|
|
: mCategory(aCategory),
|
2017-05-07 05:55:00 +03:00
|
|
|
mCallback(nullptr),
|
|
|
|
mClosure(nullptr),
|
2013-10-10 16:48:03 +04:00
|
|
|
mObserversRemoved(false) {
|
2017-05-07 05:55:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2006-02-22 17:07:21 +03:00
|
|
|
// First, enumerate the currently existing entries
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!catMan) {
|
2006-02-22 17:07:21 +03:00
|
|
|
return;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
|
|
|
nsresult rv =
|
|
|
|
catMan->EnumerateCategory(aCategory, getter_AddRefs(enumerator));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2006-02-22 17:07:21 +03:00
|
|
|
return;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2018-08-25 08:22:07 +03:00
|
|
|
for (auto& categoryEntry : SimpleEnumerator<nsICategoryEntry>(enumerator)) {
|
|
|
|
nsAutoCString entryValue;
|
|
|
|
categoryEntry->GetValue(entryValue);
|
|
|
|
|
|
|
|
if (nsCOMPtr<nsISupports> service = do_GetService(entryValue.get())) {
|
|
|
|
nsAutoCString entryName;
|
|
|
|
categoryEntry->GetEntry(entryName);
|
|
|
|
|
|
|
|
mHash.Put(entryName, service);
|
2006-02-22 17:07:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, listen for changes
|
2011-12-09 23:36:17 +04:00
|
|
|
nsCOMPtr<nsIObserverService> serv = mozilla::services::GetObserverService();
|
2009-11-19 18:51:00 +03:00
|
|
|
if (serv) {
|
2011-10-17 18:59:28 +04:00
|
|
|
serv->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID, false);
|
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID, false);
|
|
|
|
serv->AddObserver(this, NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID, false);
|
2009-11-19 18:51:00 +03:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
}
|
|
|
|
|
2016-11-16 15:25:31 +03:00
|
|
|
nsCategoryObserver::~nsCategoryObserver() = default;
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsCategoryObserver, nsIObserver)
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
void nsCategoryObserver::ListenerDied() {
|
2017-05-07 05:55:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-11-19 16:15:05 +03:00
|
|
|
RemoveObservers();
|
2017-05-07 05:55:00 +03:00
|
|
|
mCallback = nullptr;
|
|
|
|
mClosure = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCategoryObserver::SetListener(void(aCallback)(void*), void* aClosure) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mCallback = aCallback;
|
|
|
|
mClosure = aClosure;
|
2009-11-19 16:15:05 +03:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
void nsCategoryObserver::RemoveObservers() {
|
2017-05-07 05:55:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
if (mObserversRemoved) {
|
2010-09-08 02:22:00 +04:00
|
|
|
return;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2010-09-08 02:22:00 +04:00
|
|
|
|
2017-05-07 05:55:00 +03:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback(mClosure);
|
|
|
|
}
|
|
|
|
|
2010-09-08 02:22:00 +04:00
|
|
|
mObserversRemoved = true;
|
2011-12-09 23:36:17 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
2009-11-19 16:15:05 +03:00
|
|
|
if (obsSvc) {
|
|
|
|
obsSvc->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
obsSvc->RemoveObserver(this, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID);
|
|
|
|
obsSvc->RemoveObserver(this, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID);
|
|
|
|
obsSvc->RemoveObserver(this, NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID);
|
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCategoryObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-06-27 05:35:39 +04:00
|
|
|
const char16_t* aData) {
|
2017-05-07 05:55:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
mHash.Clear();
|
2009-11-19 16:15:05 +03:00
|
|
|
RemoveObservers();
|
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-26 17:53:48 +04:00
|
|
|
if (!aData ||
|
2014-06-27 05:35:39 +04:00
|
|
|
!nsDependentString(aData).Equals(NS_ConvertASCIItoUTF16(mCategory))) {
|
2006-02-22 17:07:21 +03:00
|
|
|
return NS_OK;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2006-02-22 17:07:21 +03:00
|
|
|
nsCOMPtr<nsISupportsCString> strWrapper(do_QueryInterface(aSubject));
|
2014-06-27 05:35:39 +04:00
|
|
|
if (strWrapper) {
|
2006-02-22 17:07:21 +03:00
|
|
|
strWrapper->GetData(str);
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
|
|
|
if (strcmp(aTopic, NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID) == 0) {
|
2009-11-26 00:50:01 +03:00
|
|
|
// We may get an add notification even when we already have an entry. This
|
|
|
|
// is due to the notification happening asynchronously, so if the entry gets
|
|
|
|
// added and an nsCategoryObserver gets instantiated before events get
|
|
|
|
// processed, we'd get the notification for an existing entry.
|
|
|
|
// Do nothing in that case.
|
2014-06-27 05:35:39 +04:00
|
|
|
if (mHash.GetWeak(str)) {
|
2009-11-26 00:50:01 +03:00
|
|
|
return NS_OK;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2009-11-26 00:50:01 +03:00
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
2014-06-27 05:35:39 +04:00
|
|
|
if (!catMan) {
|
2006-02-22 17:07:21 +03:00
|
|
|
return NS_OK;
|
2014-06-27 05:35:39 +04:00
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2007-04-26 17:53:48 +04:00
|
|
|
nsCString entryValue;
|
2018-07-24 03:41:06 +03:00
|
|
|
catMan->GetCategoryEntry(mCategory, str, entryValue);
|
2006-02-22 17:07:21 +03:00
|
|
|
|
2013-10-10 16:48:03 +04:00
|
|
|
nsCOMPtr<nsISupports> service = do_GetService(entryValue.get());
|
|
|
|
|
|
|
|
if (service) {
|
|
|
|
mHash.Put(str, service);
|
2006-02-22 17:07:21 +03:00
|
|
|
}
|
2017-05-07 05:55:00 +03:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback(mClosure);
|
|
|
|
}
|
2013-10-10 16:48:03 +04:00
|
|
|
} else if (strcmp(aTopic, NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID) == 0) {
|
|
|
|
mHash.Remove(str);
|
2017-05-07 05:55:00 +03:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback(mClosure);
|
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
} else if (strcmp(aTopic, NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID) == 0) {
|
|
|
|
mHash.Clear();
|
2017-05-07 05:55:00 +03:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback(mClosure);
|
|
|
|
}
|
2006-02-22 17:07:21 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|