Commit fe476002 authored by proberge's avatar proberge Committed by Commit Bot

Move eventlog_provider from //base/win to //chrome/common/win.

This removes a //chrome dependency in base (process_version_rc_template),
allowing //base to be used by targets that do not have access to //chrome.

BUG=642115
TEST=eventlog_provider.dll is installed and SYSLOG works.

Review-Url: https://codereview.chromium.org/2946983002
Cr-Commit-Position: refs/heads/master@{#481878}
parent e545f646
......@@ -723,7 +723,7 @@ group("chromium_builder_tests") {
if (is_win) {
group("chrome_official_builder_no_unittests") {
deps = [
"//base/win:eventlog_provider",
"//chrome/common/win:eventlog_provider",
"//chrome/installer/gcapi",
"//chrome/installer/mini_installer",
"//cloud_print",
......
......@@ -1412,7 +1412,6 @@ component("base") {
deps += [
"//base/trace_event/etw_manifest:chrome_events_win",
"//base/win:base_win_features",
"//base/win:eventlog_messages",
]
if (is_component_build) {
......
......@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/debug/stack_trace.h"
#include "base/syslog_logging.h"
#if defined(OS_WIN)
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/win/eventlog_messages.h"
#include <windows.h>
#include "base/debug/stack_trace.h"
#elif defined(OS_LINUX)
// <syslog.h> defines a LOG_WARNING macro that could conflict with
// base::LOG_WARNING.
......@@ -18,7 +15,6 @@
#undef LOG_WARNING
#endif
#include <cstring>
#include <ostream>
#include <string>
......@@ -27,13 +23,22 @@ namespace logging {
#if defined(OS_WIN)
namespace {
std::string* g_event_source_name = nullptr;
}
uint16_t g_category = 0;
uint32_t g_event_id = 0;
} // namespace
void SetEventSourceName(const std::string& name) {
void SetEventSource(const std::string& name,
uint16_t category,
uint32_t event_id) {
DCHECK_EQ(nullptr, g_event_source_name);
g_event_source_name = new std::string(name);
g_category = category;
g_event_id = event_id;
}
#endif // defined(OS_WIN)
EventLogMessage::EventLogMessage(const char* file,
......@@ -51,8 +56,8 @@ EventLogMessage::~EventLogMessage() {
return;
HANDLE event_log_handle =
RegisterEventSourceA(NULL, g_event_source_name->c_str());
if (event_log_handle == NULL) {
RegisterEventSourceA(nullptr, g_event_source_name->c_str());
if (event_log_handle == nullptr) {
stream() << " !!NOT ADDED TO EVENTLOG!!";
return;
}
......@@ -78,8 +83,8 @@ EventLogMessage::~EventLogMessage() {
break;
}
LPCSTR strings[1] = {message.data()};
if (!ReportEventA(event_log_handle, log_type, BROWSER_CATEGORY,
MSG_LOG_MESSAGE, NULL, 1, 0, strings, NULL)) {
if (!ReportEventA(event_log_handle, log_type, g_category, g_event_id, nullptr,
1, 0, strings, nullptr)) {
stream() << " !!NOT ADDED TO EVENTLOG!!";
}
#elif defined(OS_LINUX)
......
......@@ -5,7 +5,10 @@
#ifndef BASE_SYSLOG_LOGGING_H_
#define BASE_SYSLOG_LOGGING_H_
#include <iosfwd>
#include "base/logging.h"
#include "build/build_config.h"
namespace logging {
......@@ -17,10 +20,14 @@ namespace logging {
#define SYSLOG(severity) \
SYSLOG_STREAM(severity)
// Sets the name of the event source for logging to the Windows Event Log.
// Call this function once before using the SYSLOG macro or otherwise it will
// behave as a regular LOG macro.
void BASE_EXPORT SetEventSourceName(const std::string& name);
#if defined(OS_WIN)
// Sets the name, category and event id of the event source for logging to the
// Windows Event Log. Call this function once before using the SYSLOG macro or
// otherwise it will behave as a regular LOG macro.
void BASE_EXPORT SetEventSource(const std::string& name,
uint16_t category,
uint32_t event_id);
#endif // defined(OS_WIN)
// Creates a formatted message on the system event log. That would be the
// Application Event log on Windows and the messages log file on POSIX systems.
......
......@@ -3,9 +3,6 @@
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/win/message_compiler.gni")
import("//chrome/process_version_rc_template.gni")
declare_args() {
# Indicates if the handle verifier should operate in a single module mode. By
......@@ -25,43 +22,6 @@ buildflag_header("base_win_features") {
flags = [ "SINGLE_MODULE_MODE_HANDLE_VERIFIER=$single_module_mode_handle_verifier" ]
}
message_compiler("eventlog_messages") {
visibility = [
"//base:base",
":eventlog_provider",
]
sources = [
"eventlog_messages.mc",
]
user_mode_logging = false
compile_generated_code = false
}
process_version_rc_template("eventlog_provider_dll_version") {
sources = [
"eventlog_provider.ver",
]
output = "$target_gen_dir/eventlog_provider_dll_version.rc"
}
shared_library("eventlog_provider") {
sources = [
"$root_gen_dir/base/win/eventlog_messages.rc",
"eventlog_provider.cc",
]
if (!is_asan) {
ldflags = [ "/NOENTRY" ]
}
deps = [
"//base/win:eventlog_messages",
"//base/win:eventlog_provider_dll_version",
]
}
static_library("pe_image") {
sources = [
"pe_image.cc",
......
......@@ -443,6 +443,10 @@ static_library("common") {
}
if (is_win) {
deps = [
"//chrome/common/win:eventlog_messages",
]
public_deps += [
"//components/dom_distiller/core", # Needed by chrome_content_client.cc.
"//third_party/wtl",
......
......@@ -62,6 +62,7 @@
#include <initguid.h>
#include "base/logging_win.h"
#include "base/syslog_logging.h"
#include "chrome/common/win/eventlog_messages.h"
#include "chrome/install_static/install_details.h"
#endif
......@@ -332,8 +333,9 @@ void InitChromeLogging(const base::CommandLine& command_line,
LogEventProvider::Initialize(kChromeTraceProviderName);
// Enable logging to the Windows Event Log.
SetEventSourceName(base::UTF16ToASCII(
install_static::InstallDetails::Get().install_full_name()));
SetEventSource(base::UTF16ToASCII(
install_static::InstallDetails::Get().install_full_name()),
BROWSER_CATEGORY, MSG_LOG_MESSAGE);
#endif
base::StatisticsRecorder::InitLogOnShutdown();
......
# Copyright 2017 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.
import("//build/config/sanitizers/sanitizers.gni")
import("//build/win/message_compiler.gni")
import("//chrome/process_version_rc_template.gni")
message_compiler("eventlog_messages") {
visibility = [
"//chrome/common:common",
":eventlog_provider",
]
sources = [
"eventlog_messages.mc",
]
user_mode_logging = false
compile_generated_code = false
}
process_version_rc_template("eventlog_provider_dll_version") {
sources = [
"eventlog_provider.ver",
]
output = "$target_gen_dir/eventlog_provider_dll_version.rc"
}
shared_library("eventlog_provider") {
sources = [
"$root_gen_dir/chrome/common/win/eventlog_messages.rc",
"eventlog_provider.cc",
]
if (!is_asan) {
ldflags = [ "/NOENTRY" ]
}
deps = [
":eventlog_messages",
":eventlog_provider_dll_version",
]
}
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