#include "fuchsia_web/webengine/context_provider_main.h"
#include <lib/inspect/component/cpp/component.h>
#include <lib/sys/cpp/component_context.h>
#include <lib/sys/cpp/outgoing_directory.h>
#include "base/command_line.h"
#include "base/fuchsia/process_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h"
#include "components/fuchsia_component_support/feedback_registration.h"
#include "components/fuchsia_component_support/inspect.h"
#include "fuchsia_web/common/init_logging.h"
#include "fuchsia_web/webengine/context_provider_impl.h"
#include "fuchsia_web/webengine/switches.h"
namespace {
constexpr char kCrashProductName[] = "FuchsiaWebEngine";
constexpr char kComponentUrl[] =
"fuchsia-pkg://fuchsia.com/web_engine#meta/context_provider.cm";
}
int ContextProviderMain() {
base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::UI);
const base::CommandLine* const command_line =
base::CommandLine::ForCurrentProcess();
fuchsia_component_support::RegisterProductDataForCrashReporting(
kComponentUrl, kCrashProductName);
if (!InitLoggingFromCommandLine(*command_line)) {
return 1;
}
LogComponentStartWithVersion("WebEngine context_provider");
sys::OutgoingDirectory* const directory =
base::ComponentContextForProcess()->outgoing().get();
ContextProviderImpl context_provider(*directory);
base::ScopedServiceBinding<fuchsia::web::ContextProvider> context_binding(
directory, &context_provider);
base::ScopedServiceBinding<fuchsia::web::Debug> debug_hub_binding(
directory->debug_dir(), context_provider.debug_api());
base::ScopedServiceBinding<fuchsia::web::Debug> debug_binding(
directory, context_provider.debug_api());
inspect::ComponentInspector inspect(async_get_default_dispatcher(), {});
fuchsia_component_support::PublishVersionInfoToInspect(&inspect.root());
directory->ServeFromStartupInfo();
base::RunLoop().Run();
return 0;
}