#ifndef CEF_LIBCEF_BROWSER_MAIN_RUNNER_H_
#define CEF_LIBCEF_BROWSER_MAIN_RUNNER_H_
#pragma once
#include "include/cef_app.h"
#include "libcef/common/main_runner_delegate.h"
#include "libcef/common/main_runner_handler.h"
#include "base/callback.h"
#include "content/public/browser/browser_main_runner.h"
namespace base {
class WaitableEvent;
}
namespace content {
class ContentMainRunner;
}
class CefUIThread;
class CefMainRunner : public CefMainRunnerHandler {
public:
CefMainRunner(bool multi_threaded_message_loop, bool external_message_pump);
CefMainRunner(const CefMainRunner&) = delete;
CefMainRunner& operator=(const CefMainRunner&) = delete;
~CefMainRunner();
bool Initialize(CefSettings* settings,
CefRefPtr<CefApp> application,
const CefMainArgs& args,
void* windows_sandbox_info,
bool* initialized,
base::OnceClosure context_initialized);
void Shutdown(base::OnceClosure shutdown_on_ui_thread,
base::OnceClosure finalize_shutdown);
void RunMessageLoop();
void QuitMessageLoop();
static int RunAsHelperProcess(const CefMainArgs& args,
CefRefPtr<CefApp> application,
void* windows_sandbox_info);
private:
int ContentMainInitialize(const CefMainArgs& args,
void* windows_sandbox_info,
int* no_sandbox);
bool ContentMainRun(bool* initialized, base::OnceClosure context_initialized);
void PreBrowserMain() override;
int RunMainProcess(content::MainFunctionParams main_function_params) override;
bool CreateUIThread(base::OnceClosure setup_callback);
void OnContextInitialized(base::OnceClosure context_initialized);
void FinishShutdownOnUIThread(base::OnceClosure shutdown_on_ui_thread,
base::WaitableEvent* uithread_shutdown_event);
void FinalizeShutdown(base::OnceClosure finalize_shutdown);
const bool multi_threaded_message_loop_;
const bool external_message_pump_;
std::unique_ptr<CefMainRunnerDelegate> main_delegate_;
std::unique_ptr<content::ContentMainRunner> main_runner_;
std::unique_ptr<content::BrowserMainRunner> browser_runner_;
std::unique_ptr<CefUIThread> ui_thread_;
base::OnceClosure quit_when_idle_callback_;
};
#endif