Commit 6819d6ad authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Capture whether an SkFontMgr for unit testing is created or not

On Windows, FontCache creates an SkFontMgr using
SkFontMgr_New_DirectWrite() if the font manager isn't explicitly
set, so that unit tests work.

To clarify the suspicious that this test code is running in the
production environment, this patch captures the information in
the minidump.

Bug: 561873
Change-Id: Ib60c9a569242a242c095180bffb0024fc03f129b
Reviewed-on: https://chromium-review.googlesource.com/895167
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533756}
parent ad1cb83d
......@@ -369,7 +369,11 @@ void FontCache::CrashWithFontInfo(const FontDescription* font_description) {
FontCache* font_cache = FontCache::GetFontCache();
SkFontMgr* font_mgr = nullptr;
int num_families = std::numeric_limits<int>::min();
bool is_test_font_mgr = false;
if (font_cache) {
#if defined(OS_WIN)
is_test_font_mgr = font_cache->is_test_font_mgr_;
#endif
font_mgr = font_cache->font_manager_.get();
if (font_mgr)
num_families = font_mgr->countFamilies();
......@@ -377,6 +381,7 @@ void FontCache::CrashWithFontInfo(const FontDescription* font_description) {
FontDescription font_description_copy = *font_description;
base::debug::Alias(&font_description_copy);
base::debug::Alias(&is_test_font_mgr);
base::debug::Alias(&num_families);
CHECK(false);
......
......@@ -321,6 +321,12 @@ class PLATFORM_EXPORT FontCache {
FallbackListShaperCache fallback_list_shaper_cache_;
FontDataCache font_data_cache_;
#if defined(OS_WIN)
// Windows creates an SkFontMgr for unit testing automatically. This flag is
// to ensure it's not happening in the production from the crash log.
bool is_test_font_mgr_ = false;
#endif
void PurgePlatformFontDataCache();
void PurgeFallbackListShaperCache();
......
......@@ -103,8 +103,15 @@ void FontCache::SetStatusFontMetrics(const wchar_t* family_name,
FontCache::FontCache() : purge_prevent_count_(0) {
font_manager_ = sk_ref_sp(static_font_manager_);
if (!font_manager_)
if (!font_manager_) {
// This code path is only for unit tests. This SkFontMgr does not work in
// sandboxed environments, but injecting this initialization code to all
// unit tests isn't easy.
font_manager_ = SkFontMgr_New_DirectWrite();
// Set |is_test_font_mgr_| to capture if this is not happening in the
// production code. crbug.com/561873
is_test_font_mgr_ = true;
}
DCHECK(font_manager_.get());
}
......
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