Bug 1277405: Clear Places observers at XPCOM shutdown. r?mak
MozReview-Commit-ID: 6JYMX7TXDLZ
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -2517,16 +2517,20 @@ nsNavBookmarks::RunInBatchMode(nsINavHis
}
NS_IMETHODIMP
nsNavBookmarks::AddObserver(nsINavBookmarkObserver* aObserver,
bool aOwnsWeak)
{
NS_ENSURE_ARG(aObserver);
+
+ if (NS_WARN_IF(!mCanNotify))
+ return NS_ERROR_UNEXPECTED;
+
return mObservers.AppendWeakElement(aObserver, aOwnsWeak);
}
NS_IMETHODIMP
nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver)
{
return mObservers.RemoveWeakElement(aObserver);
@@ -2629,16 +2633,17 @@ nsNavBookmarks::Observe(nsISupports *aSu
if (annosvc) {
annosvc->RemoveObserver(this);
}
}
else if (strcmp(aTopic, TOPIC_PLACES_CONNECTION_CLOSED) == 0) {
// Don't even try to notify observers from this point on, the category
// cache would init services that could try to use our APIs.
mCanNotify = false;
+ mObservers.Clear();
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
//// nsINavHistoryObserver
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -2245,16 +2245,19 @@ nsNavHistory::GetQueryResults(nsNavHisto
}
NS_IMETHODIMP
nsNavHistory::AddObserver(nsINavHistoryObserver* aObserver, bool aOwnsWeak)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aObserver);
+ if (NS_WARN_IF(!mCanNotify))
+ return NS_ERROR_UNEXPECTED;
+
return mObservers.AppendWeakElement(aObserver, aOwnsWeak);
}
NS_IMETHODIMP
nsNavHistory::RemoveObserver(nsINavHistoryObserver* aObserver)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aObserver);
@@ -3082,19 +3085,20 @@ nsNavHistory::Observe(nsISupports *aSubj
strcmp(aTopic, TOPIC_PROFILE_CHANGE) == 0 ||
strcmp(aTopic, TOPIC_SIMULATE_PLACES_SHUTDOWN) == 0) {
// These notifications are used by tests to simulate a Places shutdown.
// They should just be forwarded to the Database handle.
mDB->Observe(aSubject, aTopic, aData);
}
else if (strcmp(aTopic, TOPIC_PLACES_CONNECTION_CLOSED) == 0) {
- // Don't even try to notify observers from this point on, the category
- // cache would init services that could try to use our APIs.
- mCanNotify = false;
+ // Don't even try to notify observers from this point on, the category
+ // cache would init services that could try to use our APIs.
+ mCanNotify = false;
+ mObservers.Clear();
}
#ifdef MOZ_XUL
else if (strcmp(aTopic, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING) == 0) {
nsCOMPtr<nsIAutoCompleteInput> input = do_QueryInterface(aSubject);
if (!input)
return NS_OK;