2020-06-24 22:26:12 +02:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_MAIN_RUNNER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_MAIN_RUNNER_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-07-02 19:27:09 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/callback.h"
|
2024-07-02 19:27:09 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_app.h"
|
2024-07-02 19:27:09 +02:00
|
|
|
#include "cef/libcef/browser/ui_thread.h"
|
|
|
|
#include "cef/libcef/common/chrome/chrome_main_delegate_cef.h"
|
|
|
|
#include "chrome/common/profiler/main_thread_stack_sampling_profiler.h"
|
|
|
|
#include "components/keep_alive_registry/scoped_keep_alive.h"
|
|
|
|
#include "content/public/app/content_main_runner.h"
|
2020-06-24 22:26:12 +02:00
|
|
|
#include "content/public/browser/browser_main_runner.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class WaitableEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manages the main process lifespan and related objects.
|
2024-07-02 19:27:09 +02:00
|
|
|
class CefMainRunner final {
|
2020-06-24 22:26:12 +02:00
|
|
|
public:
|
|
|
|
CefMainRunner(bool multi_threaded_message_loop, bool external_message_pump);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefMainRunner(const CefMainRunner&) = delete;
|
|
|
|
CefMainRunner& operator=(const CefMainRunner&) = delete;
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
// Called from CefContext::Initialize.
|
|
|
|
bool Initialize(CefSettings* settings,
|
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
const CefMainArgs& args,
|
|
|
|
void* windows_sandbox_info,
|
|
|
|
bool* initialized,
|
|
|
|
base::OnceClosure context_initialized);
|
|
|
|
|
2024-03-12 20:47:10 +01:00
|
|
|
// Only valid after Initialize is called.
|
|
|
|
int exit_code() const { return exit_code_; }
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
// Called from CefContext::Shutdown.
|
|
|
|
void Shutdown(base::OnceClosure shutdown_on_ui_thread,
|
|
|
|
base::OnceClosure finalize_shutdown);
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
void RunMessageLoop();
|
|
|
|
void QuitMessageLoop();
|
2020-06-24 22:26:12 +02:00
|
|
|
|
|
|
|
// Called from CefExecuteProcess.
|
|
|
|
static int RunAsHelperProcess(const CefMainArgs& args,
|
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info);
|
|
|
|
|
2024-07-02 19:27:09 +02:00
|
|
|
// Called from ChromeMainDelegateCef.
|
|
|
|
void PreBrowserMain();
|
|
|
|
int RunMainProcess(content::MainFunctionParams main_function_params);
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
private:
|
|
|
|
// Called from Initialize().
|
|
|
|
int ContentMainInitialize(const CefMainArgs& args,
|
|
|
|
void* windows_sandbox_info,
|
2024-08-05 18:16:49 +02:00
|
|
|
int* no_sandbox,
|
|
|
|
bool disable_signal_handlers);
|
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
int ContentMainRun(bool* initialized, base::OnceClosure context_initialized);
|
2020-06-24 22:26:12 +02:00
|
|
|
|
2024-07-02 19:27:09 +02:00
|
|
|
static void BeforeMainInitialize(const CefMainArgs& args);
|
|
|
|
bool HandleMainMessageLoopQuit();
|
2020-06-24 22:26:12 +02:00
|
|
|
|
|
|
|
// Create the UI thread when running with multi-threaded message loop mode.
|
|
|
|
bool CreateUIThread(base::OnceClosure setup_callback);
|
|
|
|
|
|
|
|
// Called on the UI thread after the context is initialized.
|
|
|
|
void OnContextInitialized(base::OnceClosure context_initialized);
|
|
|
|
|
2023-12-11 21:36:56 +01:00
|
|
|
// Performs shutdown actions that need to occur on the UI thread before the
|
|
|
|
// thread RunLoop has stopped.
|
|
|
|
void StartShutdownOnUIThread(base::OnceClosure shutdown_on_ui_thread);
|
2020-06-24 22:26:12 +02:00
|
|
|
|
2023-12-11 21:36:56 +01:00
|
|
|
// Performs shutdown actions that need to occur on the UI thread after the
|
|
|
|
// thread RunLoop has stopped and before running exit callbacks.
|
|
|
|
void FinishShutdownOnUIThread();
|
2020-06-24 22:26:12 +02:00
|
|
|
|
2024-07-02 19:27:09 +02:00
|
|
|
void BeforeUIThreadInitialize();
|
|
|
|
void BeforeUIThreadShutdown();
|
|
|
|
|
2020-06-24 22:26:12 +02:00
|
|
|
const bool multi_threaded_message_loop_;
|
|
|
|
const bool external_message_pump_;
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
std::unique_ptr<content::ContentMainRunner> main_runner_;
|
2020-06-24 22:26:12 +02:00
|
|
|
|
|
|
|
std::unique_ptr<content::BrowserMainRunner> browser_runner_;
|
|
|
|
std::unique_ptr<CefUIThread> ui_thread_;
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
// Used to quit the current base::RunLoop.
|
2023-07-11 08:41:47 +02:00
|
|
|
base::OnceClosure quit_callback_;
|
2024-03-12 20:47:10 +01:00
|
|
|
|
|
|
|
int exit_code_ = -1;
|
2024-07-02 19:27:09 +02:00
|
|
|
|
|
|
|
std::unique_ptr<ChromeMainDelegateCef> main_delegate_;
|
|
|
|
|
|
|
|
std::unique_ptr<MainThreadStackSamplingProfiler> sampling_profiler_;
|
|
|
|
std::unique_ptr<ScopedKeepAlive> keep_alive_;
|
|
|
|
|
|
|
|
raw_ptr<CefSettings> settings_ = nullptr;
|
|
|
|
CefRefPtr<CefApp> application_;
|
2020-06-24 22:26:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_MAIN_RUNNER_H_
|