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

Side by Side Diff: content/browser/browser_child_process_host_impl.cc

Issue 2221153003: Establish MojoChildConnection from BrowserChildProcessHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renderer-channel
Patch Set: rebase Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/browser_child_process_host_impl.h" 5 #include "content/browser/browser_child_process_host_impl.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/dump_without_crashing.h" 10 #include "base/debug/dump_without_crashing.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h"
20 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "build/build_config.h" 23 #include "build/build_config.h"
23 #include "components/tracing/common/tracing_switches.h" 24 #include "components/tracing/common/tracing_switches.h"
24 #include "content/browser/histogram_message_filter.h" 25 #include "content/browser/histogram_message_filter.h"
25 #include "content/browser/loader/resource_message_filter.h" 26 #include "content/browser/loader/resource_message_filter.h"
26 #include "content/browser/memory/memory_message_filter.h" 27 #include "content/browser/memory/memory_message_filter.h"
28 #include "content/browser/mojo/mojo_child_connection.h"
29 #include "content/browser/mojo/mojo_shell_context.h"
27 #include "content/browser/profiler_message_filter.h" 30 #include "content/browser/profiler_message_filter.h"
28 #include "content/browser/tracing/trace_message_filter.h" 31 #include "content/browser/tracing/trace_message_filter.h"
29 #include "content/common/child_process_host_impl.h" 32 #include "content/common/child_process_host_impl.h"
30 #include "content/common/child_process_messages.h" 33 #include "content/common/child_process_messages.h"
31 #include "content/public/browser/browser_child_process_host_delegate.h" 34 #include "content/public/browser/browser_child_process_host_delegate.h"
32 #include "content/public/browser/browser_child_process_observer.h" 35 #include "content/public/browser/browser_child_process_observer.h"
33 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/child_process_data.h" 37 #include "content/public/browser/child_process_data.h"
35 #include "content/public/browser/content_browser_client.h" 38 #include "content/public/browser/content_browser_client.h"
36 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
40 #include "content/public/common/mojo_channel_switches.h"
37 #include "content/public/common/process_type.h" 41 #include "content/public/common/process_type.h"
38 #include "content/public/common/result_codes.h" 42 #include "content/public/common/result_codes.h"
39 #include "ipc/attachment_broker.h" 43 #include "ipc/attachment_broker.h"
40 #include "ipc/attachment_broker_privileged.h" 44 #include "ipc/attachment_broker_privileged.h"
41 #include "mojo/edk/embedder/embedder.h" 45 #include "mojo/edk/embedder/embedder.h"
42 46
43 #if defined(OS_MACOSX) 47 #if defined(OS_MACOSX)
44 #include "content/browser/mach_broker_mac.h" 48 #include "content/browser/mach_broker_mac.h"
45 #endif 49 #endif
46 50
(...skipping 29 matching lines...) Expand all
76 void NotifyProcessKilled(const ChildProcessData& data, int exit_code) { 80 void NotifyProcessKilled(const ChildProcessData& data, int exit_code) {
77 FOR_EACH_OBSERVER(BrowserChildProcessObserver, g_observers.Get(), 81 FOR_EACH_OBSERVER(BrowserChildProcessObserver, g_observers.Get(),
78 BrowserChildProcessKilled(data, exit_code)); 82 BrowserChildProcessKilled(data, exit_code));
79 } 83 }
80 84
81 } // namespace 85 } // namespace
82 86
83 BrowserChildProcessHost* BrowserChildProcessHost::Create( 87 BrowserChildProcessHost* BrowserChildProcessHost::Create(
84 content::ProcessType process_type, 88 content::ProcessType process_type,
85 BrowserChildProcessHostDelegate* delegate) { 89 BrowserChildProcessHostDelegate* delegate) {
86 return new BrowserChildProcessHostImpl( 90 return Create(process_type, delegate, std::string());
87 process_type, delegate, mojo::edk::GenerateRandomToken());
88 } 91 }
89 92
90 BrowserChildProcessHost* BrowserChildProcessHost::Create( 93 BrowserChildProcessHost* BrowserChildProcessHost::Create(
91 content::ProcessType process_type, 94 content::ProcessType process_type,
92 BrowserChildProcessHostDelegate* delegate, 95 BrowserChildProcessHostDelegate* delegate,
93 const std::string& mojo_child_token) { 96 const std::string& service_name) {
94 return new BrowserChildProcessHostImpl( 97 return new BrowserChildProcessHostImpl(process_type, delegate, service_name);
95 process_type, delegate, mojo_child_token);
96 } 98 }
97 99
98 BrowserChildProcessHost* BrowserChildProcessHost::FromID(int child_process_id) { 100 BrowserChildProcessHost* BrowserChildProcessHost::FromID(int child_process_id) {
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
100 BrowserChildProcessHostImpl::BrowserChildProcessList* process_list = 102 BrowserChildProcessHostImpl::BrowserChildProcessList* process_list =
101 g_child_process_list.Pointer(); 103 g_child_process_list.Pointer();
102 for (BrowserChildProcessHostImpl* host : *process_list) { 104 for (BrowserChildProcessHostImpl* host : *process_list) {
103 if (host->GetData().id == child_process_id) 105 if (host->GetData().id == child_process_id)
104 return host; 106 return host;
105 } 107 }
(...skipping 22 matching lines...) Expand all
128 // static 130 // static
129 void BrowserChildProcessHostImpl::RemoveObserver( 131 void BrowserChildProcessHostImpl::RemoveObserver(
130 BrowserChildProcessObserver* observer) { 132 BrowserChildProcessObserver* observer) {
131 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. 133 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126.
132 g_observers.Get().RemoveObserver(observer); 134 g_observers.Get().RemoveObserver(observer);
133 } 135 }
134 136
135 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( 137 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
136 content::ProcessType process_type, 138 content::ProcessType process_type,
137 BrowserChildProcessHostDelegate* delegate, 139 BrowserChildProcessHostDelegate* delegate,
138 const std::string& mojo_child_token) 140 const std::string& service_name)
139 : data_(process_type), 141 : data_(process_type),
140 delegate_(delegate), 142 delegate_(delegate),
141 mojo_child_token_(mojo_child_token), 143 child_token_(mojo::edk::GenerateRandomToken()),
142 power_monitor_message_broadcaster_(this), 144 power_monitor_message_broadcaster_(this),
143 is_channel_connected_(false), 145 is_channel_connected_(false),
144 notify_child_disconnected_(false), 146 notify_child_disconnected_(false),
145 weak_factory_(this) { 147 weak_factory_(this) {
146 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); 148 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
147 149
148 #if USE_ATTACHMENT_BROKER 150 #if USE_ATTACHMENT_BROKER
149 // Construct the privileged attachment broker early in the life cycle of a 151 // Construct the privileged attachment broker early in the life cycle of a
150 // child process. This ensures that when a test is being run in one of the 152 // child process. This ensures that when a test is being run in one of the
151 // single process modes, the global attachment broker is the privileged 153 // single process modes, the global attachment broker is the privileged
152 // attachment broker, rather than an unprivileged attachment broker. 154 // attachment broker, rather than an unprivileged attachment broker.
153 #if defined(OS_MACOSX) 155 #if defined(OS_MACOSX)
154 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( 156 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(
155 MachBroker::GetInstance()); 157 MachBroker::GetInstance());
156 #else 158 #else
157 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); 159 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
158 #endif // defined(OS_MACOSX) 160 #endif // defined(OS_MACOSX)
159 #endif // USE_ATTACHMENT_BROKER 161 #endif // USE_ATTACHMENT_BROKER
160 162
161 child_process_host_.reset(ChildProcessHost::Create(this)); 163 child_process_host_.reset(ChildProcessHost::Create(this));
162 AddFilter(new TraceMessageFilter(data_.id)); 164 AddFilter(new TraceMessageFilter(data_.id));
163 AddFilter(new ProfilerMessageFilter(process_type)); 165 AddFilter(new ProfilerMessageFilter(process_type));
164 AddFilter(new HistogramMessageFilter); 166 AddFilter(new HistogramMessageFilter);
165 AddFilter(new MemoryMessageFilter(this, process_type)); 167 AddFilter(new MemoryMessageFilter(this, process_type));
166 168
167 g_child_process_list.Get().push_back(this); 169 g_child_process_list.Get().push_back(this);
168 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); 170 GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
169 171
170 power_monitor_message_broadcaster_.Init(); 172 power_monitor_message_broadcaster_.Init();
173
174 if (!service_name.empty()) {
175 DCHECK_CURRENTLY_ON(BrowserThread::IO);
176 child_connection_.reset(new MojoChildConnection(
177 service_name, base::StringPrintf("%d", data_.id), child_token_,
178 MojoShellContext::GetConnectorForIOThread(),
179 base::ThreadTaskRunnerHandle::Get()));
180 }
171 } 181 }
172 182
173 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { 183 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
174 g_child_process_list.Get().remove(this); 184 g_child_process_list.Get().remove(this);
175 185
176 if (notify_child_disconnected_) { 186 if (notify_child_disconnected_) {
177 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
178 base::Bind(&NotifyProcessHostDisconnected, data_)); 188 base::Bind(&NotifyProcessHostDisconnected, data_));
179 } 189 }
180 } 190 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 switches::kEnableLogging, 239 switches::kEnableLogging,
230 switches::kIPCConnectionTimeout, 240 switches::kIPCConnectionTimeout,
231 switches::kLoggingLevel, 241 switches::kLoggingLevel,
232 switches::kTraceToConsole, 242 switches::kTraceToConsole,
233 switches::kV, 243 switches::kV,
234 switches::kVModule, 244 switches::kVModule,
235 }; 245 };
236 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, 246 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
237 arraysize(kForwardSwitches)); 247 arraysize(kForwardSwitches));
238 248
249 if (child_connection_) {
250 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken,
251 child_connection_->service_token());
252 }
253
239 notify_child_disconnected_ = true; 254 notify_child_disconnected_ = true;
240 child_process_.reset(new ChildProcessLauncher( 255 child_process_.reset(new ChildProcessLauncher(
241 delegate, 256 delegate,
242 cmd_line, 257 cmd_line,
243 data_.id, 258 data_.id,
244 this, 259 this,
245 mojo_child_token_, 260 child_token_,
246 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, 261 base::Bind(&BrowserChildProcessHostImpl::OnMojoError,
247 weak_factory_.GetWeakPtr(), 262 weak_factory_.GetWeakPtr(),
248 base::ThreadTaskRunnerHandle::Get()), 263 base::ThreadTaskRunnerHandle::Get()),
249 terminate_on_shutdown)); 264 terminate_on_shutdown));
250 } 265 }
251 266
252 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { 267 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const {
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); 268 DCHECK_CURRENTLY_ON(BrowserThread::IO);
254 return data_; 269 return data_;
255 } 270 }
(...skipping 15 matching lines...) Expand all
271 void BrowserChildProcessHostImpl::SetName(const base::string16& name) { 286 void BrowserChildProcessHostImpl::SetName(const base::string16& name) {
272 DCHECK_CURRENTLY_ON(BrowserThread::IO); 287 DCHECK_CURRENTLY_ON(BrowserThread::IO);
273 data_.name = name; 288 data_.name = name;
274 } 289 }
275 290
276 void BrowserChildProcessHostImpl::SetHandle(base::ProcessHandle handle) { 291 void BrowserChildProcessHostImpl::SetHandle(base::ProcessHandle handle) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); 292 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 data_.handle = handle; 293 data_.handle = handle;
279 } 294 }
280 295
281 shell::InterfaceProvider* BrowserChildProcessHostImpl::GetRemoteInterfaces() {
282 DCHECK_CURRENTLY_ON(BrowserThread::IO);
283 return delegate_->GetRemoteInterfaces();
284 }
285
286 void BrowserChildProcessHostImpl::ForceShutdown() { 296 void BrowserChildProcessHostImpl::ForceShutdown() {
287 DCHECK_CURRENTLY_ON(BrowserThread::IO); 297 DCHECK_CURRENTLY_ON(BrowserThread::IO);
288 g_child_process_list.Get().remove(this); 298 g_child_process_list.Get().remove(this);
289 child_process_host_->ForceShutdown(); 299 child_process_host_->ForceShutdown();
290 } 300 }
291 301
292 void BrowserChildProcessHostImpl::SetBackgrounded(bool backgrounded) { 302 void BrowserChildProcessHostImpl::SetBackgrounded(bool backgrounded) {
293 child_process_->SetProcessBackgrounded(backgrounded); 303 child_process_->SetProcessBackgrounded(backgrounded);
294 } 304 }
295 305
296 void BrowserChildProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { 306 void BrowserChildProcessHostImpl::AddFilter(BrowserMessageFilter* filter) {
297 child_process_host_->AddFilter(filter->GetFilter()); 307 child_process_host_->AddFilter(filter->GetFilter());
298 } 308 }
299 309
310 shell::InterfaceProvider* BrowserChildProcessHostImpl::GetRemoteInterfaces() {
311 DCHECK_CURRENTLY_ON(BrowserThread::IO);
312 if (!child_connection_)
313 return nullptr;
314
315 return child_connection_->GetRemoteInterfaces();
316 }
317
300 void BrowserChildProcessHostImpl::HistogramBadMessageTerminated( 318 void BrowserChildProcessHostImpl::HistogramBadMessageTerminated(
301 int process_type) { 319 int process_type) {
302 UMA_HISTOGRAM_ENUMERATION("ChildProcess.BadMessgeTerminated", process_type, 320 UMA_HISTOGRAM_ENUMERATION("ChildProcess.BadMessgeTerminated", process_type,
303 PROCESS_TYPE_MAX); 321 PROCESS_TYPE_MAX);
304 } 322 }
305 323
306 base::TerminationStatus BrowserChildProcessHostImpl::GetTerminationStatus( 324 base::TerminationStatus BrowserChildProcessHostImpl::GetTerminationStatus(
307 bool known_dead, int* exit_code) { 325 bool known_dead, int* exit_code) {
308 DCHECK_CURRENTLY_ON(BrowserThread::IO); 326 DCHECK_CURRENTLY_ON(BrowserThread::IO);
309 if (!child_process_) // If the delegate doesn't use Launch() helper. 327 if (!child_process_) // If the delegate doesn't use Launch() helper.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 521
504 #if defined(OS_WIN) 522 #if defined(OS_WIN)
505 523
506 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { 524 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
507 OnChildDisconnected(); 525 OnChildDisconnected();
508 } 526 }
509 527
510 #endif 528 #endif
511 529
512 } // namespace content 530 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_child_process_host_impl.h ('k') | content/browser/gpu/gpu_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698