diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-10 20:53:11 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-10 20:53:11 +0000 |
commit | 219b56462b4589bcbf513568033a3f24bdb29fdf (patch) | |
tree | f7d3c0d8b8c6052ac85c03eb702e238dc3dd7b56 /chrome | |
parent | 7d2751d59294a8ea3ef67987ae7469ca4e6af935 (diff) | |
download | chromium_src-219b56462b4589bcbf513568033a3f24bdb29fdf.zip chromium_src-219b56462b4589bcbf513568033a3f24bdb29fdf.tar.gz chromium_src-219b56462b4589bcbf513568033a3f24bdb29fdf.tar.bz2 |
plugins: use OnChannelError to detect when the channel goes away
Previously we used a special Watcher object to watch the process,
but that is not portable to POSIX and this is simpler anyway.
With this change, I now see ~PluginProcessHost() running when a
plugin crashes.
If you recall all the way back to
http://codereview.chromium.org/16814
we did a similar thing to the renderer host.
Review URL: http://codereview.chromium.org/155331
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/utility_process_host.cc | 1 | ||||
-rw-r--r-- | chrome/browser/utility_process_host_unittest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/worker_host/worker_process_host.cc | 1 | ||||
-rw-r--r-- | chrome/common/child_process_host.cc | 33 | ||||
-rw-r--r-- | chrome/common/child_process_host.h | 11 |
5 files changed, 19 insertions, 33 deletions
diff --git a/chrome/browser/utility_process_host.cc b/chrome/browser/utility_process_host.cc index 0d9aaa6..84f506a 100644 --- a/chrome/browser/utility_process_host.cc +++ b/chrome/browser/utility_process_host.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/file_util.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" #include "base/task.h" diff --git a/chrome/browser/utility_process_host_unittest.cc b/chrome/browser/utility_process_host_unittest.cc index b813cb5..426f8ba 100644 --- a/chrome/browser/utility_process_host_unittest.cc +++ b/chrome/browser/utility_process_host_unittest.cc @@ -106,8 +106,10 @@ TEST_F(UtilityProcessHostTest, ExtensionUnpacker) { scoped_refptr<TestUtilityProcessHostClient> client( new TestUtilityProcessHostClient(&message_loop_)); ResourceDispatcherHost rdh(NULL); - TestUtilityProcessHost process_host(client.get(), &message_loop_, &rdh); - process_host.StartExtensionUnpacker( + TestUtilityProcessHost* process_host = + new TestUtilityProcessHost(client.get(), &message_loop_, &rdh); + // process_host will delete itself when it's done. + process_host->StartExtensionUnpacker( temp_extension_dir.AppendASCII("theme.crx")); message_loop_.Run(); EXPECT_TRUE(client->success()); diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index 9672dd1..017ea86 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -8,6 +8,7 @@ #include "base/command_line.h" #include "base/debug_util.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" #include "base/string_util.h" diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc index c2c925e..67d9a5a 100644 --- a/chrome/common/child_process_host.cc +++ b/chrome/common/child_process_host.cc @@ -51,8 +51,7 @@ ChildProcessHost::ChildProcessHost( : Receiver(type), ALLOW_THIS_IN_INITIALIZER_LIST(listener_(this)), resource_dispatcher_host_(resource_dispatcher_host), - opening_channel_(false), - process_event_(NULL) { + opening_channel_(false) { Singleton<ChildProcessList>::get()->push_back(this); } @@ -62,16 +61,8 @@ ChildProcessHost::~ChildProcessHost() { resource_dispatcher_host_->CancelRequestsForProcess(GetProcessId()); - if (handle()) { - watcher_.StopWatching(); + if (handle()) ProcessWatcher::EnsureProcessTerminated(handle()); - -#if defined(OS_WIN) - // Above call took ownership, so don't want WaitableEvent to assert because - // the handle isn't valid anymore. - process_event_->Release(); -#endif - } } bool ChildProcessHost::CreateChannel() { @@ -87,13 +78,8 @@ bool ChildProcessHost::CreateChannel() { } void ChildProcessHost::SetHandle(base::ProcessHandle process) { -#if defined(OS_WIN) - process_event_.reset(new base::WaitableEvent(process)); - DCHECK(!handle()); set_handle(process); - watcher_.StartWatching(process_event_.get(), this); -#endif } void ChildProcessHost::InstanceCreated() { @@ -113,20 +99,20 @@ void ChildProcessHost::Notify(NotificationType type) { FROM_HERE, new ChildNotificationTask(type, this)); } -void ChildProcessHost::OnWaitableEventSignaled(base::WaitableEvent *event) { -#if defined(OS_WIN) - HANDLE object = event->handle(); +void ChildProcessHost::OnChildDied() { DCHECK(handle()); - DCHECK_EQ(object, handle()); - bool did_crash = base::DidProcessCrash(NULL, object); + bool did_crash = base::DidProcessCrash(NULL, handle()); if (did_crash) { // Report that this child process crashed. Notify(NotificationType::CHILD_PROCESS_CRASHED); } // Notify in the main loop of the disconnection. Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); -#endif + + // On POSIX, once we've called DidProcessCrash, handle() is no longer + // valid. Ensure the destructor doesn't try to use it. + set_handle(NULL); delete this; } @@ -185,6 +171,9 @@ void ChildProcessHost::ListenerHook::OnChannelConnected(int32 peer_pid) { void ChildProcessHost::ListenerHook::OnChannelError() { host_->opening_channel_ = false; host_->OnChannelError(); + + // This will delete host_, which will also destroy this! + host_->OnChildDied(); } diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h index caabe66..3b97200 100644 --- a/chrome/common/child_process_host.h +++ b/chrome/common/child_process_host.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" -#include "base/waitable_event_watcher.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/common/ipc_channel.h" @@ -19,7 +18,6 @@ class NotificationType; // Plugins/workers and other child processes that live on the IO thread should // derive from this class. class ChildProcessHost : public ResourceDispatcherHost::Receiver, - public base::WaitableEventWatcher::Delegate, public IPC::Channel::Listener { public: virtual ~ChildProcessHost(); @@ -78,8 +76,8 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, // Sends the given notification to the notification service on the UI thread. void Notify(NotificationType type); - // WaitableEventWatcher::Delegate implementation: - virtual void OnWaitableEventSignaled(base::WaitableEvent *event); + // Called when the child process goes away. + void OnChildDied(); // By using an internal class as the IPC::Channel::Listener, we can intercept // OnMessageReceived/OnChannelConnected and do our own processing before @@ -106,11 +104,6 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver, // IPC Channel's id. std::string channel_id_; - - // Used to watch the child process handle. - base::WaitableEventWatcher watcher_; - - scoped_ptr<base::WaitableEvent> process_event_; }; #endif // CHROME_COMMON_CHILD_PROCESS_HOST_H_ |