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

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: ios 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..766b82e8ccc70df5d493060de2e47109b5514d10 100644
--- a/content/browser/utility_process_host_impl.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -16,7 +16,6 @@
#include "base/synchronization/waitable_event.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
-#include "content/child/child_process.h"
#include "content/common/child_process_host_impl.h"
#include "content/common/utility_messages.h"
#include "content/public/browser/browser_thread.h"
@@ -24,7 +23,6 @@
#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/process_type.h"
-#include "content/utility/utility_thread_impl.h"
#include "ipc/ipc_switches.h"
#include "ui/base/ui_base_switches.h"
@@ -53,53 +51,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 +60,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 +154,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