Commit e229ed0f authored by shrikant's avatar shrikant Committed by Commit bot

Change for building font cache into separate thread inside utility process so...

Change for building font cache into separate thread inside utility process so that IO thread remains responsive.

BUG=458751, 436195
R=cpu,scottmg

Review URL: https://codereview.chromium.org/1011023002

Cr-Commit-Position: refs/heads/master@{#320983}
parent 7c9fe86c
......@@ -4,6 +4,8 @@
#include "chrome/utility/font_cache_handler_win.h"
#include "base/task_runner_util.h"
#include "base/threading/thread.h"
#include "chrome/common/chrome_utility_messages.h"
#include "content/public/common/dwrite_font_platform_win.h"
#include "content/public/utility/utility_thread.h"
......@@ -19,6 +21,30 @@ bool FontCacheHandler::OnMessageReceived(const IPC::Message& message) {
}
void FontCacheHandler::OnBuildFontCache(const base::FilePath& full_path) {
DCHECK(!cache_thread_);
utility_task_runner_ = base::MessageLoop::current()->message_loop_proxy();
// Create worker thread for building font cache.
cache_thread_.reset(new base::Thread("font_cache_thread"));
if (!cache_thread_->Start()) {
NOTREACHED();
return;
}
cache_thread_->message_loop()->PostTask(
FROM_HERE, base::Bind(&FontCacheHandler::StartBuildingFontCache,
base::Unretained(this),
full_path));
}
void FontCacheHandler::StartBuildingFontCache(const base::FilePath& full_path) {
content::BuildFontCache(full_path);
utility_task_runner_->PostTask(FROM_HERE,
base::Bind(&FontCacheHandler::Cleanup,
base::Unretained(this)));
}
void FontCacheHandler::Cleanup() {
cache_thread_.reset();
content::UtilityThread::Get()->ReleaseProcessIfNeeded();
}
......@@ -6,8 +6,15 @@
#define CHROME_UTILITY_FONT_CACHE_HANDLER_WIN_H_
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/utility/utility_message_handler.h"
namespace base {
class TaskRunner;
class Thread;
}
// Handles requests to build a static direct write font cache. Must be invoked
// in a non-sandboxed utility process. We build static font cache in utility
// process as it is time consuming as well as crash prone thing. We already
......@@ -24,6 +31,14 @@ class FontCacheHandler : public UtilityMessageHandler {
private:
void OnBuildFontCache(const base::FilePath& full_path);
void StartBuildingFontCache(const base::FilePath& full_path);
void Cleanup();
scoped_refptr<base::TaskRunner> utility_task_runner_;
// Thread that caching process runs on, while FontCacheHandler handles
// messages from the browser process.
scoped_ptr<base::Thread> cache_thread_;
DISALLOW_COPY_AND_ASSIGN(FontCacheHandler);
};
......
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