ServiceWorkerVersion: remove unused parameter in DispatchInstallEvent
[chromium-blink-merge.git] / content / utility / utility_thread_impl.cc
blob26af2b17a06ae523c4e7c01d755698731fc631c4
1 // Copyright (c) 2012 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 "content/utility/utility_thread_impl.h"
7 #include <stddef.h>
9 #include "base/command_line.h"
10 #include "base/memory/scoped_vector.h"
11 #include "content/child/blink_platform_impl.h"
12 #include "content/child/child_process.h"
13 #include "content/common/child_process_messages.h"
14 #include "content/common/utility_messages.h"
15 #include "content/public/common/content_switches.h"
16 #include "content/public/utility/content_utility_client.h"
17 #include "ipc/ipc_sync_channel.h"
18 #include "third_party/WebKit/public/web/WebKit.h"
20 #if defined(OS_POSIX) && defined(ENABLE_PLUGINS)
21 #include "base/files/file_path.h"
22 #include "content/common/plugin_list.h"
23 #endif
25 namespace content {
27 namespace {
29 template<typename SRC, typename DEST>
30 void ConvertVector(const SRC& src, DEST* dest) {
31 dest->reserve(src.size());
32 for (typename SRC::const_iterator i = src.begin(); i != src.end(); ++i)
33 dest->push_back(typename DEST::value_type(*i));
36 } // namespace
38 UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
39 Init();
42 UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
43 : ChildThreadImpl(Options(channel_name, false)),
44 single_process_(true) {
45 Init();
48 UtilityThreadImpl::~UtilityThreadImpl() {
51 void UtilityThreadImpl::Shutdown() {
52 ChildThreadImpl::Shutdown();
54 if (!single_process_)
55 blink::shutdown();
58 void UtilityThreadImpl::ReleaseProcessIfNeeded() {
59 if (batch_mode_)
60 return;
62 if (single_process_) {
63 // Close the channel to cause UtilityProcessHostImpl to be deleted. We need
64 // to take a different code path than the multi-process case because that
65 // depends on the child process going away to close the channel, but that
66 // can't happen when we're in single process mode.
67 channel()->Close();
68 } else {
69 ChildProcess::current()->ReleaseProcess();
73 void UtilityThreadImpl::Init() {
74 batch_mode_ = false;
75 ChildProcess::current()->AddRefProcess();
76 if (!single_process_) {
77 // We can only initialize WebKit on one thread, and in single process mode
78 // we run the utility thread on separate thread. This means that if any code
79 // needs WebKit initialized in the utility process, they need to have
80 // another path to support single process mode.
81 blink_platform_impl_.reset(new BlinkPlatformImpl);
82 blink::initialize(blink_platform_impl_.get());
84 GetContentClient()->utility()->UtilityThreadStarted();
87 bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
88 if (GetContentClient()->utility()->OnMessageReceived(msg))
89 return true;
91 bool handled = true;
92 IPC_BEGIN_MESSAGE_MAP(UtilityThreadImpl, msg)
93 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Started, OnBatchModeStarted)
94 IPC_MESSAGE_HANDLER(UtilityMsg_BatchMode_Finished, OnBatchModeFinished)
95 #if defined(OS_POSIX) && defined(ENABLE_PLUGINS)
96 IPC_MESSAGE_HANDLER(UtilityMsg_LoadPlugins, OnLoadPlugins)
97 #endif
98 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP()
100 return handled;
103 void UtilityThreadImpl::OnBatchModeStarted() {
104 batch_mode_ = true;
107 void UtilityThreadImpl::OnBatchModeFinished() {
108 batch_mode_ = false;
109 ReleaseProcessIfNeeded();
112 #if defined(OS_POSIX) && defined(ENABLE_PLUGINS)
113 void UtilityThreadImpl::OnLoadPlugins(
114 const std::vector<base::FilePath>& plugin_paths) {
115 PluginList* plugin_list = PluginList::Singleton();
117 std::vector<WebPluginInfo> plugins;
118 // TODO(bauerb): If we restart loading plug-ins, we might mess up the logic in
119 // PluginList::ShouldLoadPlugin due to missing the previously loaded plug-ins
120 // in |plugin_groups|.
121 for (size_t i = 0; i < plugin_paths.size(); ++i) {
122 WebPluginInfo plugin;
123 if (!plugin_list->LoadPluginIntoPluginList(
124 plugin_paths[i], &plugins, &plugin))
125 Send(new UtilityHostMsg_LoadPluginFailed(i, plugin_paths[i]));
126 else
127 Send(new UtilityHostMsg_LoadedPlugin(i, plugin));
130 ReleaseProcessIfNeeded();
132 #endif
134 } // namespace content