Skip to content

Commit

Permalink
LibWeb: Rename ConnectionQueue to RequestList
Browse files Browse the repository at this point in the history
  • Loading branch information
stelar7 authored and gmta committed Jan 14, 2025
1 parent 439245b commit b43bb24
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
11 changes: 6 additions & 5 deletions Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,20 @@ set(SOURCES
Infra/ByteSequences.cpp
Infra/JSON.cpp
Infra/Strings.cpp
IndexedDB/Internal/Algorithms.cpp
IndexedDB/Internal/Database.cpp
IndexedDB/Internal/Key.cpp
IndexedDB/IDBDatabase.cpp
IndexedDB/IDBCursor.cpp
IndexedDB/IDBDatabase.cpp
IndexedDB/IDBFactory.cpp
IndexedDB/IDBOpenDBRequest.cpp
IndexedDB/IDBIndex.cpp
IndexedDB/IDBKeyRange.cpp
IndexedDB/IDBObjectStore.cpp
IndexedDB/IDBOpenDBRequest.cpp
IndexedDB/IDBRequest.cpp
IndexedDB/IDBTransaction.cpp
IndexedDB/IDBVersionChangeEvent.cpp
IndexedDB/Internal/Algorithms.cpp
IndexedDB/Internal/Database.cpp
IndexedDB/Internal/Key.cpp
IndexedDB/Internal/RequestList.cpp
Internals/Inspector.cpp
Internals/InternalAnimationTimeline.cpp
Internals/Internals.cpp
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ class IDBOpenDBRequest;
class IDBRequest;
class IDBTransaction;
class IDBVersionChangeEvent;
class RequestList;
}

namespace Web::Internals {
Expand Down
23 changes: 3 additions & 20 deletions Libraries/LibWeb/IndexedDB/Internal/ConnectionQueueHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,17 @@
#pragma once

#include <AK/HashMap.h>
#include <LibGC/Root.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/IndexedDB/IDBRequest.h>
#include <LibWeb/IndexedDB/Internal/RequestList.h>
#include <LibWeb/StorageAPI/StorageKey.h>

namespace Web::IndexedDB {

class ConnectionQueue : public AK::Vector<GC::Root<IDBRequest>> {
public:
bool all_previous_requests_processed(GC::Ref<IDBRequest> const& request) const
{
for (auto const& entry : *this) {
if (entry == request)
return true;
if (!entry->processed())
return false;
}

return true;
}
};

using ConnectionMap = HashMap<StorageAPI::StorageKey, HashMap<String, ConnectionQueue>>;
using ConnectionMap = HashMap<StorageAPI::StorageKey, HashMap<String, RequestList>>;

// https://w3c.github.io/IndexedDB/#connection-queues
class ConnectionQueueHandler {
public:
static ConnectionQueue& for_key_and_name(StorageAPI::StorageKey& key, String& name);
static RequestList& for_key_and_name(StorageAPI::StorageKey& key, String& name);
static ConnectionQueueHandler& the()
{
static ConnectionQueueHandler s_instance;
Expand Down
6 changes: 3 additions & 3 deletions Libraries/LibWeb/IndexedDB/Internal/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void Database::visit_edges(Visitor& visitor)
visitor.visit(m_upgrade_transaction);
}

ConnectionQueue& ConnectionQueueHandler::for_key_and_name(StorageAPI::StorageKey& key, String& name)
RequestList& ConnectionQueueHandler::for_key_and_name(StorageAPI::StorageKey& key, String& name)
{
return ConnectionQueueHandler::the().m_open_requests.ensure(key, [] {
return HashMap<String, ConnectionQueue>();
return HashMap<String, RequestList>();
})
.ensure(name, [] {
return ConnectionQueue();
return RequestList();
});
}

Expand Down
33 changes: 33 additions & 0 deletions Libraries/LibWeb/IndexedDB/Internal/RequestList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, stelar7 <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/IndexedDB/Internal/RequestList.h>

namespace Web::IndexedDB {

bool RequestList::all_requests_processed() const
{
for (auto const& entry : *this) {
if (!entry->processed())
return false;
}

return true;
}

bool RequestList::all_previous_requests_processed(GC::Ref<IDBRequest> const& request) const
{
for (auto const& entry : *this) {
if (entry == request)
return true;
if (!entry->processed())
return false;
}

return true;
}

}
21 changes: 21 additions & 0 deletions Libraries/LibWeb/IndexedDB/Internal/RequestList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024, stelar7 <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/Vector.h>
#include <LibGC/Root.h>
#include <LibWeb/IndexedDB/IDBRequest.h>

namespace Web::IndexedDB {

class RequestList : public AK::Vector<GC::Root<IDBRequest>> {
public:
bool all_requests_processed() const;
bool all_previous_requests_processed(GC::Ref<IDBRequest> const& request) const;
};

}

0 comments on commit b43bb24

Please sign in to comment.