| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/host_event_logger.h" | 5 #include "remoting/host/host_event_logger.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
| 16 #include "remoting/host/chromoting_host.h" | 16 #include "remoting/host/chromoting_host.h" |
| 17 #include "remoting/host/host_status_observer.h" | 17 #include "remoting/host/host_status_observer.h" |
| 18 #include "remoting/protocol/transport.h" |
| 18 | 19 |
| 19 #include "remoting_host_messages.h" | 20 #include "remoting_host_messages.h" |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { | 26 class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { |
| 26 public: | 27 public: |
| 27 HostEventLoggerWin(ChromotingHost* host, | 28 HostEventLoggerWin(ChromotingHost* host, |
| 28 const std::string& application_name); | 29 const std::string& application_name); |
| 29 | 30 |
| 30 virtual ~HostEventLoggerWin(); | 31 virtual ~HostEventLoggerWin(); |
| 31 | 32 |
| 32 // HostStatusObserver implementation. These methods will be called from the | 33 // HostStatusObserver implementation. These methods will be called from the |
| 33 // network thread. | 34 // network thread. |
| 34 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; | 35 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; |
| 35 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; | 36 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; |
| 36 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; | 37 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; |
| 37 virtual void OnClientRouteChange( | 38 virtual void OnClientRouteChange( |
| 38 const std::string& jid, | 39 const std::string& jid, |
| 39 const std::string& channel_name, | 40 const std::string& channel_name, |
| 40 const net::IPEndPoint& remote_end_point, | 41 const protocol::TransportRoute& route) OVERRIDE; |
| 41 const net::IPEndPoint& local_end_point) OVERRIDE; | |
| 42 virtual void OnShutdown() OVERRIDE; | 42 virtual void OnShutdown() OVERRIDE; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 void LogString(WORD type, DWORD event_id, const std::string& string); | 45 void LogString(WORD type, DWORD event_id, const std::string& string); |
| 46 void Log(WORD type, DWORD event_id, const std::vector<string16>& strings); | 46 void Log(WORD type, DWORD event_id, const std::vector<string16>& strings); |
| 47 | 47 |
| 48 scoped_refptr<ChromotingHost> host_; | 48 scoped_refptr<ChromotingHost> host_; |
| 49 | 49 |
| 50 // The handle of the application event log. | 50 // The handle of the application event log. |
| 51 HANDLE event_log_; | 51 HANDLE event_log_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); | 53 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 } //namespace | 56 } //namespace |
| 57 | 57 |
| 58 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, | 58 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, |
| 59 const std::string& application_name) | 59 const std::string& application_name) |
| 60 : host_(host), | 60 : host_(host), |
| 61 event_log_(NULL) { | 61 event_log_(NULL) { |
| 62 event_log_ = RegisterEventSourceW(NULL, | 62 event_log_ = RegisterEventSourceW(NULL, |
| 63 ASCIIToUTF16(application_name).c_str()); | 63 ASCIIToUTF16(application_name).c_str()); |
| 64 if (event_log_ != NULL) { | 64 if (event_log_ != NULL) { |
| 65 host_->AddStatusObserver(this); | 65 host_->AddStatusObserver(this); |
| 66 } else { | 66 } else { |
| 67 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " | 67 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " |
| 68 << application_name; | 68 << application_name; |
| 69 } | 69 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid); | 84 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { | 87 void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { |
| 88 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid); | 88 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void HostEventLoggerWin::OnClientRouteChange( | 91 void HostEventLoggerWin::OnClientRouteChange( |
| 92 const std::string& jid, | 92 const std::string& jid, |
| 93 const std::string& channel_name, | 93 const std::string& channel_name, |
| 94 const net::IPEndPoint& remote_end_point, | 94 const protocol::TransportRoute& route) { |
| 95 const net::IPEndPoint& local_end_point) { | |
| 96 std::vector<string16> strings(4); | 95 std::vector<string16> strings(4); |
| 97 strings[0] = ASCIIToUTF16(jid); | 96 strings[0] = ASCIIToUTF16(jid); |
| 98 strings[1] = ASCIIToUTF16(remote_end_point.ToString()); | 97 strings[1] = ASCIIToUTF16(route.remote_address.ToString()); |
| 99 strings[2] = ASCIIToUTF16(local_end_point.ToString()); | 98 strings[2] = ASCIIToUTF16(route.local_address.ToString()); |
| 100 strings[3] = ASCIIToUTF16(channel_name); | 99 strings[3] = ASCIIToUTF16(channel_name); |
| 100 strings[4] = ASCIIToUTF16( |
| 101 protocol::TransportRoute::GetTypeString(route.type)); |
| 101 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); | 102 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void HostEventLoggerWin::OnShutdown() { | 105 void HostEventLoggerWin::OnShutdown() { |
| 105 } | 106 } |
| 106 | 107 |
| 107 void HostEventLoggerWin::Log(WORD type, | 108 void HostEventLoggerWin::Log(WORD type, |
| 108 DWORD event_id, | 109 DWORD event_id, |
| 109 const std::vector<string16>& strings) { | 110 const std::vector<string16>& strings) { |
| 110 if (event_log_ == NULL) | 111 if (event_log_ == NULL) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 139 } | 140 } |
| 140 | 141 |
| 141 // static | 142 // static |
| 142 scoped_ptr<HostEventLogger> HostEventLogger::Create( | 143 scoped_ptr<HostEventLogger> HostEventLogger::Create( |
| 143 ChromotingHost* host, const std::string& application_name) { | 144 ChromotingHost* host, const std::string& application_name) { |
| 144 return scoped_ptr<HostEventLogger>( | 145 return scoped_ptr<HostEventLogger>( |
| 145 new HostEventLoggerWin(host, application_name)); | 146 new HostEventLoggerWin(host, application_name)); |
| 146 } | 147 } |
| 147 | 148 |
| 148 } // namespace remoting | 149 } // namespace remoting |
| OLD | NEW |