2016-05-04 20:00:03 +02:00
|
|
|
// Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#ifndef CEF_TESTS_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_
|
|
|
|
#define CEF_TESTS_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_
|
2016-05-04 20:00:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop_std.h"
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
// This MessageLoop implementation simulates the embedding of CEF into an
|
|
|
|
// existing host application that runs its own message loop. The scheduling
|
|
|
|
// implementation provided by this class is very simplistic and does not handle
|
|
|
|
// all cases (for example, nested message loops on Windows will not function
|
|
|
|
// correctly). See comments in Chromium's platform-specific
|
|
|
|
// base/message_loop/message_pump_* source files for additional guidance when
|
|
|
|
// implementing CefBrowserProcessHandler::OnScheduleMessagePumpWork() in your
|
2016-11-18 18:31:21 +01:00
|
|
|
// application. Run cefclient or ceftests with the
|
2016-05-04 20:00:03 +02:00
|
|
|
// "--external-message-pump" command-line flag to test this mode.
|
|
|
|
class MainMessageLoopExternalPump : public MainMessageLoopStd {
|
|
|
|
public:
|
|
|
|
// Creates the singleton instance of this object. Must be called on the main
|
|
|
|
// application thread.
|
2021-06-17 22:08:01 +02:00
|
|
|
static std::unique_ptr<MainMessageLoopExternalPump> Create();
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
// Returns the singleton instance of this object. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
static MainMessageLoopExternalPump* Get();
|
|
|
|
|
|
|
|
// Called from CefBrowserProcessHandler::OnScheduleMessagePumpWork() on any
|
|
|
|
// thread. The platform subclass must implement this method and schedule a
|
|
|
|
// call to OnScheduleWork() on the main application thread.
|
2023-06-01 16:06:15 +02:00
|
|
|
virtual void OnScheduleMessagePumpWork(int64_t delay_ms) = 0;
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
protected:
|
2021-06-17 22:08:01 +02:00
|
|
|
// Only allow deletion via std::unique_ptr.
|
|
|
|
friend std::default_delete<MainMessageLoopExternalPump>;
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
// Construct and destruct this object on the main application thread.
|
|
|
|
MainMessageLoopExternalPump();
|
2024-01-20 03:22:56 +01:00
|
|
|
~MainMessageLoopExternalPump() override;
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
// The platform subclass calls this method on the main application thread in
|
|
|
|
// response to the OnScheduleMessagePumpWork() call.
|
2023-06-01 16:06:15 +02:00
|
|
|
void OnScheduleWork(int64_t delay_ms);
|
2016-05-04 20:00:03 +02:00
|
|
|
|
|
|
|
// The platform subclass calls this method on the main application thread when
|
|
|
|
// the pending work timer times out.
|
|
|
|
void OnTimerTimeout();
|
|
|
|
|
|
|
|
// Control the pending work timer in the platform subclass. Only called on
|
|
|
|
// the main application thread.
|
2023-06-01 16:06:15 +02:00
|
|
|
virtual void SetTimer(int64_t delay_ms) = 0;
|
2016-05-04 20:00:03 +02:00
|
|
|
virtual void KillTimer() = 0;
|
|
|
|
virtual bool IsTimerPending() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Handle work processing.
|
|
|
|
void DoWork();
|
|
|
|
bool PerformMessageLoopWork();
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
bool is_active_ = false;
|
|
|
|
bool reentrancy_detected_ = false;
|
2016-05-04 20:00:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace client
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#endif // CEF_TESTS_SHARED_BROWSER_MAIN_MESSAGE_LOOP_EXTERNAL_PUMP_H_
|