FunctorInputCursor.h [plain text]
#pragma once
#if ENABLE(WEB_REPLAY)
#include "ReplaySessionSegment.h"
#include "SegmentedInputStorage.h"
#include <replay/InputCursor.h>
#include <replay/NondeterministicInput.h>
#include <wtf/Assertions.h>
#include <wtf/Noncopyable.h>
namespace WebCore {
class FunctorInputCursor final : public InputCursor {
WTF_MAKE_NONCOPYABLE(FunctorInputCursor);
public:
static Ref<FunctorInputCursor> create(RefPtr<ReplaySessionSegment>&& segment)
{
return adoptRef(*new FunctorInputCursor(WTFMove(segment)));
}
bool isCapturing() const override { return false; }
bool isReplaying() const override { return false; }
void storeInput(std::unique_ptr<NondeterministicInputBase>) override;
NondeterministicInputBase* uncheckedLoadInput(InputQueue) override;
template<typename Functor>
typename Functor::ReturnType forEachInputInQueue(InputQueue, Functor&);
protected:
NondeterministicInputBase* loadInput(InputQueue, const String&) override;
private:
FunctorInputCursor(RefPtr<ReplaySessionSegment>&&);
RefPtr<ReplaySessionSegment> m_segment;
};
template<typename Functor> inline
typename Functor::ReturnType FunctorInputCursor::forEachInputInQueue(InputQueue queue, Functor& functor)
{
for (size_t i = 0; i < m_segment->storage().queueSize(queue); i++)
functor(i, m_segment->storage().queue(queue).at(i).get());
return functor.returnValue();
}
inline FunctorInputCursor::FunctorInputCursor(RefPtr<ReplaySessionSegment>&& segment)
: m_segment(WTFMove(segment))
{
}
inline void FunctorInputCursor::storeInput(std::unique_ptr<NondeterministicInputBase>)
{
ASSERT_NOT_REACHED();
}
inline NondeterministicInputBase* FunctorInputCursor::loadInput(InputQueue, const String&)
{
ASSERT_NOT_REACHED();
return nullptr;
}
inline NondeterministicInputBase* FunctorInputCursor::uncheckedLoadInput(InputQueue)
{
ASSERT_NOT_REACHED();
return nullptr;
}
}
#endif // ENABLE(WEB_REPLAY)