forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWebView+LibCore: Manage process lifecycle using a SIGCHLD handler
This large commit also refactors LibWebView's process handling to use a top-level Application class that uses a new WebView::Process class to encapsulate the IPC-centric nature of each helper process.
- Loading branch information
Showing
21 changed files
with
349 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <LibImageDecoderClient/Client.h> | ||
#include <LibWebView/Application.h> | ||
#include <LibWebView/WebContentClient.h> | ||
|
||
namespace WebView { | ||
|
||
Application* Application::s_the = nullptr; | ||
|
||
Application::Application(int, char**) | ||
{ | ||
VERIFY(!s_the); | ||
s_the = this; | ||
|
||
m_process_manager.on_process_exited = [this](Process&& process) { | ||
dbgln("ProcessManager: Process{}: {} ({}) exited", process.pid(), process.title().value_or("Untitled"_string), process_name_from_type(process.type())); | ||
process_did_exit(move(process)); | ||
}; | ||
} | ||
|
||
Application::~Application() | ||
{ | ||
s_the = nullptr; | ||
} | ||
|
||
int Application::exec() | ||
{ | ||
int ret = m_event_loop.exec(); | ||
m_in_shutdown = true; | ||
return ret; | ||
} | ||
|
||
void Application::add_child_process(WebView::Process&& process) | ||
{ | ||
m_process_manager.add_process(move(process)); | ||
} | ||
|
||
#if defined(AK_OS_MACH) | ||
void Application::set_process_mach_port(pid_t pid, Core::MachPort&& port) | ||
{ | ||
m_process_manager.set_process_mach_port(pid, move(port)); | ||
} | ||
#endif | ||
|
||
Optional<Process&> Application::find_process(pid_t pid) | ||
{ | ||
return m_process_manager.find_process(pid); | ||
} | ||
|
||
void Application::update_process_statistics() | ||
{ | ||
m_process_manager.update_all_process_statistics(); | ||
} | ||
|
||
String Application::generate_process_statistics_html() | ||
{ | ||
return m_process_manager.generate_html(); | ||
} | ||
|
||
void Application::process_did_exit(Process&& process) | ||
{ | ||
if (m_in_shutdown) | ||
return; | ||
|
||
dbgln("Process {} died, type: {}", process.pid(), process_name_from_type(process.type())); | ||
|
||
switch (process.type()) { | ||
case ProcessType::ImageDecoder: | ||
if (auto client = process.client<ImageDecoderClient::Client>(); client.has_value()) { | ||
dbgln("Restart ImageDecoder process"); | ||
if (auto on_death = move(client->on_death)) { | ||
on_death(); | ||
} | ||
} | ||
break; | ||
case ProcessType::RequestServer: | ||
dbgln("FIXME: Restart request server"); | ||
break; | ||
case ProcessType::WebContent: | ||
if (auto client = process.client<WebContentClient>(); client.has_value()) { | ||
dbgln("Restart WebContent process"); | ||
if (auto on_web_content_process_crash = move(client->on_web_content_process_crash)) | ||
on_web_content_process_crash(); | ||
} | ||
break; | ||
case ProcessType::WebWorker: | ||
dbgln("WebWorker {} died, not sure what to do.", process.pid()); | ||
break; | ||
case ProcessType::Chrome: | ||
dbgln("Invalid process type to be dying: Chrome"); | ||
VERIFY_NOT_REACHED(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibCore/EventLoop.h> | ||
#include <LibWebView/Process.h> | ||
#include <LibWebView/ProcessManager.h> | ||
|
||
namespace WebView { | ||
|
||
class Application { | ||
AK_MAKE_NONCOPYABLE(Application); | ||
|
||
public: | ||
Application(int argc, char** argv); | ||
virtual ~Application(); | ||
|
||
int exec(); | ||
|
||
static Application& the() { return *s_the; } | ||
|
||
Core::EventLoop& event_loop() { return m_event_loop; } | ||
|
||
void add_child_process(Process&&); | ||
|
||
// FIXME: Should these methods be part of Application, instead of deferring to ProcessManager? | ||
#if defined(AK_OS_MACH) | ||
void set_process_mach_port(pid_t, Core::MachPort&&); | ||
#endif | ||
Optional<Process&> find_process(pid_t); | ||
|
||
// FIXME: Should we just expose the ProcessManager via a getter? | ||
void update_process_statistics(); | ||
String generate_process_statistics_html(); | ||
|
||
protected: | ||
virtual void process_did_exit(Process&&); | ||
|
||
private: | ||
static Application* s_the; | ||
|
||
Core::EventLoop m_event_loop; | ||
|
||
Optional<Process&> m_request_server_process; | ||
Optional<Process&> m_image_decoder_process; | ||
|
||
ProcessManager m_process_manager; | ||
bool m_in_shutdown { false }; | ||
}; | ||
|
||
} |
Oops, something went wrong.