OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/utility/font_cache_handler_win.h" | |
6 | |
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" | |
12 | |
13 FontCacheHandler::FontCacheHandler() { | |
14 } | |
15 | |
16 FontCacheHandler::~FontCacheHandler() { | |
17 } | |
18 | |
19 bool FontCacheHandler::OnMessageReceived(const IPC::Message& message) { | |
20 bool handled = true; | |
21 IPC_BEGIN_MESSAGE_MAP(FontCacheHandler, message) | |
22 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_BuildDirectWriteFontCache, | |
23 OnBuildFontCache) | |
24 IPC_MESSAGE_UNHANDLED(handled = false) | |
25 IPC_END_MESSAGE_MAP() | |
26 return handled; | |
27 } | |
28 | |
29 void FontCacheHandler::OnBuildFontCache(const base::FilePath& full_path) { | |
30 DCHECK(!cache_thread_); | |
31 | |
32 utility_task_runner_ = base::MessageLoop::current()->task_runner(); | |
33 | |
34 // Create worker thread for building font cache. | |
35 cache_thread_.reset(new base::Thread("font_cache_thread")); | |
36 if (!cache_thread_->Start()) { | |
37 NOTREACHED(); | |
38 return; | |
39 } | |
40 cache_thread_->message_loop()->PostTask( | |
41 FROM_HERE, base::Bind(&FontCacheHandler::StartBuildingFontCache, | |
42 base::Unretained(this), | |
43 full_path)); | |
44 } | |
45 | |
46 void FontCacheHandler::StartBuildingFontCache(const base::FilePath& full_path) { | |
47 content::BuildFontCache(full_path); | |
48 utility_task_runner_->PostTask(FROM_HERE, | |
49 base::Bind(&FontCacheHandler::Cleanup, | |
50 base::Unretained(this))); | |
51 } | |
52 | |
53 void FontCacheHandler::Cleanup() { | |
54 cache_thread_.reset(); | |
55 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
56 } | |
OLD | NEW |