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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 child_process_host_->AddFilter(new TraceMessageFilter); | 79 child_process_host_->AddFilter(new TraceMessageFilter); |
80 child_process_host_->AddFilter(new ProfilerMessageFilter(type)); | 80 child_process_host_->AddFilter(new ProfilerMessageFilter(type)); |
81 child_process_host_->AddFilter(new HistogramMessageFilter()); | 81 child_process_host_->AddFilter(new HistogramMessageFilter()); |
82 | 82 |
83 g_child_process_list.Get().push_back(this); | 83 g_child_process_list.Get().push_back(this); |
84 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); | 84 GetContentClient()->browser()->BrowserChildProcessHostCreated(this); |
85 } | 85 } |
86 | 86 |
87 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { | 87 BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() { |
88 g_child_process_list.Get().remove(this); | 88 g_child_process_list.Get().remove(this); |
89 | |
90 #if defined(OS_WIN) | |
91 // The WaitableEvent takes ownership of its handle so release it here to | |
92 // avoid a double free. | |
93 if (process_waitable_event_.get()) | |
94 process_waitable_event_->Release(); | |
cpu_(ooo_6.6-7.5)
2013/03/04 22:46:59
call GetWatchedEvent to obtain this?
apatrick_chromium
2013/03/05 00:22:41
Done.
| |
95 #endif | |
89 } | 96 } |
90 | 97 |
91 // static | 98 // static |
92 void BrowserChildProcessHostImpl::TerminateAll() { | 99 void BrowserChildProcessHostImpl::TerminateAll() { |
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
94 // Make a copy since the BrowserChildProcessHost dtor mutates the original | 101 // Make a copy since the BrowserChildProcessHost dtor mutates the original |
95 // list. | 102 // list. |
96 BrowserChildProcessList copy = g_child_process_list.Get(); | 103 BrowserChildProcessList copy = g_child_process_list.Get(); |
97 for (BrowserChildProcessList::iterator it = copy.begin(); | 104 for (BrowserChildProcessList::iterator it = copy.begin(); |
98 it != copy.end(); ++it) { | 105 it != copy.end(); ++it) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 } | 206 } |
200 | 207 |
201 bool BrowserChildProcessHostImpl::OnMessageReceived( | 208 bool BrowserChildProcessHostImpl::OnMessageReceived( |
202 const IPC::Message& message) { | 209 const IPC::Message& message) { |
203 return delegate_->OnMessageReceived(message); | 210 return delegate_->OnMessageReceived(message); |
204 } | 211 } |
205 | 212 |
206 void BrowserChildProcessHostImpl::OnChannelConnected(int32 peer_pid) { | 213 void BrowserChildProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
207 Notify(NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED); | 214 Notify(NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED); |
208 delegate_->OnChannelConnected(peer_pid); | 215 delegate_->OnChannelConnected(peer_pid); |
216 | |
217 #if defined(OS_WIN) | |
218 // From this point onward, the exit of the child process is detected by an | |
219 // error on the IPC channel. | |
220 early_exit_watcher_.StopWatching(); | |
cpu_(ooo_6.6-7.5)
2013/03/04 22:46:59
maybe this ahead of the delegate_ call?
apatrick_chromium
2013/03/05 00:22:41
Done.
| |
221 #endif | |
209 } | 222 } |
210 | 223 |
211 void BrowserChildProcessHostImpl::OnChannelError() { | 224 void BrowserChildProcessHostImpl::OnChannelError() { |
212 delegate_->OnChannelError(); | 225 delegate_->OnChannelError(); |
213 } | 226 } |
214 | 227 |
215 bool BrowserChildProcessHostImpl::CanShutdown() { | 228 bool BrowserChildProcessHostImpl::CanShutdown() { |
216 return delegate_->CanShutdown(); | 229 return delegate_->CanShutdown(); |
217 } | 230 } |
218 | 231 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 270 |
258 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { | 271 bool BrowserChildProcessHostImpl::Send(IPC::Message* message) { |
259 return child_process_host_->Send(message); | 272 return child_process_host_->Send(message); |
260 } | 273 } |
261 | 274 |
262 void BrowserChildProcessHostImpl::OnProcessLaunched() { | 275 void BrowserChildProcessHostImpl::OnProcessLaunched() { |
263 if (!child_process_->GetHandle()) { | 276 if (!child_process_->GetHandle()) { |
264 delete delegate_; // Will delete us | 277 delete delegate_; // Will delete us |
265 return; | 278 return; |
266 } | 279 } |
280 | |
281 #if defined(OS_WIN) | |
282 // Start a WaitableEventWatcher that will invoke OnProcessExitedEarly if the | |
283 // child process exits. This watcher is stopped once the IPC channel is | |
284 // connected and the exit of the child process is detecter by an error on the | |
285 // IPC channel thereafter. | |
286 process_waitable_event_.reset( | |
cpu_(ooo_6.6-7.5)
2013/03/04 22:46:59
do we really need the process_waitable_event_ as a
apatrick_chromium
2013/03/05 00:22:41
Done.
| |
287 new base::WaitableEvent(child_process_->GetHandle())); | |
288 early_exit_watcher_.StartWatching( | |
289 process_waitable_event_.get(), | |
290 base::Bind(&BrowserChildProcessHostImpl::OnProcessExitedEarly, | |
291 base::Unretained(this))); | |
292 #endif | |
293 | |
267 data_.handle = child_process_->GetHandle(); | 294 data_.handle = child_process_->GetHandle(); |
268 delegate_->OnProcessLaunched(); | 295 delegate_->OnProcessLaunched(); |
269 } | 296 } |
270 | 297 |
298 void BrowserChildProcessHostImpl::OnProcessExitedEarly( | |
299 base::WaitableEvent* event) { | |
300 OnChildDisconnected(); | |
301 } | |
302 | |
271 } // namespace content | 303 } // namespace content |
OLD | NEW |