1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:57:45 +00:00

WebDriver: Reference-count WebDriver Session objects

When some WebDriver spec steps are implemented a bit more literally, we
will end up in a situation where we remove a session from its client's
active session map, but still have more steps to perform. Currently,
when we remove the session, it is immediately destroyed because it is
stored in an OwnPtr. Instead, we can store it as a RefPtr, which will
let the caller to such steps keep the session alive until the subsequent
steps are complete.

While here, this also changes the storage of active sessions to a
HashMap, as all lookups into it are currently a linear search.
This commit is contained in:
Timothy Flynn 2023-03-07 10:36:39 -05:00 committed by Linus Groh
parent 7be8931ca0
commit a0992c7731
3 changed files with 68 additions and 74 deletions

View file

@ -9,6 +9,7 @@
#pragma once
#include <AK/Function.h>
#include <AK/NonnullRefPtr.h>
#include <LibCore/Object.h>
#include <LibWeb/WebDriver/Client.h>
#include <LibWeb/WebDriver/Error.h>
@ -34,8 +35,8 @@ public:
private:
Client(NonnullOwnPtr<Core::BufferedTCPSocket>, LaunchBrowserCallbacks, Core::Object* parent);
ErrorOr<Session*, Web::WebDriver::Error> find_session_with_id(StringView session_id);
ErrorOr<NonnullOwnPtr<Session>, Web::WebDriver::Error> take_session_with_id(StringView session_id);
ErrorOr<NonnullRefPtr<Session>, Web::WebDriver::Error> find_session_with_id(StringView session_id);
ErrorOr<NonnullRefPtr<Session>, Web::WebDriver::Error> take_session_with_id(StringView session_id);
virtual Web::WebDriver::Response new_session(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response delete_session(Web::WebDriver::Parameters parameters, JsonValue payload) override;
@ -92,7 +93,7 @@ private:
virtual Web::WebDriver::Response take_element_screenshot(Web::WebDriver::Parameters parameters, JsonValue payload) override;
virtual Web::WebDriver::Response print_page(Web::WebDriver::Parameters parameters, JsonValue payload) override;
static Vector<NonnullOwnPtr<Session>> s_sessions;
static HashMap<unsigned, NonnullRefPtr<Session>> s_sessions;
static Atomic<unsigned> s_next_session_id;
LaunchBrowserCallbacks m_callbacks;