[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 1 | // 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 | |
avi | c5960f3 | 2015-12-22 22:49:48 | [diff] [blame] | 7 | #include <stddef.h> |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 8 | #include <windows.h> |
| 9 | |
| 10 | #include <memory> |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
Hans Wennborg | 22e28d6a | 2020-06-17 17:17:21 | [diff] [blame] | 14 | #include "base/logging.h" |
[email protected] | 9cfb0c3 | 2013-03-02 04:27:49 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 17 | #include "net/base/ip_endpoint.h" |
[email protected] | 9cfb0c3 | 2013-03-02 04:27:49 | [diff] [blame] | 18 | #include "remoting/host/host_status_monitor.h" |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 19 | #include "remoting/host/host_status_observer.h" |
nicholss | e3320ae | 2016-09-16 20:12:59 | [diff] [blame] | 20 | #include "remoting/host/win/remoting_host_messages.h" |
Joe Downing | addcfd8 | 2020-11-17 19:54:33 | [diff] [blame] | 21 | #include "remoting/host/win/windows_event_logger.h" |
[email protected] | be451c8 | 2012-03-20 22:24:47 | [diff] [blame] | 22 | #include "remoting/protocol/transport.h" |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 23 | |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 24 | namespace remoting { |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { |
| 29 | public: |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 30 | HostEventLoggerWin(scoped_refptr<HostStatusMonitor> monitor, |
[email protected] | 9cfb0c3 | 2013-03-02 04:27:49 | [diff] [blame] | 31 | const std::string& application_name); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 32 | |
Peter Boström | e9178e4 | 2021-09-22 18:11:49 | [diff] [blame] | 33 | HostEventLoggerWin(const HostEventLoggerWin&) = delete; |
| 34 | HostEventLoggerWin& operator=(const HostEventLoggerWin&) = delete; |
| 35 | |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 36 | ~HostEventLoggerWin() override; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 37 | |
| 38 | // HostStatusObserver implementation. These methods will be called from the |
| 39 | // network thread. |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 40 | 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] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 44 | const std::string& jid, |
| 45 | const std::string& channel_name, |
mostynb | 11d989c | 2014-10-08 16:58:09 | [diff] [blame] | 46 | const protocol::TransportRoute& route) override; |
nick | 697f429 | 2015-04-23 18:22:31 | [diff] [blame] | 47 | void OnStart(const std::string& xmpp_login) override; |
| 48 | void OnShutdown() override; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 49 | |
| 50 | private: |
| 51 | void LogString(WORD type, DWORD event_id, const std::string& string); |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 52 | void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 53 | |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 54 | scoped_refptr<HostStatusMonitor> monitor_; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 55 | |
Joe Downing | addcfd8 | 2020-11-17 19:54:33 | [diff] [blame] | 56 | WindowsEventLogger event_logger_; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 57 | }; |
| 58 | |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 59 | } // namespace |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 60 | |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 61 | HostEventLoggerWin::HostEventLoggerWin(scoped_refptr<HostStatusMonitor> monitor, |
[email protected] | be451c8 | 2012-03-20 22:24:47 | [diff] [blame] | 62 | const std::string& application_name) |
Joe Downing | addcfd8 | 2020-11-17 19:54:33 | [diff] [blame] | 63 | : monitor_(monitor), event_logger_(application_name) { |
| 64 | if (event_logger_.IsRegistered()) { |
[email protected] | 9cfb0c3 | 2013-03-02 04:27:49 | [diff] [blame] | 65 | monitor_->AddStatusObserver(this); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 66 | } else { |
[email protected] | ad8cfa9 | 2014-05-21 20:06:23 | [diff] [blame] | 67 | PLOG(ERROR) << "Failed to register the event source: " << application_name; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | HostEventLoggerWin::~HostEventLoggerWin() { |
Joe Downing | addcfd8 | 2020-11-17 19:54:33 | [diff] [blame] | 72 | if (event_logger_.IsRegistered()) { |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 73 | monitor_->RemoveStatusObserver(this); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { |
| 78 | LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid); |
| 79 | } |
| 80 | |
| 81 | void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) { |
| 82 | LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid); |
| 83 | } |
| 84 | |
| 85 | void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { |
| 86 | LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid); |
| 87 | } |
| 88 | |
| 89 | void HostEventLoggerWin::OnClientRouteChange( |
| 90 | const std::string& jid, |
| 91 | const std::string& channel_name, |
[email protected] | be451c8 | 2012-03-20 22:24:47 | [diff] [blame] | 92 | const protocol::TransportRoute& route) { |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 93 | std::vector<std::string> strings(5); |
| 94 | strings[0] = jid; |
Lambros Lambrou | 6cd55a8 | 2020-10-20 03:46:20 | [diff] [blame] | 95 | 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] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 101 | strings[3] = channel_name; |
| 102 | strings[4] = protocol::TransportRoute::GetTypeString(route.type); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 103 | Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); |
| 104 | } |
| 105 | |
| 106 | void HostEventLoggerWin::OnShutdown() { |
[email protected] | dc22637d6 | 2012-08-31 16:26:24 | [diff] [blame] | 107 | // TODO(rmsousa): Fix host shutdown to actually call this, and add a log line. |
| 108 | } |
| 109 | |
| 110 | void HostEventLoggerWin::OnStart(const std::string& xmpp_login) { |
| 111 | LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_STARTED, xmpp_login); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void HostEventLoggerWin::Log(WORD type, |
| 115 | DWORD event_id, |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 116 | const std::vector<std::string>& strings) { |
Joe Downing | addcfd8 | 2020-11-17 19:54:33 | [diff] [blame] | 117 | if (!event_logger_.Log(type, event_id, strings)) { |
[email protected] | ad8cfa9 | 2014-05-21 20:06:23 | [diff] [blame] | 118 | PLOG(ERROR) << "Failed to write an event to the event log"; |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | void HostEventLoggerWin::LogString(WORD type, |
| 123 | DWORD event_id, |
| 124 | const std::string& string) { |
[email protected] | a11dbe9b | 2012-08-07 01:32:58 | [diff] [blame] | 125 | std::vector<std::string> strings; |
| 126 | strings.push_back(string); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 127 | Log(type, event_id, strings); |
| 128 | } |
| 129 | |
| 130 | // static |
dcheng | 0765c49 | 2016-04-06 22:41:53 | [diff] [blame] | 131 | std::unique_ptr<HostEventLogger> HostEventLogger::Create( |
Sergey Ulanov | cc04df9 | 2017-07-07 18:33:41 | [diff] [blame] | 132 | scoped_refptr<HostStatusMonitor> monitor, |
[email protected] | 9cfb0c3 | 2013-03-02 04:27:49 | [diff] [blame] | 133 | const std::string& application_name) { |
Jinho Bang | 138fde3 | 2018-01-18 23:13:42 | [diff] [blame] | 134 | return std::make_unique<HostEventLoggerWin>(monitor, application_name); |
[email protected] | 01d0ea2 | 2012-03-02 16:51:45 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | } // namespace remoting |