Bug 1500026 - Make the fallback encoding object listen to locale changes r=jfkthame
authorGabriele Svelto <gsvelto@mozilla.com>
Thu, 22 Nov 2018 12:30:13 +0000
changeset 504120 1b9f8a4d684b76ef30a20811f1bdb7e6fd49d27f
parent 504119 91f749609e5dd544cc02924a1b56436af137cfa0
child 504121 3b2a596516fc3df3e464c9431ebbfb83232965de
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1500026
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1500026 - Make the fallback encoding object listen to locale changes r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D9894
dom/encoding/FallbackEncoding.cpp
dom/encoding/FallbackEncoding.h
--- a/dom/encoding/FallbackEncoding.cpp
+++ b/dom/encoding/FallbackEncoding.cpp
@@ -49,17 +49,17 @@ static const EncodingProp domainsFallbac
 };
 
 static constexpr nsUConvProp nonParticipatingDomains[] = {
 #include "nonparticipatingdomains.properties.h"
 };
 
 NS_IMPL_ISUPPORTS(FallbackEncoding, nsIObserver)
 
-FallbackEncoding* FallbackEncoding::sInstance = nullptr;
+StaticRefPtr<FallbackEncoding> FallbackEncoding::sInstance;
 bool FallbackEncoding::sGuessFallbackFromTopLevelDomain = true;
 bool FallbackEncoding::sFallbackToUTF8ForFile = false;
 
 FallbackEncoding::FallbackEncoding()
   : mFallback(nullptr)
 {
   MOZ_ASSERT(!FallbackEncoding::sInstance,
              "Singleton already exists.");
@@ -169,17 +169,16 @@ void
 FallbackEncoding::Shutdown()
 {
   MOZ_ASSERT(FallbackEncoding::sInstance,
              "Releasing non-existent fallback cache.");
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (obs) {
     obs->RemoveObserver(sInstance, "intl:requested-locales-changed");
   }
-  delete FallbackEncoding::sInstance;
   FallbackEncoding::sInstance = nullptr;
 }
 
 bool
 FallbackEncoding::IsParticipatingTopLevelDomain(const nsACString& aTLD)
 {
   nsAutoCString dummy;
   return NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
--- a/dom/encoding/FallbackEncoding.h
+++ b/dom/encoding/FallbackEncoding.h
@@ -3,24 +3,27 @@
 /* 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/. */
 
 #ifndef mozilla_dom_FallbackEncoding_h_
 #define mozilla_dom_FallbackEncoding_h_
 
 #include "mozilla/NotNull.h"
+#include "mozilla/StaticPtr.h"
 #include "nsIObserver.h"
 #include "nsString.h"
+#include "nsWeakReference.h"
 
 namespace mozilla {
 class Encoding;
 namespace dom {
 
 class FallbackEncoding : public nsIObserver
+                       , nsSupportsWeakReference
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   /**
    * Whether FromTopLevelDomain() should be used.
    */
@@ -70,17 +73,17 @@ public:
    */
   static void Shutdown();
 
 private:
 
   /**
    * The fallback cache.
    */
-  static FallbackEncoding* sInstance;
+  static StaticRefPtr<FallbackEncoding> sInstance;
 
   FallbackEncoding();
   virtual ~FallbackEncoding() {};
 
   /**
    * Invalidates the cache.
    */
   void Invalidate()