blob: 3f64880f938b39811e6ddfc5ad22537677dedb5f [file] [log] [blame]
[email protected]02798a982012-01-27 00:45:331// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d27893f62010-07-03 05:47:422// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4c01d4992012-01-23 23:33:015#include "content/browser/browser_child_process_host_impl.h"
[email protected]d27893f62010-07-03 05:47:426
[email protected]2b065f82012-10-18 07:11:167#include "base/base_switches.h"
[email protected]4306c3792011-12-02 01:57:538#include "base/bind.h"
[email protected]d27893f62010-07-03 05:47:429#include "base/command_line.h"
Yuzhu Shen32fcad72017-09-14 23:12:3710#include "base/debug/crash_logging.h"
wfhaf32d0b2015-04-07 02:21:3611#include "base/debug/dump_without_crashing.h"
erikchen55edbff2016-05-03 23:53:1712#include "base/feature_list.h"
[email protected]57999812013-02-24 05:40:5213#include "base/files/file_path.h"
[email protected]d3c6c0d72010-12-09 08:15:0414#include "base/lazy_instance.h"
[email protected]d27893f62010-07-03 05:47:4215#include "base/logging.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
erikchen55edbff2016-05-03 23:53:1717#include "base/metrics/field_trial.h"
Ilya Sherman1c811db2017-12-14 10:36:1818#include "base/metrics/histogram_functions.h"
asvitkine30330812016-08-30 04:01:0819#include "base/metrics/histogram_macros.h"
bcwhiteb58a5fe2016-08-22 16:25:5620#include "base/metrics/persistent_histogram_allocator.h"
21#include "base/metrics/persistent_memory_allocator.h"
Ken Rockot47c47d862019-09-26 17:38:0722#include "base/no_destructor.h"
[email protected]7286e3fc2011-07-19 22:13:2423#include "base/stl_util.h"
[email protected]10994d132013-06-11 07:16:1824#include "base/strings/string_util.h"
rockotda9887902016-08-19 20:46:4225#include "base/strings/stringprintf.h"
[email protected]162a9fd2013-03-06 20:47:4926#include "base/synchronization/waitable_event.h"
Eric Seckler8652dcd52018-09-20 10:42:2827#include "base/task/post_task.h"
rockot229fb28e2016-06-16 04:46:1628#include "base/threading/thread_task_runner_handle.h"
Ken Rockot315def72018-11-10 02:16:1029#include "base/token.h"
avib7348942015-12-25 20:57:1030#include "build/build_config.h"
Ehsan Chiniforooshandef633e02018-04-24 02:05:0231#include "components/tracing/common/trace_startup_config.h"
primianoccb26c62016-06-01 21:50:0232#include "components/tracing/common/tracing_switches.h"
Robert Sesek1419427e2017-12-07 15:01:3233#include "content/browser/bad_message.h"
Ehsan Chiniforooshanf192e8a22018-03-27 03:18:2034#include "content/browser/browser_main_loop.h"
Nicholas Verne91bf4a632017-10-12 21:14:2435#include "content/browser/histogram_controller.h"
benff461632016-10-06 14:27:3336#include "content/browser/service_manager/service_manager_context.h"
Darin Fisherc23ee1a2019-06-05 23:26:3037#include "content/browser/tracing/background_tracing_manager_impl.h"
[email protected]4734d0b2011-12-03 07:10:4438#include "content/common/child_process_host_impl.h"
bend32292b2016-10-07 00:21:5839#include "content/common/service_manager/child_connection.h"
[email protected]4967f792012-01-20 22:14:4040#include "content/public/browser/browser_child_process_host_delegate.h"
[email protected]f4eaf7b92013-02-28 22:00:4041#include "content/public/browser/browser_child_process_observer.h"
John Abd-El-Malek252adb9c2019-07-30 04:57:2442#include "content/public/browser/browser_message_filter.h"
Eric Seckler8652dcd52018-09-20 10:42:2843#include "content/public/browser/browser_task_traits.h"
[email protected]57999812013-02-24 05:40:5244#include "content/public/browser/browser_thread.h"
[email protected]4306c3792011-12-02 01:57:5345#include "content/public/browser/child_process_data.h"
[email protected]87f3c082011-10-19 18:07:4446#include "content/public/browser/content_browser_client.h"
Ken Rockotd7148c202019-09-18 18:00:5947#include "content/public/browser/resource_coordinator_service.h"
Ken Rockot20cd07b2019-10-01 23:01:1948#include "content/public/browser/system_connector.h"
ke.he19b5e6a2016-10-27 08:47:0949#include "content/public/common/connection_filter.h"
Hans Wennborg5ffd1392019-10-16 11:00:0250#include "content/public/common/content_client.h"
lawrencewu2c930822016-10-13 13:54:2551#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2952#include "content/public/common/content_switches.h"
[email protected]f3b357692013-03-22 05:16:1353#include "content/public/common/process_type.h"
[email protected]b39ef1cb2011-10-25 04:46:5554#include "content/public/common/result_codes.h"
jcivelli828cd7f2017-01-18 19:50:4655#include "content/public/common/sandboxed_process_launcher_delegate.h"
ke.he19b5e6a2016-10-27 08:47:0956#include "content/public/common/service_manager_connection.h"
Nicholas Verne91bf4a632017-10-12 21:14:2457#include "mojo/public/cpp/system/platform_handle.h"
Yoichi Osato14073bd2019-06-04 11:06:3758#include "net/websockets/websocket_basic_stream.h"
Yoichi Osato7ce08952019-06-18 02:10:3459#include "net/websockets/websocket_channel.h"
ochang6a8400e2017-05-01 21:28:2460#include "services/service_manager/embedder/switches.h"
Ken Rockota86fa542018-11-13 21:47:1361#include "services/service_manager/public/cpp/constants.h"
Eric Seckler660ffc42019-09-30 19:00:0462#include "services/tracing/public/cpp/trace_startup.h"
[email protected]d27893f62010-07-03 05:47:4263
[email protected]f1675202012-07-09 15:18:0064#if defined(OS_MACOSX)
Robert Sesekde2e713262019-07-15 20:57:5865#include "content/browser/child_process_task_port_provider_mac.h"
Ken Rockot47c47d862019-09-26 17:38:0766#include "content/browser/sandbox_support_mac_impl.h"
67#include "content/common/sandbox_support_mac.mojom.h"
68#endif
69
70#if defined(OS_WIN)
71#include "content/browser/renderer_host/dwrite_font_proxy_impl_win.h"
72#include "content/public/common/font_cache_dispatcher_win.h"
73#include "content/public/common/font_cache_win.mojom.h"
[email protected]3838ca12011-11-02 14:37:1574#endif
[email protected]a3a7e2c2011-09-16 23:07:0575
[email protected]130757672012-10-24 00:26:1976namespace content {
[email protected]d27893f62010-07-03 05:47:4277namespace {
78
scottmg5e65e3a2017-03-08 08:48:4679static base::LazyInstance<
80 BrowserChildProcessHostImpl::BrowserChildProcessList>::DestructorAtExit
[email protected]4967f792012-01-20 22:14:4081 g_child_process_list = LAZY_INSTANCE_INITIALIZER;
[email protected]d27893f62010-07-03 05:47:4282
Trent Apteda250ec3ab2018-08-19 08:52:1983base::LazyInstance<base::ObserverList<BrowserChildProcessObserver>::Unchecked>::
Daniel Bratellbfcfe222017-10-17 17:57:0084 DestructorAtExit g_browser_child_process_observers =
85 LAZY_INSTANCE_INITIALIZER;
[email protected]f4eaf7b92013-02-28 22:00:4086
afakhry9cc79002015-10-22 19:25:1587void NotifyProcessLaunchedAndConnected(const ChildProcessData& data) {
Daniel Bratellbfcfe222017-10-17 17:57:0088 for (auto& observer : g_browser_child_process_observers.Get())
ericwilligers254597b2016-10-17 10:32:3189 observer.BrowserChildProcessLaunchedAndConnected(data);
afakhry9cc79002015-10-22 19:25:1590}
91
[email protected]f4eaf7b92013-02-28 22:00:4092void NotifyProcessHostConnected(const ChildProcessData& data) {
Daniel Bratellbfcfe222017-10-17 17:57:0093 for (auto& observer : g_browser_child_process_observers.Get())
ericwilligers254597b2016-10-17 10:32:3194 observer.BrowserChildProcessHostConnected(data);
[email protected]f4eaf7b92013-02-28 22:00:4095}
96
97void NotifyProcessHostDisconnected(const ChildProcessData& data) {
Daniel Bratellbfcfe222017-10-17 17:57:0098 for (auto& observer : g_browser_child_process_observers.Get())
ericwilligers254597b2016-10-17 10:32:3199 observer.BrowserChildProcessHostDisconnected(data);
[email protected]f4eaf7b92013-02-28 22:00:40100}
101
Bo Liue9624612018-04-28 00:39:08102#if !defined(OS_ANDROID)
Bo Liu2a489402018-04-24 23:41:27103void NotifyProcessCrashed(const ChildProcessData& data,
104 const ChildProcessTerminationInfo& info) {
Daniel Bratellbfcfe222017-10-17 17:57:00105 for (auto& observer : g_browser_child_process_observers.Get())
Bo Liu2a489402018-04-24 23:41:27106 observer.BrowserChildProcessCrashed(data, info);
[email protected]4306c3792011-12-02 01:57:53107}
Bo Liue9624612018-04-28 00:39:08108#endif
[email protected]d27893f62010-07-03 05:47:42109
Bo Liu2a489402018-04-24 23:41:27110void NotifyProcessKilled(const ChildProcessData& data,
111 const ChildProcessTerminationInfo& info) {
Daniel Bratellbfcfe222017-10-17 17:57:00112 for (auto& observer : g_browser_child_process_observers.Get())
Bo Liu2a489402018-04-24 23:41:27113 observer.BrowserChildProcessKilled(data, info);
wfhf0003292015-08-18 22:16:46114}
115
Ken Rockotd7148c202019-09-18 18:00:59116memory_instrumentation::mojom::ProcessType GetCoordinatorClientProcessType(
117 ProcessType process_type) {
118 switch (process_type) {
119 case PROCESS_TYPE_RENDERER:
120 return memory_instrumentation::mojom::ProcessType::RENDERER;
121 case PROCESS_TYPE_UTILITY:
122 return memory_instrumentation::mojom::ProcessType::UTILITY;
123 case PROCESS_TYPE_GPU:
124 return memory_instrumentation::mojom::ProcessType::GPU;
125 case PROCESS_TYPE_PPAPI_PLUGIN:
126 case PROCESS_TYPE_PPAPI_BROKER:
127 return memory_instrumentation::mojom::ProcessType::PLUGIN;
128 default:
129 NOTREACHED();
130 return memory_instrumentation::mojom::ProcessType::OTHER;
131 }
132}
133
[email protected]d27893f62010-07-03 05:47:42134} // namespace
135
[email protected]4967f792012-01-20 22:14:40136BrowserChildProcessHost* BrowserChildProcessHost::Create(
vadimt379d7fe2015-04-01 00:09:35137 content::ProcessType process_type,
[email protected]4967f792012-01-20 22:14:40138 BrowserChildProcessHostDelegate* delegate) {
rockotda9887902016-08-19 20:46:42139 return Create(process_type, delegate, std::string());
amistry6ad1e812016-06-06 05:36:30140}
141
142BrowserChildProcessHost* BrowserChildProcessHost::Create(
143 content::ProcessType process_type,
144 BrowserChildProcessHostDelegate* delegate,
rockotda9887902016-08-19 20:46:42145 const std::string& service_name) {
146 return new BrowserChildProcessHostImpl(process_type, delegate, service_name);
[email protected]4967f792012-01-20 22:14:40147}
148
amistryfaa231a42015-05-20 01:49:12149BrowserChildProcessHost* BrowserChildProcessHost::FromID(int child_process_id) {
150 DCHECK_CURRENTLY_ON(BrowserThread::IO);
151 BrowserChildProcessHostImpl::BrowserChildProcessList* process_list =
152 g_child_process_list.Pointer();
153 for (BrowserChildProcessHostImpl* host : *process_list) {
154 if (host->GetData().id == child_process_id)
155 return host;
156 }
157 return nullptr;
158}
159
[email protected]458433c2012-02-29 23:43:39160#if defined(OS_MACOSX)
erikchencd3e0e7b2015-10-01 22:53:51161base::PortProvider* BrowserChildProcessHost::GetPortProvider() {
Robert Sesekde2e713262019-07-15 20:57:58162 return ChildProcessTaskPortProvider::GetInstance();
[email protected]458433c2012-02-29 23:43:39163}
164#endif
165
[email protected]f4eaf7b92013-02-28 22:00:40166// static
[email protected]4c01d4992012-01-23 23:33:01167BrowserChildProcessHostImpl::BrowserChildProcessList*
Maggie Chen47b8dc1d2018-11-10 00:12:34168BrowserChildProcessHostImpl::GetIterator() {
[email protected]4967f792012-01-20 22:14:40169 return g_child_process_list.Pointer();
170}
171
[email protected]f4eaf7b92013-02-28 22:00:40172// static
173void BrowserChildProcessHostImpl::AddObserver(
174 BrowserChildProcessObserver* observer) {
mostynbfbcdc27a2015-03-13 17:58:52175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Daniel Bratellbfcfe222017-10-17 17:57:00176 g_browser_child_process_observers.Get().AddObserver(observer);
[email protected]f4eaf7b92013-02-28 22:00:40177}
178
179// static
180void BrowserChildProcessHostImpl::RemoveObserver(
181 BrowserChildProcessObserver* observer) {
182 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126.
Daniel Bratellbfcfe222017-10-17 17:57:00183 g_browser_child_process_observers.Get().RemoveObserver(observer);
[email protected]f4eaf7b92013-02-28 22:00:40184}
185
[email protected]4c01d4992012-01-23 23:33:01186BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
vadimt379d7fe2015-04-01 00:09:35187 content::ProcessType process_type,
amistry6ad1e812016-06-06 05:36:30188 BrowserChildProcessHostDelegate* delegate,
rockotda9887902016-08-19 20:46:42189 const std::string& service_name)
[email protected]f3b357692013-03-22 05:16:13190 : data_(process_type),
[email protected]9dd90152013-08-02 22:09:13191 delegate_(delegate),
sadrul6c5aed8c2017-01-11 23:11:44192 channel_(nullptr),
amistry012289f2016-04-01 00:56:37193 is_channel_connected_(false),
Jeremy Roman3bca4bf2019-07-11 03:41:25194 notify_child_disconnected_(false) {
[email protected]4734d0b2011-12-03 07:10:44195 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
[email protected]4306c3792011-12-02 01:57:53196
Ayu Ishii75cc1062019-01-08 01:27:37197 child_process_host_ = ChildProcessHost::Create(this);
[email protected]38917fe2011-04-06 17:29:12198
199 g_child_process_list.Get().push_back(this);
[email protected]130757672012-10-24 00:26:19200 GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
[email protected]30c4c67a2014-07-22 02:33:55201
rockotda9887902016-08-19 20:46:42202 if (!service_name.empty()) {
203 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Ken Rockota86fa542018-11-13 21:47:13204 child_connection_ = std::make_unique<ChildConnection>(
205 service_manager::Identity(
206 service_name, service_manager::kSystemInstanceGroup,
207 base::Token::CreateRandom(), base::Token::CreateRandom()),
208 &mojo_invitation_, ServiceManagerContext::GetConnectorForIOThread(),
209 base::ThreadTaskRunnerHandle::Get());
Will Harrisedb011f2018-06-01 20:28:44210 data_.metrics_name = service_name;
rockotda9887902016-08-19 20:46:42211 }
bcwhiteb58a5fe2016-08-22 16:25:56212
213 // Create a persistent memory segment for subprocess histograms.
214 CreateMetricsAllocator();
[email protected]38917fe2011-04-06 17:29:12215}
216
[email protected]4c01d4992012-01-23 23:33:01217BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
[email protected]d3c6c0d72010-12-09 08:15:04218 g_child_process_list.Get().remove(this);
amistry012289f2016-04-01 00:56:37219
220 if (notify_child_disconnected_) {
Sami Kyostila8e4d5a92019-08-02 12:45:05221 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28222 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26223 base::BindOnce(&NotifyProcessHostDisconnected, data_.Duplicate()));
amistry012289f2016-04-01 00:56:37224 }
[email protected]d27893f62010-07-03 05:47:42225}
226
227// static
[email protected]4c01d4992012-01-23 23:33:01228void BrowserChildProcessHostImpl::TerminateAll() {
mostynbfbcdc27a2015-03-13 17:58:52229 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]f174efd2012-01-17 18:43:33230 // Make a copy since the BrowserChildProcessHost dtor mutates the original
231 // list.
232 BrowserChildProcessList copy = g_child_process_list.Get();
jdoerrie55ec69d2018-10-08 13:34:46233 for (auto it = copy.begin(); it != copy.end(); ++it) {
[email protected]5998d9d2012-03-06 04:25:26234 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl.
235 }
[email protected]d27893f62010-07-03 05:47:42236}
237
erikchen55edbff2016-05-03 23:53:17238// static
lawrencewu0b4964922016-10-25 16:28:14239void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags(
erikchen55edbff2016-05-03 23:53:17240 base::CommandLine* cmd_line) {
erikchen55edbff2016-05-03 23:53:17241 // If we run base::FieldTrials, we want to pass to their state to the
242 // child process so that it can act in accordance with each state.
lawrencewu5e03cd32016-12-05 16:23:28243 base::FieldTrialList::CopyFieldTrialStateToFlags(
244 switches::kFieldTrialHandle, switches::kEnableFeatures,
245 switches::kDisableFeatures, cmd_line);
erikchen55edbff2016-05-03 23:53:17246}
247
Ehsan Chiniforooshanf192e8a22018-03-27 03:18:20248// static
249void BrowserChildProcessHostImpl::CopyTraceStartupFlags(
250 base::CommandLine* cmd_line) {
Eric Seckler660ffc42019-09-30 19:00:04251 tracing::PropagateTracingFlagsToChildProcessCmdLine(cmd_line);
Ehsan Chiniforooshanf192e8a22018-03-27 03:18:20252}
253
[email protected]4c01d4992012-01-23 23:33:01254void BrowserChildProcessHostImpl::Launch(
jcivellid20cc0b2016-12-22 03:51:41255 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
256 std::unique_ptr<base::CommandLine> cmd_line,
sievers954e37a2015-03-28 01:50:24257 bool terminate_on_shutdown) {
jcivellid20cc0b2016-12-22 03:51:41258 GetContentClient()->browser()->AppendExtraCommandLineSwitches(cmd_line.get(),
259 data_.id);
Maggie Chen47b8dc1d2018-11-10 00:12:34260 LaunchWithoutExtraCommandLineSwitches(
261 std::move(delegate), std::move(cmd_line), terminate_on_shutdown);
[email protected]d27893f62010-07-03 05:47:42262}
263
Lucas Furukawa Gadani0d5e7142019-04-18 23:00:50264const ChildProcessData& BrowserChildProcessHostImpl::GetData() {
mostynbfbcdc27a2015-03-13 17:58:52265 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]4967f792012-01-20 22:14:40266 return data_;
267}
268
Lucas Furukawa Gadani0d5e7142019-04-18 23:00:50269ChildProcessHost* BrowserChildProcessHostImpl::GetHost() {
mostynbfbcdc27a2015-03-13 17:58:52270 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]4967f792012-01-20 22:14:40271 return child_process_host_.get();
272}
273
Lucas Furukawa Gadani0d5e7142019-04-18 23:00:50274const base::Process& BrowserChildProcessHostImpl::GetProcess() {
mostynbfbcdc27a2015-03-13 17:58:52275 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]5d84d012010-12-02 17:17:21276 DCHECK(child_process_.get())
277 << "Requesting a child process handle before launching.";
rvargas079d1842014-10-17 22:32:16278 DCHECK(child_process_->GetProcess().IsValid())
[email protected]5d84d012010-12-02 17:17:21279 << "Requesting a child process handle before launch has completed OK.";
rvargas5779b382014-11-18 20:44:11280 return child_process_->GetProcess();
[email protected]5d84d012010-12-02 17:17:21281}
282
Alex Ilin30e7d062019-02-21 12:24:53283std::unique_ptr<base::PersistentMemoryAllocator>
bcwhiteb58a5fe2016-08-22 16:25:56284BrowserChildProcessHostImpl::TakeMetricsAllocator() {
285 return std::move(metrics_allocator_);
286}
287
[email protected]fcf75d42013-12-03 20:11:26288void BrowserChildProcessHostImpl::SetName(const base::string16& name) {
mostynbfbcdc27a2015-03-13 17:58:52289 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]f174efd2012-01-17 18:43:33290 data_.name = name;
291}
292
Will Harrisedb011f2018-06-01 20:28:44293void BrowserChildProcessHostImpl::SetMetricsName(
294 const std::string& metrics_name) {
295 DCHECK_CURRENTLY_ON(BrowserThread::IO);
296 data_.metrics_name = metrics_name;
297}
298
Francois Doray884da022018-10-30 23:45:58299void BrowserChildProcessHostImpl::SetProcess(base::Process process) {
mostynbfbcdc27a2015-03-13 17:58:52300 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Francois Doray884da022018-10-30 23:45:58301 data_.SetProcess(std::move(process));
[email protected]f174efd2012-01-17 18:43:33302}
303
Ken Rockotea1716a02017-05-11 05:49:10304service_manager::mojom::ServiceRequest
305BrowserChildProcessHostImpl::TakeInProcessServiceRequest() {
Ken Rockot026afc32018-06-04 19:19:18306 auto invitation = std::move(mojo_invitation_);
Ken Rockotf4d8a942017-05-13 00:10:37307 return service_manager::mojom::ServiceRequest(
Ken Rockot026afc32018-06-04 19:19:18308 invitation.ExtractMessagePipe(child_connection_->service_token()));
sammc2b0375b2016-12-22 01:26:17309}
310
[email protected]4c01d4992012-01-23 23:33:01311void BrowserChildProcessHostImpl::ForceShutdown() {
mostynbfbcdc27a2015-03-13 17:58:52312 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]d3c6c0d72010-12-09 08:15:04313 g_child_process_list.Get().remove(this);
[email protected]4cb43102011-12-02 20:24:49314 child_process_host_->ForceShutdown();
[email protected]d27893f62010-07-03 05:47:42315}
316
[email protected]ba780c12013-10-01 17:07:06317void BrowserChildProcessHostImpl::AddFilter(BrowserMessageFilter* filter) {
318 child_process_host_->AddFilter(filter->GetFilter());
319}
320
Maggie Chen47b8dc1d2018-11-10 00:12:34321void BrowserChildProcessHostImpl::LaunchWithoutExtraCommandLineSwitches(
322 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
323 std::unique_ptr<base::CommandLine> cmd_line,
324 bool terminate_on_shutdown) {
325 DCHECK_CURRENTLY_ON(BrowserThread::IO);
326 const base::CommandLine& browser_command_line =
327 *base::CommandLine::ForCurrentProcess();
328 static const char* const kForwardSwitches[] = {
Yoichi Osato14073bd2019-06-04 11:06:37329 net::kWebSocketReadBufferSize,
Yoichi Osato7ce08952019-06-18 02:10:34330 net::kWebSocketReceiveQuotaThreshold,
Maggie Chen47b8dc1d2018-11-10 00:12:34331 service_manager::switches::kDisableInProcessStackTraces,
Yue Ru Suna50a80f2019-02-08 05:02:58332 switches::kDisableBestEffortTasks,
Maggie Chen47b8dc1d2018-11-10 00:12:34333 switches::kDisableLogging,
Maggie Chen47b8dc1d2018-11-10 00:12:34334 switches::kEnableLogging,
335 switches::kIPCConnectionTimeout,
Francois Doray177da2c2019-06-20 14:14:22336 switches::kLogBestEffortTasks,
Greg Thompson54915832018-12-21 17:11:47337 switches::kLogFile,
Maggie Chen47b8dc1d2018-11-10 00:12:34338 switches::kLoggingLevel,
339 switches::kTraceToConsole,
340 switches::kV,
341 switches::kVModule,
342 };
343 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
344 base::size(kForwardSwitches));
345
346 if (child_connection_) {
347 cmd_line->AppendSwitchASCII(
348 service_manager::switches::kServiceRequestChannelToken,
349 child_connection_->service_token());
Darin Fisherc23ee1a2019-06-05 23:26:30350
351 // Tracing adds too much overhead to the profiling service.
352 if (service_manager::SandboxTypeFromCommandLine(*cmd_line) !=
353 service_manager::SANDBOX_TYPE_PROFILING) {
Darin Fisher0e4fc2e2019-06-13 02:19:18354 BackgroundTracingManagerImpl::ActivateForProcess(
355 data_.id,
356 static_cast<ChildProcessHostImpl*>(child_process_host_.get())
Ken Rockot62fb4352019-07-18 16:03:38357 ->child_process());
Darin Fisherc23ee1a2019-06-05 23:26:30358 }
Maggie Chen47b8dc1d2018-11-10 00:12:34359 }
360
361 // All processes should have a non-empty metrics name.
362 DCHECK(!data_.metrics_name.empty());
363
364 notify_child_disconnected_ = true;
365 child_process_.reset(new ChildProcessLauncher(
366 std::move(delegate), std::move(cmd_line), data_.id, this,
367 std::move(mojo_invitation_),
368 base::BindRepeating(&BrowserChildProcessHostImpl::OnMojoError,
369 weak_factory_.GetWeakPtr(),
370 base::ThreadTaskRunnerHandle::Get()),
371 terminate_on_shutdown));
372 ShareMetricsAllocatorToProcess();
373}
374
bena06f7d62017-04-04 20:48:52375void BrowserChildProcessHostImpl::BindInterface(
376 const std::string& interface_name,
377 mojo::ScopedMessagePipeHandle interface_pipe) {
rockotda9887902016-08-19 20:46:42378 DCHECK_CURRENTLY_ON(BrowserThread::IO);
379 if (!child_connection_)
bena06f7d62017-04-04 20:48:52380 return;
rockotda9887902016-08-19 20:46:42381
bena06f7d62017-04-04 20:48:52382 child_connection_->BindInterface(interface_name, std::move(interface_pipe));
rockotda9887902016-08-19 20:46:42383}
384
[email protected]ef2f6ba2014-05-15 23:06:07385void BrowserChildProcessHostImpl::HistogramBadMessageTerminated(
Wei-Yin Chen (陳威尹)223326c2017-07-21 02:08:28386 ProcessType process_type) {
[email protected]ef2f6ba2014-05-15 23:06:07387 UMA_HISTOGRAM_ENUMERATION("ChildProcess.BadMessgeTerminated", process_type,
388 PROCESS_TYPE_MAX);
389}
390
Min Qineb961902019-03-16 08:08:22391#if defined(OS_ANDROID)
392void BrowserChildProcessHostImpl::EnableWarmUpConnection() {
393 can_use_warm_up_connection_ = true;
394}
395#endif
396
Bo Liu0d2a2322018-04-19 00:18:09397ChildProcessTerminationInfo BrowserChildProcessHostImpl::GetTerminationInfo(
398 bool known_dead) {
mostynbfbcdc27a2015-03-13 17:58:52399 DCHECK_CURRENTLY_ON(BrowserThread::IO);
Bo Liu0d2a2322018-04-19 00:18:09400 if (!child_process_) {
401 // If the delegate doesn't use Launch() helper.
402 ChildProcessTerminationInfo info;
Francois Doray884da022018-10-30 23:45:58403 info.status = base::GetTerminationStatus(data_.GetProcess().Handle(),
404 &info.exit_code);
Bo Liu0d2a2322018-04-19 00:18:09405 return info;
406 }
407 return child_process_->GetChildTerminationInfo(known_dead);
[email protected]d27893f62010-07-03 05:47:42408}
409
[email protected]4c01d4992012-01-23 23:33:01410bool BrowserChildProcessHostImpl::OnMessageReceived(
411 const IPC::Message& message) {
[email protected]4967f792012-01-20 22:14:40412 return delegate_->OnMessageReceived(message);
[email protected]4cb43102011-12-02 20:24:49413}
414
avib7348942015-12-25 20:57:10415void BrowserChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) {
afakhry9cc79002015-10-22 19:25:15416 DCHECK_CURRENTLY_ON(BrowserThread::IO);
417
418 is_channel_connected_ = true;
amistry012289f2016-04-01 00:56:37419 notify_child_disconnected_ = true;
afakhry9cc79002015-10-22 19:25:15420
Robert Sesekde2e713262019-07-15 20:57:58421#if defined(OS_MACOSX)
422 ChildProcessTaskPortProvider::GetInstance()->OnChildProcessLaunched(
423 peer_pid, static_cast<ChildProcessHostImpl*>(child_process_host_.get())
Ken Rockot62fb4352019-07-18 16:03:38424 ->child_process());
Robert Sesekde2e713262019-07-15 20:57:58425#endif
426
[email protected]162a9fd2013-03-06 20:47:49427#if defined(OS_WIN)
428 // From this point onward, the exit of the child process is detected by an
429 // error on the IPC channel.
[email protected]162a9fd2013-03-06 20:47:49430 early_exit_watcher_.StopWatching();
431#endif
432
Sami Kyostila8e4d5a92019-08-02 12:45:05433 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28434 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26435 base::BindOnce(&NotifyProcessHostConnected, data_.Duplicate()));
[email protected]162a9fd2013-03-06 20:47:49436
[email protected]4967f792012-01-20 22:14:40437 delegate_->OnChannelConnected(peer_pid);
afakhry9cc79002015-10-22 19:25:15438
439 if (IsProcessLaunched()) {
Sami Kyostila8e4d5a92019-08-02 12:45:05440 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28441 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26442 base::BindOnce(&NotifyProcessLaunchedAndConnected, data_.Duplicate()));
afakhry9cc79002015-10-22 19:25:15443 }
[email protected]4967f792012-01-20 22:14:40444}
445
[email protected]4c01d4992012-01-23 23:33:01446void BrowserChildProcessHostImpl::OnChannelError() {
[email protected]4967f792012-01-20 22:14:40447 delegate_->OnChannelError();
[email protected]0d6e9bd2011-10-18 04:29:16448}
449
[email protected]ef2f6ba2014-05-15 23:06:07450void BrowserChildProcessHostImpl::OnBadMessageReceived(
451 const IPC::Message& message) {
Roman Karaseva43d5b4e2017-12-21 03:06:02452 std::string log_message = "Bad message received of type: ";
453 if (message.IsValid()) {
454 log_message += std::to_string(message.type());
455 } else {
456 log_message += "unknown";
457 }
sadrul73f39a62017-01-11 04:07:24458 TerminateOnBadMessageReceived(log_message);
jbauman278b2cc2016-01-08 22:48:53459}
460
sadrul73f39a62017-01-11 04:07:24461void BrowserChildProcessHostImpl::TerminateOnBadMessageReceived(
462 const std::string& error) {
Wei-Yin Chen (陳威尹)223326c2017-07-21 02:08:28463 HistogramBadMessageTerminated(static_cast<ProcessType>(data_.process_type));
avi83883c82014-12-23 00:08:49464 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]e44d1342014-05-16 21:29:33465 switches::kDisableKillAfterBadIPC)) {
466 return;
467 }
sadrul73f39a62017-01-11 04:07:24468 LOG(ERROR) << "Terminating child process for bad IPC message: " << error;
wfhaf32d0b2015-04-07 02:21:36469 // Create a memory dump. This will contain enough stack frames to work out
470 // what the bad message was.
471 base::debug::DumpWithoutCrashing();
472
Bo Liue06143912018-04-20 20:42:30473 child_process_->Terminate(RESULT_CODE_KILLED_BAD_MESSAGE);
[email protected]ef2f6ba2014-05-15 23:06:07474}
475
sadrul6c5aed8c2017-01-11 23:11:44476void BrowserChildProcessHostImpl::OnChannelInitialized(IPC::Channel* channel) {
477 channel_ = channel;
478}
479
[email protected]4c01d4992012-01-23 23:33:01480void BrowserChildProcessHostImpl::OnChildDisconnected() {
mostynbfbcdc27a2015-03-13 17:58:52481 DCHECK_CURRENTLY_ON(BrowserThread::IO);
jbauman319402e2014-10-21 17:52:21482#if defined(OS_WIN)
483 // OnChildDisconnected may be called without OnChannelConnected, so stop the
484 // early exit watcher so GetTerminationStatus can close the process handle.
485 early_exit_watcher_.StopWatching();
486#endif
Francois Doray884da022018-10-30 23:45:58487 if (child_process_.get() || data_.GetProcess().IsValid()) {
Bo Liu0d2a2322018-04-19 00:18:09488 ChildProcessTerminationInfo info =
489 GetTerminationInfo(true /* known_dead */);
Bo Liue9624612018-04-28 00:39:08490#if defined(OS_ANDROID)
491 delegate_->OnProcessCrashed(info.exit_code);
Sami Kyostila8e4d5a92019-08-02 12:45:05492 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28493 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26494 base::BindOnce(&NotifyProcessKilled, data_.Duplicate(), info));
Bo Liue9624612018-04-28 00:39:08495#else // OS_ANDROID
Bo Liu0d2a2322018-04-19 00:18:09496 switch (info.status) {
[email protected]6d057a0c2013-07-09 21:12:07497 case base::TERMINATION_STATUS_PROCESS_CRASHED:
498 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: {
Bo Liu0d2a2322018-04-19 00:18:09499 delegate_->OnProcessCrashed(info.exit_code);
Sami Kyostila8e4d5a92019-08-02 12:45:05500 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28501 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26502 base::BindOnce(&NotifyProcessCrashed, data_.Duplicate(), info));
[email protected]6d057a0c2013-07-09 21:12:07503 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Crashed2",
Wei-Yin Chen (陳威尹)3330991f2017-07-27 17:25:57504 static_cast<ProcessType>(data_.process_type),
[email protected]6d057a0c2013-07-09 21:12:07505 PROCESS_TYPE_MAX);
506 break;
507 }
oshima620225722015-06-04 19:45:27508#if defined(OS_CHROMEOS)
509 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
510#endif
[email protected]6d057a0c2013-07-09 21:12:07511 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: {
Bo Liu0d2a2322018-04-19 00:18:09512 delegate_->OnProcessCrashed(info.exit_code);
Sami Kyostila8e4d5a92019-08-02 12:45:05513 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28514 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26515 base::BindOnce(&NotifyProcessKilled, data_.Duplicate(), info));
[email protected]6d057a0c2013-07-09 21:12:07516 // Report that this child process was killed.
517 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2",
Wei-Yin Chen (陳威尹)3330991f2017-07-27 17:25:57518 static_cast<ProcessType>(data_.process_type),
[email protected]6d057a0c2013-07-09 21:12:07519 PROCESS_TYPE_MAX);
520 break;
521 }
522 case base::TERMINATION_STATUS_STILL_RUNNING: {
523 UMA_HISTOGRAM_ENUMERATION("ChildProcess.DisconnectedAlive2",
Wei-Yin Chen (陳威尹)3330991f2017-07-27 17:25:57524 static_cast<ProcessType>(data_.process_type),
[email protected]6d057a0c2013-07-09 21:12:07525 PROCESS_TYPE_MAX);
Nico Weber9dbefa62018-01-27 01:01:42526 break;
[email protected]6d057a0c2013-07-09 21:12:07527 }
528 default:
529 break;
[email protected]12fed812011-09-16 05:47:29530 }
Bo Liue9624612018-04-28 00:39:08531#endif // OS_ANDROID
[email protected]6d057a0c2013-07-09 21:12:07532 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Disconnected2",
Wei-Yin Chen (陳威尹)3330991f2017-07-27 17:25:57533 static_cast<ProcessType>(data_.process_type),
[email protected]6d057a0c2013-07-09 21:12:07534 PROCESS_TYPE_MAX);
oshima620225722015-06-04 19:45:27535#if defined(OS_CHROMEOS)
Bo Liu0d2a2322018-04-19 00:18:09536 if (info.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) {
oshima620225722015-06-04 19:45:27537 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM",
Wei-Yin Chen (陳威尹)3330991f2017-07-27 17:25:57538 static_cast<ProcessType>(data_.process_type),
oshima620225722015-06-04 19:45:27539 PROCESS_TYPE_MAX);
540 }
541#endif
[email protected]d27893f62010-07-03 05:47:42542 }
sadrul6c5aed8c2017-01-11 23:11:44543 channel_ = nullptr;
[email protected]4967f792012-01-20 22:14:40544 delete delegate_; // Will delete us
[email protected]a3a7e2c2011-09-16 23:07:05545}
546
[email protected]4c01d4992012-01-23 23:33:01547bool BrowserChildProcessHostImpl::Send(IPC::Message* message) {
[email protected]4cb43102011-12-02 20:24:49548 return child_process_host_->Send(message);
549}
550
bcwhiteb58a5fe2016-08-22 16:25:56551void BrowserChildProcessHostImpl::CreateMetricsAllocator() {
552 // Create a persistent memory segment for subprocess histograms only if
553 // they're active in the browser.
554 // TODO(bcwhite): Remove this once persistence is always enabled.
555 if (!base::GlobalHistogramAllocator::Get())
556 return;
557
558 // Determine the correct parameters based on the process type.
559 size_t memory_size;
560 base::StringPiece metrics_name;
561 switch (data_.process_type) {
bcwhite2496c83e2016-08-29 17:29:25562 case PROCESS_TYPE_UTILITY:
Matt Menkee5bc4a562017-08-07 23:58:22563 // This needs to be larger for the network service.
564 memory_size = 256 << 10; // 256 KiB
bcwhite2496c83e2016-08-29 17:29:25565 metrics_name = "UtilityMetrics";
566 break;
567
568 case PROCESS_TYPE_ZYGOTE:
bcwhite867f45532017-01-05 17:29:02569 memory_size = 64 << 10; // 64 KiB
bcwhite2496c83e2016-08-29 17:29:25570 metrics_name = "ZygoteMetrics";
571 break;
572
573 case PROCESS_TYPE_SANDBOX_HELPER:
bcwhite867f45532017-01-05 17:29:02574 memory_size = 64 << 10; // 64 KiB
bcwhite2496c83e2016-08-29 17:29:25575 metrics_name = "SandboxHelperMetrics";
576 break;
577
bcwhiteb58a5fe2016-08-22 16:25:56578 case PROCESS_TYPE_GPU:
Sadrul Habib Chowdhury2353ca522018-08-15 15:53:26579 // This needs to be larger for the display-compositor in the gpu process.
580 memory_size = 256 << 10; // 256 KiB
bcwhiteb58a5fe2016-08-22 16:25:56581 metrics_name = "GpuMetrics";
582 break;
583
bcwhite2496c83e2016-08-29 17:29:25584 case PROCESS_TYPE_PPAPI_PLUGIN:
bcwhite867f45532017-01-05 17:29:02585 memory_size = 64 << 10; // 64 KiB
bcwhite2496c83e2016-08-29 17:29:25586 metrics_name = "PpapiPluginMetrics";
587 break;
588
589 case PROCESS_TYPE_PPAPI_BROKER:
bcwhite867f45532017-01-05 17:29:02590 memory_size = 64 << 10; // 64 KiB
bcwhite2496c83e2016-08-29 17:29:25591 metrics_name = "PpapiBrokerMetrics";
592 break;
593
bcwhiteb58a5fe2016-08-22 16:25:56594 default:
595 return;
596 }
597
598 // Create the shared memory segment and attach an allocator to it.
599 // Mapping the memory shouldn't fail but be safe if it does; everything
600 // will continue to work but just as if persistence weren't available.
Alex Ilin30e7d062019-02-21 12:24:53601 base::WritableSharedMemoryRegion shm_region =
602 base::WritableSharedMemoryRegion::Create(memory_size);
603 base::WritableSharedMemoryMapping shm_mapping = shm_region.Map();
604 if (!shm_region.IsValid() || !shm_mapping.IsValid())
bcwhiteb58a5fe2016-08-22 16:25:56605 return;
Alex Ilin30e7d062019-02-21 12:24:53606 metrics_allocator_ =
607 std::make_unique<base::WritableSharedPersistentMemoryAllocator>(
608 std::move(shm_mapping), static_cast<uint64_t>(data_.id),
609 metrics_name);
610 metrics_shared_region_ = std::move(shm_region);
bcwhiteb58a5fe2016-08-22 16:25:56611}
612
613void BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess() {
614 if (metrics_allocator_) {
Nicholas Verne91bf4a632017-10-12 21:14:24615 HistogramController::GetInstance()->SetHistogramMemory<ChildProcessHost>(
Alex Ilin30e7d062019-02-21 12:24:53616 GetHost(), std::move(metrics_shared_region_));
Nicholas Verne91bf4a632017-10-12 21:14:24617 } else {
618 HistogramController::GetInstance()->SetHistogramMemory<ChildProcessHost>(
Alex Ilin30e7d062019-02-21 12:24:53619 GetHost(), base::WritableSharedMemoryRegion());
bcwhiteb58a5fe2016-08-22 16:25:56620 }
621}
622
wfh3adf87d2016-05-03 23:26:06623void BrowserChildProcessHostImpl::OnProcessLaunchFailed(int error_code) {
624 delegate_->OnProcessLaunchFailed(error_code);
amistry012289f2016-04-01 00:56:37625 notify_child_disconnected_ = false;
[email protected]fa01e472014-02-11 14:45:35626 delete delegate_; // Will delete us
627}
628
Min Qineb961902019-03-16 08:08:22629#if defined(OS_ANDROID)
630bool BrowserChildProcessHostImpl::CanUseWarmUpConnection() {
631 return can_use_warm_up_connection_;
632}
633#endif
634
[email protected]4c01d4992012-01-23 23:33:01635void BrowserChildProcessHostImpl::OnProcessLaunched() {
afakhry9cc79002015-10-22 19:25:15636 DCHECK_CURRENTLY_ON(BrowserThread::IO);
637
rvargas079d1842014-10-17 22:32:16638 const base::Process& process = child_process_->GetProcess();
639 DCHECK(process.IsValid());
[email protected]162a9fd2013-03-06 20:47:49640
rockotfe2fecc2017-01-19 20:16:19641 if (child_connection_)
David Bienvenuf47de5f12019-02-21 19:46:23642 child_connection_->SetProcess(process.Duplicate());
rockotfe2fecc2017-01-19 20:16:19643
jam3c8c50c2015-11-25 18:48:29644#if defined(OS_WIN)
[email protected]162a9fd2013-03-06 20:47:49645 // Start a WaitableEventWatcher that will invoke OnProcessExitedEarly if the
646 // child process exits. This watcher is stopped once the IPC channel is
647 // connected and the exit of the child process is detecter by an error on the
648 // IPC channel thereafter.
rvargas079d1842014-10-17 22:32:16649 DCHECK(!early_exit_watcher_.GetWatchedObject());
jam7fab1082015-09-29 02:26:18650 early_exit_watcher_.StartWatchingOnce(process.Handle(), this);
[email protected]162a9fd2013-03-06 20:47:49651#endif
652
Francois Doray884da022018-10-30 23:45:58653 data_.SetProcess(process.Duplicate());
[email protected]4967f792012-01-20 22:14:40654 delegate_->OnProcessLaunched();
afakhry9cc79002015-10-22 19:25:15655
656 if (is_channel_connected_) {
Sami Kyostila8e4d5a92019-08-02 12:45:05657 base::PostTask(
Eric Seckler8652dcd52018-09-20 10:42:28658 FROM_HERE, {BrowserThread::UI},
Bruce Dawson02f07de2018-07-31 17:28:26659 base::BindOnce(&NotifyProcessLaunchedAndConnected, data_.Duplicate()));
afakhry9cc79002015-10-22 19:25:15660 }
661}
662
Ken Rockotd7148c202019-09-18 18:00:59663void BrowserChildProcessHostImpl::RegisterCoordinatorClient(
664 mojo::PendingReceiver<memory_instrumentation::mojom::Coordinator> receiver,
665 mojo::PendingRemote<memory_instrumentation::mojom::ClientProcess>
666 client_process) {
667 base::PostTask(
668 FROM_HERE, BrowserThread::UI,
669 base::BindOnce(
670 [](mojo::PendingReceiver<memory_instrumentation::mojom::Coordinator>
671 receiver,
672 mojo::PendingRemote<memory_instrumentation::mojom::ClientProcess>
673 client_process,
674 memory_instrumentation::mojom::ProcessType process_type,
675 base::ProcessId process_id,
676 base::Optional<std::string> service_name) {
677 GetMemoryInstrumentationCoordinatorController()
678 ->RegisterClientProcess(std::move(receiver),
679 std::move(client_process), process_type,
680 process_id, std::move(service_name));
681 },
682 std::move(receiver), std::move(client_process),
683 GetCoordinatorClientProcessType(
684 static_cast<ProcessType>(data_.process_type)),
685 child_process_->GetProcess().Pid(), delegate_->GetServiceName()));
686}
687
afakhry9cc79002015-10-22 19:25:15688bool BrowserChildProcessHostImpl::IsProcessLaunched() const {
689 DCHECK_CURRENTLY_ON(BrowserThread::IO);
690
691 return child_process_.get() && child_process_->GetProcess().IsValid();
[email protected]d27893f62010-07-03 05:47:42692}
[email protected]130757672012-10-24 00:26:19693
rockot229fb28e2016-06-16 04:46:16694// static
695void BrowserChildProcessHostImpl::OnMojoError(
696 base::WeakPtr<BrowserChildProcessHostImpl> process,
697 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
698 const std::string& error) {
699 if (!task_runner->BelongsToCurrentThread()) {
700 task_runner->PostTask(
tzik4fea24af2017-08-23 11:41:47701 FROM_HERE, base::BindOnce(&BrowserChildProcessHostImpl::OnMojoError,
702 process, task_runner, error));
olka91f1d412016-11-21 15:24:53703 return;
rockot229fb28e2016-06-16 04:46:16704 }
705 if (!process)
706 return;
Wei-Yin Chen (陳威尹)223326c2017-07-21 02:08:28707 HistogramBadMessageTerminated(
708 static_cast<ProcessType>(process->data_.process_type));
rockot229fb28e2016-06-16 04:46:16709 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
710 switches::kDisableKillAfterBadIPC)) {
711 return;
712 }
713 LOG(ERROR) << "Terminating child process for bad Mojo message: " << error;
714
Yuzhu Shen32fcad72017-09-14 23:12:37715 // Create a memory dump with the error message captured in a crash key value.
716 // This will make it easy to determine details about what interface call
717 // failed.
Robert Sesek1419427e2017-12-07 15:01:32718 base::debug::ScopedCrashKeyString scoped_error_key(
719 bad_message::GetMojoErrorCrashKey(), error);
rockot229fb28e2016-06-16 04:46:16720 base::debug::DumpWithoutCrashing();
Bo Liue06143912018-04-20 20:42:30721 process->child_process_->Terminate(RESULT_CODE_KILLED_BAD_MESSAGE);
rockot229fb28e2016-06-16 04:46:16722}
723
[email protected]162a9fd2013-03-06 20:47:49724#if defined(OS_WIN)
725
rvargas079d1842014-10-17 22:32:16726void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) {
[email protected]162a9fd2013-03-06 20:47:49727 OnChildDisconnected();
728}
729
730#endif
731
[email protected]130757672012-10-24 00:26:19732} // namespace content