2024-03-25 21:29:14 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-04-04 17:10:08 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-04-14 22:26:29 -03:00
|
|
|
#include <AK/Function.h>
|
2026-05-26 13:02:04 -03:00
|
|
|
#include <AK/HashMap.h>
|
2025-03-24 10:50:12 -03:00
|
|
|
#include <AK/JsonValue.h>
|
2026-05-26 13:02:04 -03:00
|
|
|
#include <AK/RefPtr.h>
|
2024-03-25 21:29:14 -03:00
|
|
|
#include <AK/Types.h>
|
2026-04-14 22:26:29 -03:00
|
|
|
#include <LibCore/EventLoop.h>
|
2024-04-21 00:35:17 -03:00
|
|
|
#include <LibCore/Platform/ProcessStatistics.h>
|
2026-05-26 13:02:04 -03:00
|
|
|
#include <LibCore/Timer.h>
|
2024-03-25 21:29:14 -03:00
|
|
|
#include <LibWebView/Forward.h>
|
2024-06-30 01:24:01 -03:00
|
|
|
#include <LibWebView/Process.h>
|
2025-11-22 20:01:02 -03:00
|
|
|
#include <LibWebView/ProcessMonitor.h>
|
2024-06-30 01:24:01 -03:00
|
|
|
#include <LibWebView/ProcessType.h>
|
2024-03-25 21:29:14 -03:00
|
|
|
|
|
|
|
|
namespace WebView {
|
|
|
|
|
|
2025-07-02 00:55:11 -03:00
|
|
|
WEBVIEW_API ProcessType process_type_from_name(StringView);
|
|
|
|
|
WEBVIEW_API StringView process_name_from_type(ProcessType type);
|
2024-03-25 21:29:14 -03:00
|
|
|
|
2025-07-02 00:55:11 -03:00
|
|
|
class WEBVIEW_API ProcessManager {
|
2024-06-30 01:24:01 -03:00
|
|
|
AK_MAKE_NONCOPYABLE(ProcessManager);
|
|
|
|
|
|
2024-03-25 21:29:14 -03:00
|
|
|
public:
|
2024-06-30 01:24:01 -03:00
|
|
|
ProcessManager();
|
2024-03-25 21:29:14 -03:00
|
|
|
|
2024-06-30 01:24:01 -03:00
|
|
|
void add_process(Process&&);
|
2026-04-14 22:26:29 -03:00
|
|
|
void for_each_process(Function<void(Process&)>);
|
2024-06-30 01:24:01 -03:00
|
|
|
Optional<Process> remove_process(pid_t);
|
|
|
|
|
Optional<Process&> find_process(pid_t);
|
2026-05-26 13:02:04 -03:00
|
|
|
void cancel_forced_exit(pid_t);
|
|
|
|
|
void force_exit_after_timeout(pid_t, int timeout_ms);
|
2024-03-25 21:29:14 -03:00
|
|
|
|
2024-04-04 17:10:08 -03:00
|
|
|
#if defined(AK_OS_MACH)
|
2024-06-30 01:24:01 -03:00
|
|
|
void set_process_mach_port(pid_t, Core::MachPort&&);
|
2024-04-04 17:10:08 -03:00
|
|
|
#endif
|
|
|
|
|
|
2024-06-30 01:24:01 -03:00
|
|
|
void update_all_process_statistics();
|
2025-03-24 10:50:12 -03:00
|
|
|
JsonValue serialize_json();
|
2024-03-26 14:38:12 -03:00
|
|
|
|
2026-04-14 22:26:29 -03:00
|
|
|
Function<void(Process&)> on_process_added; // test-web
|
2026-05-12 12:20:40 -03:00
|
|
|
Function<void(Process&&, Optional<int> exit_status)> on_process_exited;
|
2024-03-25 21:29:14 -03:00
|
|
|
|
2024-06-30 01:24:01 -03:00
|
|
|
private:
|
2026-04-14 22:26:29 -03:00
|
|
|
void verify_event_loop() const;
|
|
|
|
|
|
2024-04-21 00:35:17 -03:00
|
|
|
Core::Platform::ProcessStatistics m_statistics;
|
2024-06-30 01:24:01 -03:00
|
|
|
HashMap<pid_t, Process> m_processes;
|
2026-05-26 13:02:04 -03:00
|
|
|
HashMap<pid_t, RefPtr<Core::Timer>> m_forced_exit_timers;
|
2025-11-22 20:01:02 -03:00
|
|
|
ProcessMonitor m_process_monitor;
|
2026-04-14 22:26:29 -03:00
|
|
|
Core::EventLoop* m_creation_event_loop { &Core::EventLoop::current() };
|
2024-03-25 21:29:14 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|