From a1ff54a54f03fc51819796082430c278db458814 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 Mar 2020 18:25:08 +0000 Subject: [PATCH] Bug 1607356 - Move OTS sanitization to background thread. r=KrisWright Differential Revision: https://phabricator.services.mozilla.com/D65267 --HG-- extra : moz-landing-system : lando --- gfx/thebes/gfxUserFontSet.cpp | 20 +++++--------------- gfx/thebes/gfxUserFontSet.h | 8 ++------ layout/build/nsLayoutStatics.cpp | 2 -- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 0e8945ab1ec1..b752ac6b2054 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -705,11 +705,10 @@ bool gfxUserFontEntry::LoadPlatformFontSync(const uint8_t* aFontData, std::move(messages)); } -void gfxUserFontEntry::StartPlatformFontLoadOnWorkerThread( +void gfxUserFontEntry::StartPlatformFontLoadOnBackgroundThread( const uint8_t* aFontData, uint32_t aLength, nsMainThreadPtrHandle aCallback) { - MOZ_ASSERT(sFontLoadingThread); - MOZ_ASSERT(sFontLoadingThread->IsOnCurrentThread()); + MOZ_ASSERT(!NS_IsMainThread()); uint32_t saneLen; gfxUserFontType fontType; @@ -921,12 +920,6 @@ void gfxUserFontEntry::FontDataDownloadComplete( void gfxUserFontEntry::LoadPlatformFontAsync( const uint8_t* aFontData, uint32_t aLength, nsIFontLoadCompleteCallback* aCallback) { - // Ensure the font loading thread is available. - if (!sFontLoadingThread) { - sFontLoadingThread = - new LazyIdleThread(5000, NS_LITERAL_CSTRING("FontLoader")); - } - nsMainThreadPtrHandle cb( new nsMainThreadPtrHolder("FontLoader", aCallback)); @@ -943,11 +936,10 @@ void gfxUserFontEntry::LoadPlatformFontAsync( nsCOMPtr event = NewRunnableMethod>( - "gfxUserFontEntry::StartPlatformFontLoadOnWorkerThread", this, - &gfxUserFontEntry::StartPlatformFontLoadOnWorkerThread, aFontData, + "gfxUserFontEntry::StartPlatformFontLoadOnBackgroundThread", this, + &gfxUserFontEntry::StartPlatformFontLoadOnBackgroundThread, aFontData, aLength, cb); - MOZ_ALWAYS_SUCCEEDS( - sFontLoadingThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL)); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchBackgroundTask(event.forget())); } void gfxUserFontEntry::ContinuePlatformFontLoadOnMainThread( @@ -1424,8 +1416,6 @@ gfxUserFontSet::UserFontCache::MemoryReporter::CollectReports( return NS_OK; } -StaticRefPtr gfxUserFontEntry::sFontLoadingThread; - #ifdef DEBUG_USERFONT_CACHE void gfxUserFontSet::UserFontCache::Entry::Dump() { diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 02f528bc476c..95c5bae5a2d2 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -641,8 +641,6 @@ class gfxUserFontEntry : public gfxFontEntry { MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder"); } - static void Shutdown() { sFontLoadingThread = nullptr; } - protected: struct OTSMessage { nsCString mMessage; @@ -679,8 +677,8 @@ class gfxUserFontEntry : public gfxFontEntry { void LoadPlatformFontAsync(const uint8_t* aFontData, uint32_t aLength, nsIFontLoadCompleteCallback* aCallback); - // helper method for LoadPlatformFontAsync; runs on the FontLoader thread - void StartPlatformFontLoadOnWorkerThread( + // helper method for LoadPlatformFontAsync; runs on a background thread + void StartPlatformFontLoadOnBackgroundThread( const uint8_t* aFontData, uint32_t aLength, nsMainThreadPtrHandle aCallback); @@ -749,8 +747,6 @@ class gfxUserFontEntry : public gfxFontEntry { gfxUserFontSet* MOZ_NON_OWNING_REF mFontSet; // font-set which owns this userfont entry RefPtr mPrincipal; - - static mozilla::StaticRefPtr sFontLoadingThread; }; #endif /* GFX_USER_FONT_SET_H */ diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index db0ecd45f9bd..ae7d196ec06f 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -416,6 +416,4 @@ void nsLayoutStatics::Shutdown() { css::ImageLoader::Shutdown(); mozilla::net::UrlClassifierFeatureFactory::Shutdown(); - - gfxUserFontEntry::Shutdown(); }