Bug 1473631: Part 9 - Replace pref observers with callbacks in gfxPlatformFontList. r?njn draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 05 Jul 2018 14:47:39 -0700
changeset 818481 44aa2241ae5f3f45a34dc41308720d1c0a5a5ff3
parent 818480 cf171797dc1d388443e64d28a3495911496b0ae3
child 818482 4b186852a9ec326bc86a1f658ee7c2abca8c10ba
push id116269
push usermaglione.k@gmail.com
push dateSat, 14 Jul 2018 02:18:47 +0000
reviewersnjn
bugs1473631
milestone63.0a1
Bug 1473631: Part 9 - Replace pref observers with callbacks in gfxPlatformFontList. r?njn MozReview-Commit-ID: AT8BmGNj6QD
gfx/thebes/gfxPlatformFontList.cpp
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -121,34 +121,40 @@ static_assert(MOZ_ARRAY_LENGTH(gPrefLang
 
 class gfxFontListPrefObserver final : public nsIObserver {
     ~gfxFontListPrefObserver() {}
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
+static void
+FontListPrefChanged(const char* aPref, void* aData = nullptr)
+{
+    // XXX this could be made to only clear out the cache for the prefs that were changed
+    // but it probably isn't that big a deal.
+    gfxPlatformFontList::PlatformFontList()->ClearLangGroupPrefFonts();
+    gfxFontCache::GetCache()->AgeAllGenerations();
+}
+
 static gfxFontListPrefObserver* gFontListPrefObserver = nullptr;
 
 NS_IMPL_ISUPPORTS(gfxFontListPrefObserver, nsIObserver)
 
 #define LOCALES_CHANGED_TOPIC "intl:system-locales-changed"
 
 NS_IMETHODIMP
 gfxFontListPrefObserver::Observe(nsISupports     *aSubject,
                                  const char      *aTopic,
                                  const char16_t *aData)
 {
-    NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) ||
-                 !strcmp(aTopic, LOCALES_CHANGED_TOPIC), "invalid topic");
-    // XXX this could be made to only clear out the cache for the prefs that were changed
-    // but it probably isn't that big a deal.
-    gfxPlatformFontList::PlatformFontList()->ClearLangGroupPrefFonts();
-    gfxFontCache::GetCache()->AgeAllGenerations();
-    if (XRE_IsParentProcess() && !strcmp(aTopic, LOCALES_CHANGED_TOPIC)) {
+    NS_ASSERTION(!strcmp(aTopic, LOCALES_CHANGED_TOPIC), "invalid topic");
+    FontListPrefChanged(nullptr);
+
+    if (XRE_IsParentProcess()) {
         gfxPlatform::ForceGlobalReflow();
     }
     return NS_OK;
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(FontListMallocSizeOf)
 
 NS_IMPL_ISUPPORTS(gfxPlatformFontList::MemoryReporter, nsIMemoryReporter)
@@ -210,17 +216,18 @@ gfxPlatformFontList::gfxPlatformFontList
 
     LoadBadUnderlineList();
 
     // pref changes notification setup
     NS_ASSERTION(!gFontListPrefObserver,
                  "There has been font list pref observer already");
     gFontListPrefObserver = new gfxFontListPrefObserver();
     NS_ADDREF(gFontListPrefObserver);
-    Preferences::AddStrongObservers(gFontListPrefObserver, kObservedPrefs);
+
+    Preferences::RegisterPrefixCallbacks(FontListPrefChanged, kObservedPrefs);
 
     nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
     if (obs) {
         obs->AddObserver(gFontListPrefObserver, LOCALES_CHANGED_TOPIC, false);
     }
 
     // Only the parent process listens for whitelist changes; it will then
     // notify its children to rebuild their font lists.
@@ -232,17 +239,18 @@ gfxPlatformFontList::gfxPlatformFontList
     RegisterStrongMemoryReporter(new MemoryReporter());
 }
 
 gfxPlatformFontList::~gfxPlatformFontList()
 {
     mSharedCmaps.Clear();
     ClearLangGroupPrefFonts();
     NS_ASSERTION(gFontListPrefObserver, "There is no font list pref observer");
-    Preferences::RemoveObservers(gFontListPrefObserver, kObservedPrefs);
+
+    Preferences::UnregisterPrefixCallbacks(FontListPrefChanged, kObservedPrefs);
 
     nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
     if (obs) {
         obs->RemoveObserver(gFontListPrefObserver, LOCALES_CHANGED_TOPIC);
     }
 
     if (XRE_IsParentProcess()) {
         Preferences::UnregisterCallback(FontWhitelistPrefChanged,