#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_OHOS_H_
#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_OHOS_H_
#include <memory>
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/functional/callback.h"
#include "base/message_loop/message_pump.h"
#include "base/time/time.h"
#include "event_handler_adapter.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace base {
class RunLoop;
class BASE_EXPORT MessagePumpForUI : public MessagePump {
public:
MessagePumpForUI();
MessagePumpForUI(const MessagePumpForUI&) = delete;
MessagePumpForUI& operator=(const MessagePumpForUI&) = delete;
~MessagePumpForUI() override;
void Run(Delegate* delegate) override;
void Quit() override;
void ScheduleWork() override;
void ScheduleDelayedWork(
const Delegate::NextWorkInfo& next_work_info) override;
void Attach(Delegate* delegate);
void Abort() { should_abort_ = true; }
bool IsAborted() { return should_abort_; }
bool ShouldQuit() const { return should_abort_ || quit_; }
void QuitWhenIdle(base::OnceClosure callback);
void OnDelayedLooperCallback();
void OnNonDelayedLooperCallback();
protected:
Delegate* SetDelegate(Delegate* delegate);
bool SetQuit(bool quit);
void DoDelayedLooperWork();
void DoNonDelayedLooperWork(bool do_idle_work);
private:
void ScheduleWorkInternal(bool do_idle_work);
void DoIdleWork();
std::unique_ptr<RunLoop> run_loop_;
bool should_abort_ = false;
bool quit_ = false;
Delegate* delegate_ = nullptr;
absl::optional<TimeTicks> delayed_scheduled_time_;
base::OnceClosure on_quit_callback_;
int non_delayed_fd_;
int delayed_fd_;
std::unique_ptr<OHOS::NWeb::EventHandlerAdapter> ohos_event_handler_adapter_;
std::shared_ptr<OHOS::NWeb::EventHandlerFDListenerAdapter> ohos_listener;
};
}
#endif