Windows: Add DirectWrite font cache support (issue #1652)

This commit is contained in:
Marshall Greenblatt
2015-06-11 18:08:33 -04:00
parent de05577c86
commit ee90dc0915
11 changed files with 93 additions and 34 deletions

View File

@@ -9,6 +9,28 @@
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_main.h"
#include "chrome/common/chrome_utility_messages.h"
#include "content/public/browser/utility_process_host.h"
#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/dwrite_font_platform_win.h"
#include "grit/cef_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/win/direct_write.h"
namespace {
void ExecuteFontCacheBuildTask(const base::FilePath& path) {
base::WeakPtr<content::UtilityProcessHost> utility_process_host(
content::UtilityProcessHost::Create(NULL, NULL)->AsWeakPtr());
utility_process_host->SetName(l10n_util::GetStringUTF16(
IDS_UTILITY_PROCESS_FONT_CACHE_BUILDER_NAME));
utility_process_host->DisableSandbox();
utility_process_host->Send(
new ChromeUtilityHostMsg_BuildDirectWriteFontCache(path));
}
} // namespace
void CefBrowserMainParts::PlatformInitialize() {
HRESULT res;
@@ -28,5 +50,38 @@ void CefBrowserMainParts::PlatformInitialize() {
CefBrowserHostImpl::RegisterWindowClass();
}
void CefBrowserMainParts::PlatformCleanup() {
void CefBrowserMainParts::PlatformPreMainMessageLoopRun() {
// From ChromeBrowserMainPartsWin::PostProfileInit().
// DirectWrite support is mainly available on Windows 7 and up.
if (gfx::win::ShouldUseDirectWrite()) {
const base::FilePath& cache_path = global_browser_context_->GetPath();
if (cache_path.empty())
return;
const base::FilePath& font_cache_path =
cache_path.AppendASCII(content::kFontCacheSharedSectionName);
// This function will create a read only section if cache file exists
// otherwise it will spawn utility process to build cache file, which will
// be used during next browser start/postprofileinit.
if (!content::LoadFontCache(font_cache_path)) {
// We delay building of font cache until first startup page loads.
// During first renderer start there are lot of things happening
// simultaneously some of them are:
// - Renderer is going through all font files on the system to create
// a font collection.
// - Renderer loading up startup URL, accessing HTML/JS File cache,
// net activity etc.
// - Extension initialization.
// We delay building of cache mainly to avoid parallel font file
// loading along with Renderer. Some systems have significant number of
// font files which takes long time to process.
// Related information is at http://crbug.com/436195.
const int kBuildFontCacheDelaySec = 30;
content::BrowserThread::PostDelayedTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(ExecuteFontCacheBuildTask, font_cache_path),
base::TimeDelta::FromSeconds(kBuildFontCacheDelaySec));
}
}
}