Browse Source

feat: add child-process-gone event to app (#24367)

Milan Burda 4 years ago
parent
commit
fa1323d6cd
3 changed files with 56 additions and 1 deletions
  1. 36 1
      docs/api/app.md
  2. 16 0
      shell/browser/api/electron_api_app.cc
  3. 4 0
      shell/browser/api/electron_api_app.h

+ 36 - 1
docs/api/app.md

@@ -360,7 +360,7 @@ page.
 
 Emitted whenever there is a GPU info update.
 
-### Event: 'gpu-process-crashed'
+### Event: 'gpu-process-crashed' _Deprecated_
 
 Returns:
 
@@ -369,6 +369,11 @@ Returns:
 
 Emitted when the GPU process crashes or is killed.
 
+**Deprecated:** This event is superceded by the `child-process-gone` event
+which contains more information about why the child process dissapeared. It
+isn't always because it crashed. The `killed` boolean can be replaced by
+checking `reason === 'killed'` when you switch to that event.
+
 ### Event: 'renderer-process-crashed' _Deprecated_
 
 Returns:
@@ -403,6 +408,36 @@ Returns:
 Emitted when the renderer process unexpectedly dissapears.  This is normally
 because it was crashed or killed.
 
+#### Event: 'child-process-gone'
+
+Returns:
+
+* `event` Event
+* `details` Object
+  * `type` String - Process type. One of the following values:
+    * `Utility`
+    * `Zygote`
+    * `Sandbox helper`
+    * `GPU`
+    * `Pepper Plugin`
+    * `Pepper Plugin Broker`
+    * `Unknown`
+  * `reason` String - The reason the child process is gone. Possible values:
+    * `clean-exit` - Process exited with an exit code of zero
+    * `abnormal-exit` - Process exited with a non-zero exit code
+    * `killed` - Process was sent a SIGTERM or otherwise killed externally
+    * `crashed` - Process crashed
+    * `oom` - Process ran out of memory
+    * `launch-failure` - Process never successfully launched
+    * `integrity-failure` - Windows code integrity checks failed
+  * `exitCode` Number - The exit code for the process
+      (e.g. status from waitpid if on posix, from GetExitCodeProcess on Windows).
+  * `name` String (optional) - The name of the process. i.e. for plugins it might be Flash.
+    Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc.
+
+Emitted when the child process unexpectedly dissapears. This is normally
+because it was crashed or killed. It does not include renderer processes.
+
 ### Event: 'accessibility-support-changed' _macOS_ _Windows_
 
 Returns:

+ 16 - 0
shell/browser/api/electron_api_app.cc

@@ -803,12 +803,28 @@ void App::BrowserChildProcessCrashed(
     const content::ChildProcessData& data,
     const content::ChildProcessTerminationInfo& info) {
   ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
+  BrowserChildProcessCrashedOrKilled(data, info);
 }
 
 void App::BrowserChildProcessKilled(
     const content::ChildProcessData& data,
     const content::ChildProcessTerminationInfo& info) {
   ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
+  BrowserChildProcessCrashedOrKilled(data, info);
+}
+
+void App::BrowserChildProcessCrashedOrKilled(
+    const content::ChildProcessData& data,
+    const content::ChildProcessTerminationInfo& info) {
+  v8::HandleScope handle_scope(isolate());
+  auto details = gin_helper::Dictionary::CreateEmpty(isolate());
+  details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type));
+  details.Set("reason", info.status);
+  details.Set("exitCode", info.exit_code);
+  if (!data.name.empty()) {
+    details.Set("name", data.name);
+  }
+  Emit("child-process-gone", details);
 }
 
 void App::RenderProcessReady(content::RenderProcessHost* host) {

+ 4 - 0
shell/browser/api/electron_api_app.h

@@ -157,6 +157,10 @@ class App : public ElectronBrowserClient::Delegate,
       const content::ChildProcessTerminationInfo& info) override;
 
  private:
+  void BrowserChildProcessCrashedOrKilled(
+      const content::ChildProcessData& data,
+      const content::ChildProcessTerminationInfo& info);
+
   void SetAppPath(const base::FilePath& app_path);
   void ChildProcessLaunched(int process_type,
                             base::ProcessHandle handle,