Skip to content

Commit

Permalink
Wip: Wip lmao probably doesn't build
Browse files Browse the repository at this point in the history
  • Loading branch information
ADKaster committed Jun 28, 2024
1 parent 3c188d4 commit b096367
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 103 deletions.
3 changes: 1 addition & 2 deletions Userland/Libraries/LibCore/EventLoopImplementationUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ struct SignalHandlersInfo {
};

static Singleton<SignalHandlersInfo> s_signals;
template<bool create_if_null = true>
inline SignalHandlersInfo* signals_info()
{
return s_signals.ptr();
Expand All @@ -518,7 +517,7 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
thread_data.notifier_by_ptr.clear();
thread_data.notifier_by_index.clear();
thread_data.initialize_wake_pipe();
if (auto* info = signals_info<false>()) {
if (auto* info = signals_info()) {
info->signal_handlers.clear();
info->next_signal_id = 0;
}
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibCore/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MimeData;
class NetworkJob;
class NetworkResponse;
class Notifier;
class Process;
class ProcessStatisticsReader;
class Resource;
class ResourceImplementation;
Expand Down
8 changes: 0 additions & 8 deletions Userland/Libraries/LibCore/Platform/ProcessInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ struct ProcessInfo {
{
}

virtual ~ProcessInfo() = default;

pid_t pid { 0 };

u64 memory_usage_bytes { 0 };
Expand All @@ -30,12 +28,6 @@ struct ProcessInfo {
u64 time_spent_in_process { 0 };

#if defined(AK_OS_MACH)
ProcessInfo(pid_t pid, Core::MachPort&& port)
: pid(pid)
, child_task_port(move(port))
{
}

Core::MachPort child_task_port;
#endif
};
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibCore/Platform/ProcessStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
namespace Core::Platform {

struct ProcessStatistics {
template<typename ProcessInfoType, typename Callback>
template<typename Callback>
void for_each_process(Callback&& callback)
{
for (auto& process : processes)
callback(verify_cast<ProcessInfoType>(*process));
callback(*process);
}

u64 total_time_scheduled { 0 };
Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibCore/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ struct ArgvList {
}
};

Process Process::current()
{
auto p = Process { getpid() };
p.m_should_disown = false;
return p;
}

ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
{
#define CHECK(invocation) \
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibCore/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Process {
}

static ErrorOr<Process> spawn(ProcessSpawnOptions const& options);
static Process current();

// FIXME: Make the following 2 functions return Process instance or delete them.
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<ByteString> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
Expand Down
34 changes: 34 additions & 0 deletions Userland/Libraries/LibWebView/Application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWebView/Application.h>

namespace WebView {

Application* Application::s_the = nullptr;

Application::Application(int, char**)
{
VERIFY(!s_the);
s_the = this;
}

Application::~Application()
{
s_the = nullptr;
}

int Application::exec()
{
return m_event_loop.exec();
}

void Application::add_child_process(WebView::Process&& process)
{
m_process_manager.add_process(move(process));
}

}
43 changes: 43 additions & 0 deletions Userland/Libraries/LibWebView/Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibCore/EventLoop.h>
#include <LibWebView/Process.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&&);

protected:
virtual void process_did_exit(Process const&) = 0;

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;
};

}
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWebView/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
include(${SerenityOS_SOURCE_DIR}/Meta/CMake/public_suffix.cmake)

set(SOURCES
Application.cpp
Attribute.cpp
ChromeProcess.cpp
CookieJar.cpp
Database.cpp
InspectorClient.cpp
ProcessHandle.cpp
Process.cpp
ProcessManager.cpp
RequestServerAdapter.cpp
SearchEngine.cpp
Expand Down
24 changes: 24 additions & 0 deletions Userland/Libraries/LibWebView/Process.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibCore/Process.h>
#include <LibWebView/Process.h>

namespace WebView {

Process::Process(ProcessType type, RefPtr<IPC::ConnectionBase> connection, Core::Process process)
: m_process(move(process))
, m_type(type)
, m_connection(move(connection))
{
}

Process::~Process()
{
m_connection->shutdown();
}

}
43 changes: 43 additions & 0 deletions Userland/Libraries/LibWebView/Process.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibCore/Process.h>
#include <LibIPC/Connection.h>
#include <LibWebView/ProcessManager.h>
#include <LibWebView/ProcessType.h>

namespace WebView {

class Process {
AK_MAKE_NONCOPYABLE(Process);
AK_MAKE_DEFAULT_MOVABLE(Process);

public:
Process(ProcessType type, RefPtr<IPC::ConnectionBase> connection, Core::Process process);
~Process();

ProcessType type() const { return m_type; }
Optional<String> const& title() const { return m_title; }
void set_title(String title) { m_title = move(title); }

template<typename ConnectionFromClient>
ConnectionFromClient& client()
{
return verify_cast<ConnectionFromClient>(*m_connection);
}

pid_t pid() const { return m_process.pid(); }

private:
Core::Process m_process;
ProcessType m_type;
Optional<String> m_title;
RefPtr<IPC::ConnectionBase> m_connection;
};

}
41 changes: 0 additions & 41 deletions Userland/Libraries/LibWebView/ProcessInfo.h

This file was deleted.

Loading

0 comments on commit b096367

Please sign in to comment.