From e45f83e62a877316e1b8fb0021b2732e6c4fa9d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 4 Dec 2013 22:00:20 +0800 Subject: [PATCH] Make sure browserWindow.destroy() doesn't leave zombie processes. --- browser/api/atom_api_window.cc | 8 ++++++++ browser/native_window.cc | 4 ++++ browser/native_window.h | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index a0262592..c05493ca 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -4,6 +4,7 @@ #include "browser/api/atom_api_window.h" +#include "base/process_util.h" #include "base/values.h" #include "browser/native_window.h" #include "common/v8_conversions.h" @@ -126,8 +127,15 @@ v8::Handle Window::New(const v8::Arguments &args) { v8::Handle Window::Destroy(const v8::Arguments &args) { UNWRAP_WINDOW_AND_CHECK; + base::ProcessHandle handle = self->window_->GetRenderProcessHandle(); delete self; + // Check if the render process is terminated, it could happen that the render + // became a zombie. + if (!base::WaitForSingleProcess(handle, + base::TimeDelta::FromMilliseconds(500))) + base::KillProcess(handle, 0, true); + return v8::Undefined(); } diff --git a/browser/native_window.cc b/browser/native_window.cc index e8c337c0..99e89d57 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -199,6 +199,10 @@ bool NativeWindow::SetIcon(const std::string& str_path) { return true; } +base::ProcessHandle NativeWindow::GetRenderProcessHandle() { + return GetWebContents()->GetRenderProcessHost()->GetHandle(); +} + void NativeWindow::CapturePage(const gfx::Rect& rect, const CapturePageCallback& callback) { GetWebContents()->GetRenderViewHost()->CopyFromBackingStore( diff --git a/browser/native_window.h b/browser/native_window.h index d3ea4312..c7d1169c 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -114,6 +114,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void RestartHangMonitorTimeout(); virtual bool SetIcon(const std::string& path); + // Returns the process handle of render process, useful for killing the + // render process manually + virtual base::ProcessHandle GetRenderProcessHandle(); + // Captures the page with |rect|, |callback| would be called when capturing is // done. virtual void CapturePage(const gfx::Rect& rect, -- 2.43.0