Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: content/utility/utility_thread_impl.cc

Issue 18119009: Make utility process run in-process when running in single-process mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: add comment Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/utility/utility_thread_impl.cc
===================================================================
--- content/utility/utility_thread_impl.cc (revision 209067)
+++ content/utility/utility_thread_impl.cc (working copy)
@@ -13,6 +13,7 @@
#include "content/child/webkitplatformsupport_impl.h"
#include "content/common/child_process_messages.h"
#include "content/common/utility_messages.h"
+#include "content/public/common/content_switches.h"
#include "content/public/utility/content_utility_client.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "webkit/plugins/npapi/plugin_list.h"
@@ -36,19 +37,22 @@
} // namespace
-UtilityThreadImpl::UtilityThreadImpl()
- : batch_mode_(false) {
- ChildProcess::current()->AddRefProcess();
- webkit_platform_support_.reset(new WebKitPlatformSupportImpl);
- WebKit::initialize(webkit_platform_support_.get());
- GetContentClient()->utility()->UtilityThreadStarted();
+UtilityThreadImpl::UtilityThreadImpl() : initialize_webkit_(true) {
+ Init();
}
+UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
+ : ChildThread(channel_name),
+ initialize_webkit_(false) {
+ Init();
+}
+
UtilityThreadImpl::~UtilityThreadImpl() {
}
void UtilityThreadImpl::Shutdown() {
- WebKit::shutdown();
+ if (initialize_webkit_)
+ WebKit::shutdown();
}
bool UtilityThreadImpl::Send(IPC::Message* msg) {
@@ -56,8 +60,15 @@
}
void UtilityThreadImpl::ReleaseProcessIfNeeded() {
- if (!batch_mode_)
- ChildProcess::current()->ReleaseProcess();
+ if (batch_mode_)
+ return;
+
+ // We don't need to call ChildProcess::current()->ReleaseProcess() here, and
+ // can just quit the message loop directly. This is because the unlike other
+ // kind of child processes, there's no race condition between killing utility
+ // processes. A side benefit is that it makes tests which use this code path
+ // easier to clean up.
+ base::MessageLoop::current()->Quit();
}
#if defined(OS_WIN)
@@ -72,6 +83,19 @@
#endif // OS_WIN
+void UtilityThreadImpl::Init() {
+ batch_mode_ = false;
+ ChildProcess::current()->AddRefProcess();
+ if (initialize_webkit_) {
+ // We can only initialize WebKit on one thread, and in single process mode
+ // we run the utility thread on separate thread. This means that if any code
+ // needs WebKit initialized in the utility process, they need to have
+ // another path to support single process mode.
+ webkit_platform_support_.reset(new WebKitPlatformSupportImpl);
+ WebKit::initialize(webkit_platform_support_.get());
+ }
+ GetContentClient()->utility()->UtilityThreadStarted();
+}
bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
if (GetContentClient()->utility()->OnMessageReceived(msg))
« content/utility/utility_thread_impl.h ('K') | « content/utility/utility_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698