Modified code to report caret offset and text selection in all editable text and...
[chromium-blink-merge.git] / chrome / utility / font_cache_handler_win.cc
blob6d3964a1c87983cee5de416164e13e98bde7c623
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) {
14 bool handled = true;
15 IPC_BEGIN_MESSAGE_MAP(FontCacheHandler, message)
16 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_BuildDirectWriteFontCache,
17 OnBuildFontCache)
18 IPC_MESSAGE_UNHANDLED(handled = false)
19 IPC_END_MESSAGE_MAP()
20 return handled;
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()) {
31 NOTREACHED();
32 return;
34 cache_thread_->message_loop()->PostTask(
35 FROM_HERE, base::Bind(&FontCacheHandler::StartBuildingFontCache,
36 base::Unretained(this),
37 full_path));
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();