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

Unified Diff: content/browser/utility_process_host_impl.cc

Issue 23235002: Set up content in-process main threads via factory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't add targets (were already in !ios block) Created 7 years, 4 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/browser/utility_process_host_impl.cc
diff --git a/content/browser/utility_process_host_impl.cc b/content/browser/utility_process_host_impl.cc
index 2e562188d24d22199fca01170defd4762418b8c2..41f531a5e63143d0a75e344a44ece150d9cd3b3d 100644
--- a/content/browser/utility_process_host_impl.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -53,53 +53,8 @@ private:
};
#endif
-// We want to ensure there's only one utility thread running at a time, as there
-// are many globals used in the utility process.
-static base::LazyInstance<base::Lock> g_one_utility_thread_lock;
-// Single process not supported in multiple dll mode currently.
-#if !defined(CHROME_MULTIPLE_DLL)
-class UtilityMainThread : public base::Thread {
- public:
- UtilityMainThread(const std::string& channel_id)
- : Thread("Chrome_InProcUtilityThread"),
- channel_id_(channel_id) {
- }
-
- virtual ~UtilityMainThread() {
- Stop();
- }
-
- private:
- // base::Thread implementation:
- virtual void Init() OVERRIDE {
- // We need to return right away or else the main thread that started us will
- // hang.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&UtilityMainThread::InitInternal, base::Unretained(this)));
- }
-
- virtual void CleanUp() OVERRIDE {
- child_process_.reset();
-
- // See comment in RendererMainThread.
- SetThreadWasQuitProperly(true);
- g_one_utility_thread_lock.Get().Release();
- }
-
- void InitInternal() {
- g_one_utility_thread_lock.Get().Acquire();
- child_process_.reset(new ChildProcess());
- child_process_->set_main_thread(new UtilityThreadImpl(channel_id_));
- }
-
- std::string channel_id_;
- scoped_ptr<ChildProcess> child_process_;
-
- DISALLOW_COPY_AND_ASSIGN(UtilityMainThread);
-};
-#endif // !CHROME_MULTIPLE_DLL
+UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL;
UtilityProcessHost* UtilityProcessHost::Create(
UtilityProcessHostClient* client,
@@ -107,6 +62,11 @@ UtilityProcessHost* UtilityProcessHost::Create(
return new UtilityProcessHostImpl(client, client_task_runner);
}
+void UtilityProcessHost::RegisterUtilityMainThreadFactory(
+ UtilityMainThreadFactoryFunction create) {
+ g_utility_main_thread_factory = create;
+}
+
UtilityProcessHostImpl::UtilityProcessHostImpl(
UtilityProcessHostClient* client,
base::SequencedTaskRunner* client_task_runner)
@@ -196,15 +156,13 @@ bool UtilityProcessHostImpl::StartProcess() {
return false;
// Single process not supported in multiple dll mode currently.
-#if !defined(CHROME_MULTIPLE_DLL)
- if (RenderProcessHost::run_renderer_in_process()) {
+ if (RenderProcessHost::run_renderer_in_process() &&
+ g_utility_main_thread_factory) {
// See comment in RenderProcessHostImpl::Init() for the background on why we
// support single process mode this way.
- in_process_thread_.reset(new UtilityMainThread(channel_id));
+ in_process_thread_.reset(g_utility_main_thread_factory(channel_id));
in_process_thread_->Start();
- } else
-#endif // !CHROME_MULTIPLE_DLL
- {
+ } else {
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
int child_flags = child_flags_;

Powered by Google App Engine
This is Rietveld 408576698