This source file includes following definitions.
- ConvertVector
- single_process_
- Shutdown
- Send
- ReleaseProcessIfNeeded
- PreCacheFont
- ReleaseCachedFonts
- Init
- OnControlMessageReceived
- OnBatchModeStarted
- OnBatchModeFinished
- OnLoadPlugins
#include "content/utility/utility_thread_impl.h"
#include <stddef.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_vector.h"
#include "content/child/blink_platform_impl.h"
#include "content/child/child_process.h"
#include "content/common/child_process_messages.h"
#include "content/common/plugin_list.h"
#include "content/common/utility_messages.h"
#include "content/public/common/content_switches.h"
#include "content/public/utility/content_utility_client.h"
#include "ipc/ipc_sync_channel.h"
#include "third_party/WebKit/public/web/WebKit.h"
namespace content {
namespace {
template<typename SRC, typename DEST>
void ConvertVector(const SRC& src, DEST* dest) {
dest->reserve(src.size());
for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
dest->push_back(typename DEST::value_type(*i));
}
}
UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
Init();
}
UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
: ChildThread(channel_name),
single_process_(true) {
Init();
}
UtilityThreadImpl::~UtilityThreadImpl() {
}
void UtilityThreadImpl::Shutdown() {
ChildThread::Shutdown();
if (!single_process_)
blink::shutdown();
}
bool UtilityThreadImpl::Send(IPC::Message* msg) {
return ChildThread::Send(msg);
}
void UtilityThreadImpl::ReleaseProcessIfNeeded() {
if (batch_mode_)
return;
if (single_process_) {
channel()->Close();
} else {
ChildProcess::current()->ReleaseProcess();
}
}
#if defined(OS_WIN)
void UtilityThreadImpl::PreCacheFont(const LOGFONT& log_font) {
Send(new ChildProcessHostMsg_PreCacheFont(log_font));
}
void UtilityThreadImpl::ReleaseCachedFonts() {
Send(new ChildProcessHostMsg_ReleaseCachedFonts());
}
#endif
void UtilityThreadImpl::Init() {
batch_mode_ = false;
ChildProcess::current()->AddRefProcess();
if (!single_process_) {
webkit_platform_support_.reset(new BlinkPlatformImpl);
blink::initialize(webkit_platform_support_.get());
}
GetContentClient()->utility()->UtilityThreadStarted();
}
bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
if (GetContentClient()->utility()->OnMessageReceived(msg))
return true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg)
IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
#if defined(OS_POSIX)
IPC_MESSAGE_HANDLER(UtilityMsg_LoadPlugins, OnLoadPlugins)
#endif
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void UtilityThreadImpl::OnBatchModeStarted() {
batch_mode_ = true;
}
void UtilityThreadImpl::OnBatchModeFinished() {
batch_mode_ = false;
ReleaseProcessIfNeeded();
}
#if defined(OS_POSIX)
void UtilityThreadImpl::OnLoadPlugins(
const std::vector<base::FilePath>& plugin_paths) {
PluginList* plugin_list = PluginList::Singleton();
std::vector<WebPluginInfo> plugins;
for (size_t i = 0; i < plugin_paths.size(); ++i) {
WebPluginInfo plugin;
if (!plugin_list->LoadPluginIntoPluginList(
plugin_paths[i], &plugins, &plugin))
Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i]));
else
Send(new UtilityHostMsg_LoadedPlugin(i, plugin));
}
ReleaseProcessIfNeeded();
}
#endif
}