| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 g_observers.Get().RemoveObserver(observer); | 154 g_observers.Get().RemoveObserver(observer); |
| 155 } | 155 } |
| 156 | 156 |
| 157 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( | 157 BrowserChildProcessHostImpl::BrowserChildProcessHostImpl( |
| 158 content::ProcessType process_type, | 158 content::ProcessType process_type, |
| 159 BrowserChildProcessHostDelegate* delegate, | 159 BrowserChildProcessHostDelegate* delegate, |
| 160 const std::string& service_name) | 160 const std::string& service_name) |
| 161 : data_(process_type), | 161 : data_(process_type), |
| 162 delegate_(delegate), | 162 delegate_(delegate), |
| 163 child_token_(mojo::edk::GenerateRandomToken()), | 163 child_token_(mojo::edk::GenerateRandomToken()), |
| 164 channel_(nullptr), |
| 164 is_channel_connected_(false), | 165 is_channel_connected_(false), |
| 165 notify_child_disconnected_(false), | 166 notify_child_disconnected_(false), |
| 166 weak_factory_(this) { | 167 weak_factory_(this) { |
| 167 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); | 168 data_.id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); |
| 168 | 169 |
| 169 child_process_host_.reset(ChildProcessHost::Create(this)); | 170 child_process_host_.reset(ChildProcessHost::Create(this)); |
| 170 AddFilter(new TraceMessageFilter(data_.id)); | 171 AddFilter(new TraceMessageFilter(data_.id)); |
| 171 AddFilter(new ProfilerMessageFilter(process_type)); | 172 AddFilter(new ProfilerMessageFilter(process_type)); |
| 172 AddFilter(new HistogramMessageFilter); | 173 AddFilter(new HistogramMessageFilter); |
| 173 AddFilter(new MemoryMessageFilter(this, process_type)); | 174 AddFilter(new MemoryMessageFilter(this, process_type)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // what the bad message was. | 390 // what the bad message was. |
| 390 base::debug::DumpWithoutCrashing(); | 391 base::debug::DumpWithoutCrashing(); |
| 391 | 392 |
| 392 child_process_->GetProcess().Terminate(RESULT_CODE_KILLED_BAD_MESSAGE, false); | 393 child_process_->GetProcess().Terminate(RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 393 } | 394 } |
| 394 | 395 |
| 395 bool BrowserChildProcessHostImpl::CanShutdown() { | 396 bool BrowserChildProcessHostImpl::CanShutdown() { |
| 396 return delegate_->CanShutdown(); | 397 return delegate_->CanShutdown(); |
| 397 } | 398 } |
| 398 | 399 |
| 400 void BrowserChildProcessHostImpl::OnChannelInitialized(IPC::Channel* channel) { |
| 401 channel_ = channel; |
| 402 } |
| 403 |
| 399 void BrowserChildProcessHostImpl::OnChildDisconnected() { | 404 void BrowserChildProcessHostImpl::OnChildDisconnected() { |
| 400 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 405 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 401 #if defined(OS_WIN) | 406 #if defined(OS_WIN) |
| 402 // OnChildDisconnected may be called without OnChannelConnected, so stop the | 407 // OnChildDisconnected may be called without OnChannelConnected, so stop the |
| 403 // early exit watcher so GetTerminationStatus can close the process handle. | 408 // early exit watcher so GetTerminationStatus can close the process handle. |
| 404 early_exit_watcher_.StopWatching(); | 409 early_exit_watcher_.StopWatching(); |
| 405 #endif | 410 #endif |
| 406 if (child_process_.get() || data_.handle) { | 411 if (child_process_.get() || data_.handle) { |
| 407 int exit_code; | 412 int exit_code; |
| 408 base::TerminationStatus status = GetTerminationStatus( | 413 base::TerminationStatus status = GetTerminationStatus( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 data_.process_type, | 453 data_.process_type, |
| 449 PROCESS_TYPE_MAX); | 454 PROCESS_TYPE_MAX); |
| 450 #if defined(OS_CHROMEOS) | 455 #if defined(OS_CHROMEOS) |
| 451 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { | 456 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { |
| 452 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", | 457 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", |
| 453 data_.process_type, | 458 data_.process_type, |
| 454 PROCESS_TYPE_MAX); | 459 PROCESS_TYPE_MAX); |
| 455 } | 460 } |
| 456 #endif | 461 #endif |
| 457 } | 462 } |
| 463 channel_ = nullptr; |
| 458 delete delegate_; // Will delete us | 464 delete delegate_; // Will delete us |
| 459 } | 465 } |
| 460 | 466 |
| 461 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { | 467 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { |
| 462 return child_process_host_->Send(message); | 468 return child_process_host_->Send(message); |
| 463 } | 469 } |
| 464 | 470 |
| 465 void BrowserChildProcessHostImpl::CreateMetricsAllocator() { | 471 void BrowserChildProcessHostImpl::CreateMetricsAllocator() { |
| 466 // Create a persistent memory segment for subprocess histograms only if | 472 // Create a persistent memory segment for subprocess histograms only if |
| 467 // they're active in the browser. | 473 // they're active in the browser. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 606 |
| 601 #if defined(OS_WIN) | 607 #if defined(OS_WIN) |
| 602 | 608 |
| 603 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 609 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
| 604 OnChildDisconnected(); | 610 OnChildDisconnected(); |
| 605 } | 611 } |
| 606 | 612 |
| 607 #endif | 613 #endif |
| 608 | 614 |
| 609 } // namespace content | 615 } // namespace content |
| OLD | NEW |