Commit 93fb7fb9 authored by Kris Maglione's avatar Kris Maglione
Browse files

Bug 1398357: Part 1 - Fix removal of LocaleService preference observers. r=gandalf

By the time the LocaleService destructor is called, by definition sInstance
has been cleared and its preference observers have been removed, since both
are strong references. In practice, this doesn't seem to cause trouble, but it
does lead to worrying warnings at shutdown in debug builds, which are annoying
red herrings when debugging other issues.

MozReview-Commit-ID: IalOigr2GWN

--HG--
extra : rebase_source : f86a8e81b91c639dedaca85e5bc3b53d54e01645
extra : histedit_source : 643b76de0d29ca4890ac4dd4175259989a63688e
parent 105f384e
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ static const char* kObservedPrefs[] = {
using namespace mozilla::intl;
using namespace mozilla;

NS_IMPL_ISUPPORTS(LocaleService, mozILocaleService, nsIObserver)
NS_IMPL_ISUPPORTS(LocaleService, mozILocaleService, nsIObserver,
                  nsISupportsWeakReference)

mozilla::StaticRefPtr<LocaleService> LocaleService::sInstance;

@@ -182,7 +183,7 @@ LocaleService::GetInstance()
    if (sInstance->IsServer()) {
      // We're going to observe for requested languages changes which come
      // from prefs.
      DebugOnly<nsresult> rv = Preferences::AddStrongObservers(sInstance, kObservedPrefs);
      DebugOnly<nsresult> rv = Preferences::AddWeakObservers(sInstance, kObservedPrefs);
      MOZ_ASSERT(NS_SUCCEEDED(rv), "Adding observers failed.");
    }
    ClearOnShutdown(&sInstance);
@@ -193,7 +194,7 @@ LocaleService::GetInstance()
LocaleService::~LocaleService()
{
  if (mIsServer) {
    Preferences::RemoveObservers(sInstance, kObservedPrefs);
    Preferences::RemoveObservers(this, kObservedPrefs);
  }
}

+3 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include "nsIObserver.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsWeakReference.h"

#include "mozILocaleService.h"

@@ -68,7 +69,8 @@ namespace intl {
 * but we negotiate between languages etc.
 */
class LocaleService : public mozILocaleService,
                      public nsIObserver
                      public nsIObserver,
                      public nsSupportsWeakReference
{
public:
  NS_DECL_ISUPPORTS