1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/utility/font_cache_handler_win.h"
7 #include "base/task_runner_util.h"
8 #include "base/threading/thread.h"
9 #include "chrome/common/chrome_utility_messages.h"
10 #include "content/public/common/dwrite_font_platform_win.h"
11 #include "content/public/utility/utility_thread.h"
13 bool FontCacheHandler::OnMessageReceived(const IPC::Message
& message
) {
15 IPC_BEGIN_MESSAGE_MAP(FontCacheHandler
, message
)
16 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_BuildDirectWriteFontCache
,
18 IPC_MESSAGE_UNHANDLED(handled
= false)
23 void FontCacheHandler::OnBuildFontCache(const base::FilePath
& full_path
) {
24 DCHECK(!cache_thread_
);
26 utility_task_runner_
= base::MessageLoop::current()->message_loop_proxy();
28 // Create worker thread for building font cache.
29 cache_thread_
.reset(new base::Thread("font_cache_thread"));
30 if (!cache_thread_
->Start()) {
34 cache_thread_
->message_loop()->PostTask(
35 FROM_HERE
, base::Bind(&FontCacheHandler::StartBuildingFontCache
,
36 base::Unretained(this),
40 void FontCacheHandler::StartBuildingFontCache(const base::FilePath
& full_path
) {
41 content::BuildFontCache(full_path
);
42 utility_task_runner_
->PostTask(FROM_HERE
,
43 base::Bind(&FontCacheHandler::Cleanup
,
44 base::Unretained(this)));
47 void FontCacheHandler::Cleanup() {
48 cache_thread_
.reset();
49 content::UtilityThread::Get()->ReleaseProcessIfNeeded();