Commit 4175f565 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[Fuchsia] Enable Fuchsia logging service for all Fuchsia binaries.

* Moves logging initialization function to a common location.
* Adds initializers to Context Provider, Cast Runner, Web Runner.
* Migrates WebEngineMainDelegate to use common function.

Bug: 951143
Change-Id: I031f2279a7bfdae81be3256ee40f7e73113fce77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1785012
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Auto-Submit: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695887}
parent 2dc04e0f
...@@ -11,10 +11,12 @@ import("//testing/test.gni") ...@@ -11,10 +11,12 @@ import("//testing/test.gni")
# Integration helpers for commonly used fuchsia.* APIs. # Integration helpers for commonly used fuchsia.* APIs.
source_set("base") { source_set("base") {
sources = [ sources = [
"init_logging.cc",
"mem_buffer_util.cc", "mem_buffer_util.cc",
"string_util.cc", "string_util.cc",
] ]
public = [ public = [
"init_logging.h",
"mem_buffer_util.h", "mem_buffer_util.h",
"string_util.h", "string_util.h",
] ]
......
// Copyright 2019 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.
#include "fuchsia/base/init_logging.h"
#include "base/command_line.h"
namespace cr_fuchsia {
namespace {
// These are intended to match those in content_switches.cc.
constexpr char kEnableLogging[] = "enable-logging";
constexpr char kLogFile[] = "log-file";
} // namespace
bool InitLoggingFromCommandLine(const base::CommandLine& command_line) {
logging::LoggingSettings settings;
if (command_line.GetSwitchValueASCII(kEnableLogging) == "stderr") {
settings.logging_dest = logging::LOG_TO_STDERR;
} else {
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
}
if (command_line.HasSwitch(kLogFile)) {
settings.logging_dest |= logging::LOG_TO_FILE;
settings.log_file_path = command_line.GetSwitchValueASCII(kLogFile).c_str();
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
}
logging::SetLogItems(true /* Process ID */, true /* Thread ID */,
true /* Timestamp */, false /* Tick count */);
return true;
// return logging::InitLogging(settings);
}
} // namespace cr_fuchsia
// Copyright 2019 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 FUCHSIA_BASE_INIT_LOGGING_H_
#define FUCHSIA_BASE_INIT_LOGGING_H_
namespace base {
class CommandLine;
}
namespace cr_fuchsia {
// Configures logging for the current process based on the supplied
// |command_line|. Returns false if a logging output stream could not
// be created.
bool InitLoggingFromCommandLine(const base::CommandLine& command_line);
} // namespace cr_fuchsia
#endif // FUCHSIA_BASE_INIT_LOGGING_H_
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/component_context.h>
#include <lib/sys/cpp/outgoing_directory.h> #include <lib/sys/cpp/outgoing_directory.h>
#include "base/command_line.h"
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_pump_type.h" #include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h" #include "base/task/single_thread_task_executor.h"
#include "fuchsia/base/init_logging.h"
#include "fuchsia/base/lifecycle_impl.h" #include "fuchsia/base/lifecycle_impl.h"
#include "fuchsia/engine/context_provider_impl.h" #include "fuchsia/engine/context_provider_impl.h"
...@@ -21,6 +23,11 @@ int ContextProviderMain() { ...@@ -21,6 +23,11 @@ int ContextProviderMain() {
sys::OutgoingDirectory* directory = sys::OutgoingDirectory* directory =
base::fuchsia::ComponentContextForCurrentProcess()->outgoing().get(); base::fuchsia::ComponentContextForCurrentProcess()->outgoing().get();
if (!cr_fuchsia::InitLoggingFromCommandLine(
*base::CommandLine::ForCurrentProcess())) {
return 1;
}
ContextProviderImpl context_provider; ContextProviderImpl context_provider;
base::fuchsia::ScopedServiceBinding<fuchsia::web::ContextProvider> binding( base::fuchsia::ScopedServiceBinding<fuchsia::web::ContextProvider> binding(
directory, &context_provider); directory, &context_provider);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "fuchsia/base/init_logging.h"
#include "fuchsia/engine/browser/web_engine_browser_main.h" #include "fuchsia/engine/browser/web_engine_browser_main.h"
#include "fuchsia/engine/browser/web_engine_content_browser_client.h" #include "fuchsia/engine/browser/web_engine_content_browser_client.h"
#include "fuchsia/engine/common.h" #include "fuchsia/engine/common.h"
...@@ -22,24 +23,6 @@ namespace { ...@@ -22,24 +23,6 @@ namespace {
WebEngineMainDelegate* g_current_web_engine_main_delegate = nullptr; WebEngineMainDelegate* g_current_web_engine_main_delegate = nullptr;
void InitLoggingFromCommandLine(const base::CommandLine& command_line) {
logging::LoggingSettings settings;
if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") {
settings.logging_dest = logging::LOG_TO_STDERR;
} else {
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
}
if (command_line.HasSwitch(switches::kLogFile)) {
settings.logging_dest |= logging::LOG_TO_FILE;
settings.log_file_path =
command_line.GetSwitchValueASCII(switches::kLogFile).c_str();
settings.delete_old = logging::DELETE_OLD_LOG_FILE;
}
logging::InitLogging(settings);
logging::SetLogItems(true /* Process ID */, true /* Thread ID */,
true /* Timestamp */, false /* Tick count */);
}
void InitializeResourceBundle() { void InitializeResourceBundle() {
base::FilePath pak_file; base::FilePath pak_file;
bool result = base::PathService::Get(base::DIR_ASSETS, &pak_file); bool result = base::PathService::Get(base::DIR_ASSETS, &pak_file);
...@@ -65,7 +48,12 @@ WebEngineMainDelegate::~WebEngineMainDelegate() = default; ...@@ -65,7 +48,12 @@ WebEngineMainDelegate::~WebEngineMainDelegate() = default;
bool WebEngineMainDelegate::BasicStartupComplete(int* exit_code) { bool WebEngineMainDelegate::BasicStartupComplete(int* exit_code) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
InitLoggingFromCommandLine(*command_line);
if (!cr_fuchsia::InitLoggingFromCommandLine(*command_line)) {
*exit_code = 1;
return true;
}
content_client_ = std::make_unique<WebEngineContentClient>(); content_client_ = std::make_unique<WebEngineContentClient>();
SetContentClient(content_client_.get()); SetContentClient(content_client_.get());
return false; return false;
......
...@@ -101,6 +101,7 @@ executable("cast_runner_exe") { ...@@ -101,6 +101,7 @@ executable("cast_runner_exe") {
":cast_runner_core", ":cast_runner_core",
":common", ":common",
"//base", "//base",
"//fuchsia/base",
] ]
visibility = [ ":*" ] visibility = [ ":*" ]
} }
...@@ -214,6 +215,7 @@ executable("web_runner_exe") { ...@@ -214,6 +215,7 @@ executable("web_runner_exe") {
deps = [ deps = [
":common", ":common",
"//base", "//base",
"//fuchsia/base",
] ]
visibility = [ ":*" ] visibility = [ ":*" ]
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h" #include "base/task/single_thread_task_executor.h"
#include "build/buildflag.h" #include "build/buildflag.h"
#include "fuchsia/base/init_logging.h"
#include "fuchsia/runners/buildflags.h" #include "fuchsia/runners/buildflags.h"
#include "fuchsia/runners/cast/cast_runner.h" #include "fuchsia/runners/cast/cast_runner.h"
...@@ -17,6 +18,12 @@ int main(int argc, char** argv) { ...@@ -17,6 +18,12 @@ int main(int argc, char** argv) {
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO); base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
base::RunLoop run_loop; base::RunLoop run_loop;
base::CommandLine::Init(argc, argv);
if (!cr_fuchsia::InitLoggingFromCommandLine(
*base::CommandLine::ForCurrentProcess())) {
return 1;
}
fuchsia::web::ContextFeatureFlags features = fuchsia::web::ContextFeatureFlags features =
fuchsia::web::ContextFeatureFlags::NETWORK | fuchsia::web::ContextFeatureFlags::NETWORK |
fuchsia::web::ContextFeatureFlags::AUDIO | fuchsia::web::ContextFeatureFlags::AUDIO |
......
...@@ -4,16 +4,24 @@ ...@@ -4,16 +4,24 @@
#include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/component_context.h>
#include "base/command_line.h"
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
#include "base/message_loop/message_pump_type.h" #include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/task/single_thread_task_executor.h" #include "base/task/single_thread_task_executor.h"
#include "fuchsia/base/init_logging.h"
#include "fuchsia/runners/common/web_content_runner.h" #include "fuchsia/runners/common/web_content_runner.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO); base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
base::RunLoop run_loop; base::RunLoop run_loop;
base::CommandLine::Init(argc, argv);
if (!cr_fuchsia::InitLoggingFromCommandLine(
*base::CommandLine::ForCurrentProcess())) {
return 1;
}
constexpr fuchsia::web::ContextFeatureFlags kWebRunnerFeatures = constexpr fuchsia::web::ContextFeatureFlags kWebRunnerFeatures =
fuchsia::web::ContextFeatureFlags::NETWORK | fuchsia::web::ContextFeatureFlags::NETWORK |
fuchsia::web::ContextFeatureFlags::AUDIO | fuchsia::web::ContextFeatureFlags::AUDIO |
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment