blob: e68c75d0612022b167ba8183a1038cdab0f8896d [file] [log] [blame]
[email protected]01d0ea22012-03-02 16:51:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/host/host_event_logger.h"
6
avic5960f32015-12-22 22:49:487#include <stddef.h>
dcheng0765c492016-04-06 22:41:538#include <windows.h>
9
10#include <memory>
[email protected]01d0ea22012-03-02 16:51:4511#include <string>
12#include <vector>
13
Hans Wennborg22e28d6a2020-06-17 17:17:2114#include "base/logging.h"
[email protected]9cfb0c32013-03-02 04:27:4915#include "base/memory/weak_ptr.h"
[email protected]906265872013-06-07 22:40:4516#include "base/strings/utf_string_conversions.h"
[email protected]01d0ea22012-03-02 16:51:4517#include "net/base/ip_endpoint.h"
[email protected]9cfb0c32013-03-02 04:27:4918#include "remoting/host/host_status_monitor.h"
[email protected]01d0ea22012-03-02 16:51:4519#include "remoting/host/host_status_observer.h"
nicholsse3320ae2016-09-16 20:12:5920#include "remoting/host/win/remoting_host_messages.h"
Joe Downingaddcfd82020-11-17 19:54:3321#include "remoting/host/win/windows_event_logger.h"
[email protected]be451c82012-03-20 22:24:4722#include "remoting/protocol/transport.h"
[email protected]01d0ea22012-03-02 16:51:4523
[email protected]01d0ea22012-03-02 16:51:4524namespace remoting {
25
26namespace {
27
28class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver {
29 public:
Sergey Ulanovcc04df92017-07-07 18:33:4130 HostEventLoggerWin(scoped_refptr<HostStatusMonitor> monitor,
[email protected]9cfb0c32013-03-02 04:27:4931 const std::string& application_name);
[email protected]01d0ea22012-03-02 16:51:4532
Peter Boströme9178e42021-09-22 18:11:4933 HostEventLoggerWin(const HostEventLoggerWin&) = delete;
34 HostEventLoggerWin& operator=(const HostEventLoggerWin&) = delete;
35
nick697f4292015-04-23 18:22:3136 ~HostEventLoggerWin() override;
[email protected]01d0ea22012-03-02 16:51:4537
38 // HostStatusObserver implementation. These methods will be called from the
39 // network thread.
nick697f4292015-04-23 18:22:3140 void OnClientAuthenticated(const std::string& jid) override;
41 void OnClientDisconnected(const std::string& jid) override;
42 void OnAccessDenied(const std::string& jid) override;
43 void OnClientRouteChange(
[email protected]01d0ea22012-03-02 16:51:4544 const std::string& jid,
45 const std::string& channel_name,
mostynb11d989c2014-10-08 16:58:0946 const protocol::TransportRoute& route) override;
nick697f4292015-04-23 18:22:3147 void OnStart(const std::string& xmpp_login) override;
48 void OnShutdown() override;
[email protected]01d0ea22012-03-02 16:51:4549
50 private:
51 void LogString(WORD type, DWORD event_id, const std::string& string);
[email protected]a11dbe9b2012-08-07 01:32:5852 void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings);
[email protected]01d0ea22012-03-02 16:51:4553
Sergey Ulanovcc04df92017-07-07 18:33:4154 scoped_refptr<HostStatusMonitor> monitor_;
[email protected]01d0ea22012-03-02 16:51:4555
Joe Downingaddcfd82020-11-17 19:54:3356 WindowsEventLogger event_logger_;
[email protected]01d0ea22012-03-02 16:51:4557};
58
Sergey Ulanovcc04df92017-07-07 18:33:4159} // namespace
[email protected]01d0ea22012-03-02 16:51:4560
Sergey Ulanovcc04df92017-07-07 18:33:4161HostEventLoggerWin::HostEventLoggerWin(scoped_refptr<HostStatusMonitor> monitor,
[email protected]be451c82012-03-20 22:24:4762 const std::string& application_name)
Joe Downingaddcfd82020-11-17 19:54:3363 : monitor_(monitor), event_logger_(application_name) {
64 if (event_logger_.IsRegistered()) {
[email protected]9cfb0c32013-03-02 04:27:4965 monitor_->AddStatusObserver(this);
[email protected]01d0ea22012-03-02 16:51:4566 } else {
[email protected]ad8cfa92014-05-21 20:06:2367 PLOG(ERROR) << "Failed to register the event source: " << application_name;
[email protected]01d0ea22012-03-02 16:51:4568 }
69}
70
71HostEventLoggerWin::~HostEventLoggerWin() {
Joe Downingaddcfd82020-11-17 19:54:3372 if (event_logger_.IsRegistered()) {
Sergey Ulanovcc04df92017-07-07 18:33:4173 monitor_->RemoveStatusObserver(this);
[email protected]01d0ea22012-03-02 16:51:4574 }
75}
76
77void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) {
78 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid);
79}
80
81void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) {
82 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid);
83}
84
85void HostEventLoggerWin::OnAccessDenied(const std::string& jid) {
86 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid);
87}
88
89void HostEventLoggerWin::OnClientRouteChange(
90 const std::string& jid,
91 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:4792 const protocol::TransportRoute& route) {
[email protected]a11dbe9b2012-08-07 01:32:5893 std::vector<std::string> strings(5);
94 strings[0] = jid;
Lambros Lambrou6cd55a82020-10-20 03:46:2095 strings[1] = route.remote_address.address().IsValid()
96 ? route.remote_address.ToString()
97 : "unknown";
98 strings[2] = route.local_address.address().IsValid()
99 ? route.local_address.ToString()
100 : "unknown";
[email protected]a11dbe9b2012-08-07 01:32:58101 strings[3] = channel_name;
102 strings[4] = protocol::TransportRoute::GetTypeString(route.type);
[email protected]01d0ea22012-03-02 16:51:45103 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings);
104}
105
106void HostEventLoggerWin::OnShutdown() {
[email protected]dc22637d62012-08-31 16:26:24107 // TODO(rmsousa): Fix host shutdown to actually call this, and add a log line.
108}
109
110void HostEventLoggerWin::OnStart(const std::string& xmpp_login) {
111 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_STARTED, xmpp_login);
[email protected]01d0ea22012-03-02 16:51:45112}
113
114void HostEventLoggerWin::Log(WORD type,
115 DWORD event_id,
[email protected]a11dbe9b2012-08-07 01:32:58116 const std::vector<std::string>& strings) {
Joe Downingaddcfd82020-11-17 19:54:33117 if (!event_logger_.Log(type, event_id, strings)) {
[email protected]ad8cfa92014-05-21 20:06:23118 PLOG(ERROR) << "Failed to write an event to the event log";
[email protected]01d0ea22012-03-02 16:51:45119 }
120}
121
122void HostEventLoggerWin::LogString(WORD type,
123 DWORD event_id,
124 const std::string& string) {
[email protected]a11dbe9b2012-08-07 01:32:58125 std::vector<std::string> strings;
126 strings.push_back(string);
[email protected]01d0ea22012-03-02 16:51:45127 Log(type, event_id, strings);
128}
129
130// static
dcheng0765c492016-04-06 22:41:53131std::unique_ptr<HostEventLogger> HostEventLogger::Create(
Sergey Ulanovcc04df92017-07-07 18:33:41132 scoped_refptr<HostStatusMonitor> monitor,
[email protected]9cfb0c32013-03-02 04:27:49133 const std::string& application_name) {
Jinho Bang138fde32018-01-18 23:13:42134 return std::make_unique<HostEventLoggerWin>(monitor, application_name);
[email protected]01d0ea22012-03-02 16:51:45135}
136
137} // namespace remoting