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

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

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