| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // what the bad message was. | 391 // what the bad message was. |
| 391 base::debug::DumpWithoutCrashing(); | 392 base::debug::DumpWithoutCrashing(); |
| 392 | 393 |
| 393 child_process_->GetProcess().Terminate(RESULT_CODE_KILLED_BAD_MESSAGE, false); | 394 child_process_->GetProcess().Terminate(RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 394 } | 395 } |
| 395 | 396 |
| 396 bool BrowserChildProcessHostImpl::CanShutdown() { | 397 bool BrowserChildProcessHostImpl::CanShutdown() { |
| 397 return delegate_->CanShutdown(); | 398 return delegate_->CanShutdown(); |
| 398 } | 399 } |
| 399 | 400 |
| 401 void BrowserChildProcessHostImpl::OnChannelInitialized(IPC::Channel* channel) { |
| 402 channel_ = channel; |
| 403 } |
| 404 |
| 400 void BrowserChildProcessHostImpl::OnChildDisconnected() { | 405 void BrowserChildProcessHostImpl::OnChildDisconnected() { |
| 401 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 406 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 402 #if defined(OS_WIN) | 407 #if defined(OS_WIN) |
| 403 // OnChildDisconnected may be called without OnChannelConnected, so stop the | 408 // OnChildDisconnected may be called without OnChannelConnected, so stop the |
| 404 // early exit watcher so GetTerminationStatus can close the process handle. | 409 // early exit watcher so GetTerminationStatus can close the process handle. |
| 405 early_exit_watcher_.StopWatching(); | 410 early_exit_watcher_.StopWatching(); |
| 406 #endif | 411 #endif |
| 407 if (child_process_.get() || data_.handle) { | 412 if (child_process_.get() || data_.handle) { |
| 408 int exit_code; | 413 int exit_code; |
| 409 base::TerminationStatus status = GetTerminationStatus( | 414 base::TerminationStatus status = GetTerminationStatus( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 data_.process_type, | 454 data_.process_type, |
| 450 PROCESS_TYPE_MAX); | 455 PROCESS_TYPE_MAX); |
| 451 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
| 452 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { | 457 if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM) { |
| 453 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", | 458 UMA_HISTOGRAM_ENUMERATION("ChildProcess.Killed2.OOM", |
| 454 data_.process_type, | 459 data_.process_type, |
| 455 PROCESS_TYPE_MAX); | 460 PROCESS_TYPE_MAX); |
| 456 } | 461 } |
| 457 #endif | 462 #endif |
| 458 } | 463 } |
| 464 channel_ = nullptr; |
| 459 delete delegate_; // Will delete us | 465 delete delegate_; // Will delete us |
| 460 } | 466 } |
| 461 | 467 |
| 462 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { | 468 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { |
| 463 return child_process_host_->Send(message); | 469 return child_process_host_->Send(message); |
| 464 } | 470 } |
| 465 | 471 |
| 466 void BrowserChildProcessHostImpl::CreateMetricsAllocator() { | 472 void BrowserChildProcessHostImpl::CreateMetricsAllocator() { |
| 467 // Create a persistent memory segment for subprocess histograms only if | 473 // Create a persistent memory segment for subprocess histograms only if |
| 468 // they're active in the browser. | 474 // they're active in the browser. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 607 |
| 602 #if defined(OS_WIN) | 608 #if defined(OS_WIN) |
| 603 | 609 |
| 604 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 610 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
| 605 OnChildDisconnected(); | 611 OnChildDisconnected(); |
| 606 } | 612 } |
| 607 | 613 |
| 608 #endif | 614 #endif |
| 609 | 615 |
| 610 } // namespace content | 616 } // namespace content |
| OLD | NEW |