Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/api/app.md
Expand Up @@ -360,7 +360,7 @@ page.

Emitted whenever there is a GPU info update.

### Event: 'gpu-process-crashed'
### Event: 'gpu-process-crashed' _Deprecated_

Returns:

Expand All @@ -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:
Expand Down Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awkward naming because of the child_process module in node. Is there another name we can use for this that wouldn't conflict with that existing concept

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is a different enough context that the namespace collision doesn't bother me, and it's valuable i think to match Chromium's naming where possible.


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:
Expand Down
16 changes: 16 additions & 0 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/api/electron_api_app.h
Expand Up @@ -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,
Expand Down