]> khamidou — GitHub mirrors - electron.git/commitdiff
Make sure browserWindow.destroy() doesn't leave zombie processes.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 4 Dec 2013 14:00:20 +0000 (22:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 4 Dec 2013 14:00:20 +0000 (22:00 +0800)
browser/api/atom_api_window.cc
browser/native_window.cc
browser/native_window.h

index a0262592ed87a8a9b342e8d922b5d9033baf0f71..c05493ca96723eae0d59c3ee067feed9b676df78 100644 (file)
@@ -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<v8::Value> Window::New(const v8::Arguments &args) {
 v8::Handle<v8::Value> 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();
 }
 
index e8c337c01fe9c7bae1d65a9e9aec673857431282..99e89d57320c74b1a414e10e8dcb864a40da50d9 100644 (file)
@@ -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(
index d3ea4312c2fe23e5a94c7433056d67b17d8311c6..c7d1169cdc3d973fc3dfd8eba3525d1ff68c579e 100644 (file)
@@ -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,