Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. | 119 // TODO(phajdan.jr): Check thread after fixing http://crbug.com/167126. |
| 120 g_observers.Get().RemoveObserver(observer); | 120 g_observers.Get().RemoveObserver(observer); |
| 121 } | 121 } |
| 122 | 122 |
| 123 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( | 123 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( |
| 124 content::ProcessType process_type, | 124 content::ProcessType process_type, |
| 125 BrowserChildProcessHostDelegate* delegate) | 125 BrowserChildProcessHostDelegate* delegate) |
| 126 : data_(process_type), | 126 : data_(process_type), |
| 127 delegate_(delegate), | 127 delegate_(delegate), |
| 128 power_monitor_message_broadcaster_(this), | 128 power_monitor_message_broadcaster_(this), |
| 129 is_channel_connected_(false) { | 129 is_channel_connected_(false), |
| 130 notify_child_disconnected_(false) { | |
| 130 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); | 131 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); |
| 131 | 132 |
| 132 #if USE_ATTACHMENT_BROKER | 133 #if USE_ATTACHMENT_BROKER |
| 133 // Construct the privileged attachment broker early in the life cycle of a | 134 // Construct the privileged attachment broker early in the life cycle of a |
| 134 // child process. This ensures that when a test is being run in one of the | 135 // child process. This ensures that when a test is being run in one of the |
| 135 // single process modes, the global attachment broker is the privileged | 136 // single process modes, the global attachment broker is the privileged |
| 136 // attachment broker, rather than an unprivileged attachment broker. | 137 // attachment broker, rather than an unprivileged attachment broker. |
| 137 #if defined(OS_MACOSX) | 138 #if defined(OS_MACOSX) |
| 138 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | 139 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( |
| 139 MachBroker::GetInstance()); | 140 MachBroker::GetInstance()); |
| 140 #else | 141 #else |
| 141 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | 142 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
| 142 #endif // defined(OS_MACOSX) | 143 #endif // defined(OS_MACOSX) |
| 143 #endif // USE_ATTACHMENT_BROKER | 144 #endif // USE_ATTACHMENT_BROKER |
| 144 | 145 |
| 145 child_process_host_.reset(ChildProcessHost::Create(this)); | 146 child_process_host_.reset(ChildProcessHost::Create(this)); |
| 146 AddFilter(new TraceMessageFilter(data_.id)); | 147 AddFilter(new TraceMessageFilter(data_.id)); |
| 147 AddFilter(new ProfilerMessageFilter(process_type)); | 148 AddFilter(new ProfilerMessageFilter(process_type)); |
| 148 AddFilter(new HistogramMessageFilter); | 149 AddFilter(new HistogramMessageFilter); |
| 149 AddFilter(new MemoryMessageFilter(this, process_type)); | 150 AddFilter(new MemoryMessageFilter(this, process_type)); |
| 150 | 151 |
| 151 g_child_process_list.Get().push_back(this); | 152 g_child_process_list.Get().push_back(this); |
| 152 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); | 153 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); |
| 153 | 154 |
| 154 power_monitor_message_broadcaster_.Init(); | 155 power_monitor_message_broadcaster_.Init(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { | 158 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { |
| 158 g_child_process_list.Get().remove(this); | 159 g_child_process_list.Get().remove(this); |
| 160 | |
| 161 if (notify_child_disconnected_) { | |
| 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 163 base::Bind(&NotifyProcessHostDisconnected, data_)); | |
| 164 } | |
| 159 } | 165 } |
| 160 | 166 |
| 161 // static | 167 // static |
| 162 void BrowserChildProcessHostImpl::TerminateAll() { | 168 void BrowserChildProcessHostImpl::TerminateAll() { |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 169 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 164 // Make a copy since the BrowserChildProcessHost dtor mutates the original | 170 // Make a copy since the BrowserChildProcessHost dtor mutates the original |
| 165 // list. | 171 // list. |
| 166 BrowserChildProcessList copy = g_child_process_list.Get(); | 172 BrowserChildProcessList copy = g_child_process_list.Get(); |
| 167 for (BrowserChildProcessList::iterator it = copy.begin(); | 173 for (BrowserChildProcessList::iterator it = copy.begin(); |
| 168 it != copy.end(); ++it) { | 174 it != copy.end(); ++it) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 186 switches::kEnableLogging, | 192 switches::kEnableLogging, |
| 187 switches::kIPCConnectionTimeout, | 193 switches::kIPCConnectionTimeout, |
| 188 switches::kLoggingLevel, | 194 switches::kLoggingLevel, |
| 189 switches::kTraceToConsole, | 195 switches::kTraceToConsole, |
| 190 switches::kV, | 196 switches::kV, |
| 191 switches::kVModule, | 197 switches::kVModule, |
| 192 }; | 198 }; |
| 193 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | 199 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, |
| 194 arraysize(kForwardSwitches)); | 200 arraysize(kForwardSwitches)); |
| 195 | 201 |
| 202 notify_child_disconnected_ = true; | |
|
ncarter (slow)
2016/03/31 16:06:15
Actually, is this line necessary? If we're only no
Anand Mistry (off Chromium)
2016/03/31 18:51:33
I believe so. I thought about this, but then I not
ncarter (slow)
2016/03/31 20:17:31
That comment is correct: OnProcessLaunched() can o
Anand Mistry (off Chromium)
2016/03/31 22:14:10
It seems that the current behaviour isn't balanced
| |
| 196 child_process_.reset(new ChildProcessLauncher( | 203 child_process_.reset(new ChildProcessLauncher( |
| 197 delegate, | 204 delegate, |
| 198 cmd_line, | 205 cmd_line, |
| 199 data_.id, | 206 data_.id, |
| 200 this, | 207 this, |
| 201 terminate_on_shutdown)); | 208 terminate_on_shutdown)); |
| 202 } | 209 } |
| 203 | 210 |
| 204 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { | 211 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { |
| 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 280 |
| 274 bool BrowserChildProcessHostImpl::OnMessageReceived( | 281 bool BrowserChildProcessHostImpl::OnMessageReceived( |
| 275 const IPC::Message& message) { | 282 const IPC::Message& message) { |
| 276 return delegate_->OnMessageReceived(message); | 283 return delegate_->OnMessageReceived(message); |
| 277 } | 284 } |
| 278 | 285 |
| 279 void BrowserChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) { | 286 void BrowserChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) { |
| 280 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 287 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 281 | 288 |
| 282 is_channel_connected_ = true; | 289 is_channel_connected_ = true; |
| 290 notify_child_disconnected_ = true; | |
| 283 | 291 |
| 284 #if defined(OS_WIN) | 292 #if defined(OS_WIN) |
| 285 // From this point onward, the exit of the child process is detected by an | 293 // From this point onward, the exit of the child process is detected by an |
| 286 // error on the IPC channel. | 294 // error on the IPC channel. |
| 287 early_exit_watcher_.StopWatching(); | 295 early_exit_watcher_.StopWatching(); |
| 288 #endif | 296 #endif |
| 289 | 297 |
| 290 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 298 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 291 base::Bind(&NotifyProcessHostConnected, data_)); | 299 base::Bind(&NotifyProcessHostConnected, data_)); |
| 292 | 300 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 data_.process_type, | 388 data_.process_type, |
| 381 PROCESS_TYPE_MAX); | 389 PROCESS_TYPE_MAX); |
| 382 #if defined(OS_CHROMEOS) | 390 #if defined(OS_CHROMEOS) |
| 383 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { | 391 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { |
| 384 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", | 392 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", |
| 385 data_.process_type, | 393 data_.process_type, |
| 386 PROCESS_TYPE_MAX); | 394 PROCESS_TYPE_MAX); |
| 387 } | 395 } |
| 388 #endif | 396 #endif |
| 389 } | 397 } |
| 390 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 391 base::Bind(&NotifyProcessHostDisconnected, data_)); | |
| 392 delete delegate_; // Will delete us | 398 delete delegate_; // Will delete us |
| 393 } | 399 } |
| 394 | 400 |
| 395 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { | 401 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { |
| 396 return child_process_host_->Send(message); | 402 return child_process_host_->Send(message); |
| 397 } | 403 } |
| 398 | 404 |
| 399 void BrowserChildProcessHostImpl::OnProcessLaunchFailed() { | 405 void BrowserChildProcessHostImpl::OnProcessLaunchFailed() { |
| 400 delegate_->OnProcessLaunchFailed(); | 406 delegate_->OnProcessLaunchFailed(); |
| 407 notify_child_disconnected_ = false; | |
| 401 delete delegate_; // Will delete us | 408 delete delegate_; // Will delete us |
| 402 } | 409 } |
| 403 | 410 |
| 404 void BrowserChildProcessHostImpl::OnProcessLaunched() { | 411 void BrowserChildProcessHostImpl::OnProcessLaunched() { |
| 405 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 412 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 406 | 413 |
| 407 const base::Process& process = child_process_->GetProcess(); | 414 const base::Process& process = child_process_->GetProcess(); |
| 408 DCHECK(process.IsValid()); | 415 DCHECK(process.IsValid()); |
| 409 | 416 |
| 410 mojo::edk::ScopedPlatformHandle client_pipe = | 417 mojo::edk::ScopedPlatformHandle client_pipe = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 440 | 447 |
| 441 #if defined(OS_WIN) | 448 #if defined(OS_WIN) |
| 442 | 449 |
| 443 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 450 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
| 444 OnChildDisconnected(); | 451 OnChildDisconnected(); |
| 445 } | 452 } |
| 446 | 453 |
| 447 #endif | 454 #endif |
| 448 | 455 |
| 449 } // namespace content | 456 } // namespace content |
| OLD | NEW |