Commit 9aa85d8b authored by Ben Wagner's avatar Ben Wagner Committed by Commit Bot

Avoid creating FontCache for memory dump.

It is possible that a memory dump will be requested before the blink
font manager is set. This can result in attempting to create a fallback
font manager and ignoring the real one which may be set later. Avoid
this situation by ensuring that the memory dump request does not
implicitly cause a global FontCache to be created just to dump that it
is empty.

Bug: chromium:1140954
Cq-Include-Trybots: luci.chromium.try:win_chromium_dbg_ng
Change-Id: If29d830c66f85552663384898fbf3d29fb6d67e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490503
Commit-Queue: Ben Wagner <bungeman@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819842}
parent 12218a16
...@@ -90,8 +90,8 @@ bool FontCache::lcd_text_enabled_ = false; ...@@ -90,8 +90,8 @@ bool FontCache::lcd_text_enabled_ = false;
bool FontCache::use_skia_font_fallback_ = false; bool FontCache::use_skia_font_fallback_ = false;
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
FontCache* FontCache::GetFontCache() { FontCache* FontCache::GetFontCache(CreateIfNeeded create) {
return &FontGlobalContext::GetFontCache(); return FontGlobalContext::GetFontCache(create);
} }
FontCache::FontCache() FontCache::FontCache()
......
...@@ -91,6 +91,8 @@ enum class AlternateFontName { ...@@ -91,6 +91,8 @@ enum class AlternateFontName {
kLastResort kLastResort
}; };
enum CreateIfNeeded { kDoNotCreate, kCreate };
typedef HashMap<unsigned, typedef HashMap<unsigned,
std::unique_ptr<FontPlatformData>, std::unique_ptr<FontPlatformData>,
WTF::IntHash<unsigned>, WTF::IntHash<unsigned>,
...@@ -113,7 +115,11 @@ class PLATFORM_EXPORT FontCache { ...@@ -113,7 +115,11 @@ class PLATFORM_EXPORT FontCache {
USING_FAST_MALLOC(FontCache); USING_FAST_MALLOC(FontCache);
public: public:
static FontCache* GetFontCache(); // FontCache initialisation on Windows depends on a global FontMgr being
// configured through a call from the browser process. CreateIfNeeded helps
// avoid early creation of a font cache when these globals have not yet
// been set.
static FontCache* GetFontCache(CreateIfNeeded = kCreate);
void ReleaseFontData(const SimpleFontData*); void ReleaseFontData(const SimpleFontData*);
......
...@@ -18,8 +18,11 @@ bool FontCacheMemoryDumpProvider::OnMemoryDump( ...@@ -18,8 +18,11 @@ bool FontCacheMemoryDumpProvider::OnMemoryDump(
const base::trace_event::MemoryDumpArgs&, const base::trace_event::MemoryDumpArgs&,
base::trace_event::ProcessMemoryDump* memory_dump) { base::trace_event::ProcessMemoryDump* memory_dump) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
FontCache::GetFontCache()->DumpFontPlatformDataCache(memory_dump); FontCache* cache = FontCache::GetFontCache(kDoNotCreate);
FontCache::GetFontCache()->DumpShapeResultCache(memory_dump); if (cache) {
cache->DumpFontPlatformDataCache(memory_dump);
cache->DumpShapeResultCache(memory_dump);
}
return true; return true;
} }
......
...@@ -90,12 +90,13 @@ IdentifiableToken FontGlobalContext::GetOrComputePostScriptNameDigest( ...@@ -90,12 +90,13 @@ IdentifiableToken FontGlobalContext::GetOrComputePostScriptNameDigest(
} }
void FontGlobalContext::ClearMemory() { void FontGlobalContext::ClearMemory() {
if (!Get(kDoNotCreate)) FontGlobalContext* context = Get(kDoNotCreate);
if (!context)
return; return;
GetFontCache().Invalidate(); context->font_cache_.Invalidate();
Get()->typeface_digest_cache_.Clear(); context->typeface_digest_cache_.Clear();
Get()->postscript_name_digest_cache_.Clear(); context->postscript_name_digest_cache_.Clear();
} }
} // namespace blink } // namespace blink
...@@ -21,8 +21,6 @@ class FontCache; ...@@ -21,8 +21,6 @@ class FontCache;
class FontUniqueNameLookup; class FontUniqueNameLookup;
class HarfBuzzFontCache; class HarfBuzzFontCache;
enum CreateIfNeeded { kDoNotCreate, kCreate };
// FontGlobalContext contains non-thread-safe, thread-specific data used for // FontGlobalContext contains non-thread-safe, thread-specific data used for
// font formatting. // font formatting.
class PLATFORM_EXPORT FontGlobalContext { class PLATFORM_EXPORT FontGlobalContext {
...@@ -31,7 +29,10 @@ class PLATFORM_EXPORT FontGlobalContext { ...@@ -31,7 +29,10 @@ class PLATFORM_EXPORT FontGlobalContext {
public: public:
static FontGlobalContext* Get(CreateIfNeeded = kCreate); static FontGlobalContext* Get(CreateIfNeeded = kCreate);
static inline FontCache& GetFontCache() { return Get()->font_cache_; } static inline FontCache* GetFontCache(CreateIfNeeded create = kCreate) {
FontGlobalContext* context = Get(create);
return context ? &context->font_cache_ : nullptr;
}
static HarfBuzzFontCache* GetHarfBuzzFontCache(); static HarfBuzzFontCache* GetHarfBuzzFontCache();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment