| 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 #include "remoting/protocol/transport.h" |
| 19 | 19 |
| 20 #include "remoting_host_messages.h" | 20 #include "remoting_host_messages.h" |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { | 26 class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { |
| 27 public: | 27 public: |
| 28 HostEventLoggerWin(ChromotingHost* host, | 28 HostEventLoggerWin(ChromotingHost* host, const std::string& application_name); |
| 29 const std::string& application_name); | |
| 30 | 29 |
| 31 virtual ~HostEventLoggerWin(); | 30 virtual ~HostEventLoggerWin(); |
| 32 | 31 |
| 33 // HostStatusObserver implementation. These methods will be called from the | 32 // HostStatusObserver implementation. These methods will be called from the |
| 34 // network thread. | 33 // network thread. |
| 35 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; | 34 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; |
| 36 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; | 35 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; |
| 37 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; | 36 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; |
| 38 virtual void OnClientRouteChange( | 37 virtual void OnClientRouteChange( |
| 39 const std::string& jid, | 38 const std::string& jid, |
| 40 const std::string& channel_name, | 39 const std::string& channel_name, |
| 41 const protocol::TransportRoute& route) OVERRIDE; | 40 const protocol::TransportRoute& route) OVERRIDE; |
| 42 virtual void OnShutdown() OVERRIDE; | 41 virtual void OnShutdown() OVERRIDE; |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 void LogString(WORD type, DWORD event_id, const std::string& string); | 44 void LogString(WORD type, DWORD event_id, const std::string& string); |
| 46 void Log(WORD type, DWORD event_id, const std::vector<string16>& strings); | 45 void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings); |
| 47 | 46 |
| 48 scoped_refptr<ChromotingHost> host_; | 47 scoped_refptr<ChromotingHost> host_; |
| 49 | 48 |
| 50 // The handle of the application event log. | 49 // The handle of the application event log. |
| 51 HANDLE event_log_; | 50 HANDLE event_log_; |
| 52 | 51 |
| 53 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); | 52 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 } //namespace | 55 } //namespace |
| 57 | 56 |
| 58 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, | 57 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, |
| 59 const std::string& application_name) | 58 const std::string& application_name) |
| 60 : host_(host), | 59 : host_(host), |
| 61 event_log_(NULL) { | 60 event_log_(NULL) { |
| 62 event_log_ = RegisterEventSourceW(NULL, | 61 event_log_ = RegisterEventSourceW(NULL, |
| 63 ASCIIToUTF16(application_name).c_str()); | 62 UTF8ToUTF16(application_name).c_str()); |
| 64 if (event_log_ != NULL) { | 63 if (event_log_ != NULL) { |
| 65 host_->AddStatusObserver(this); | 64 host_->AddStatusObserver(this); |
| 66 } else { | 65 } else { |
| 67 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " | 66 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " |
| 68 << application_name; | 67 << application_name; |
| 69 } | 68 } |
| 70 } | 69 } |
| 71 | 70 |
| 72 HostEventLoggerWin::~HostEventLoggerWin() { | 71 HostEventLoggerWin::~HostEventLoggerWin() { |
| 73 if (event_log_ != NULL) { | 72 if (event_log_ != NULL) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 } | 84 } |
| 86 | 85 |
| 87 void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { | 86 void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { |
| 88 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid); | 87 LogString(EVENTLOG_ERROR_TYPE, MSG_HOST_CLIENT_ACCESS_DENIED, jid); |
| 89 } | 88 } |
| 90 | 89 |
| 91 void HostEventLoggerWin::OnClientRouteChange( | 90 void HostEventLoggerWin::OnClientRouteChange( |
| 92 const std::string& jid, | 91 const std::string& jid, |
| 93 const std::string& channel_name, | 92 const std::string& channel_name, |
| 94 const protocol::TransportRoute& route) { | 93 const protocol::TransportRoute& route) { |
| 95 std::vector<string16> strings(5); | 94 std::vector<std::string> strings(5); |
| 96 strings[0] = ASCIIToUTF16(jid); | 95 strings[0] = jid; |
| 97 strings[1] = ASCIIToUTF16(route.remote_address.ToString()); | 96 strings[1] = route.remote_address.ToString(); |
| 98 strings[2] = ASCIIToUTF16(route.local_address.ToString()); | 97 strings[2] = route.local_address.ToString(); |
| 99 strings[3] = ASCIIToUTF16(channel_name); | 98 strings[3] = channel_name; |
| 100 strings[4] = ASCIIToUTF16( | 99 strings[4] = protocol::TransportRoute::GetTypeString(route.type); |
| 101 protocol::TransportRoute::GetTypeString(route.type)); | |
| 102 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); | 100 Log(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_ROUTING_CHANGED, strings); |
| 103 } | 101 } |
| 104 | 102 |
| 105 void HostEventLoggerWin::OnShutdown() { | 103 void HostEventLoggerWin::OnShutdown() { |
| 106 } | 104 } |
| 107 | 105 |
| 108 void HostEventLoggerWin::Log(WORD type, | 106 void HostEventLoggerWin::Log(WORD type, |
| 109 DWORD event_id, | 107 DWORD event_id, |
| 110 const std::vector<string16>& strings) { | 108 const std::vector<std::string>& strings) { |
| 111 if (event_log_ == NULL) | 109 if (event_log_ == NULL) |
| 112 return; | 110 return; |
| 113 | 111 |
| 114 // ReportEventW() takes an array of raw string pointers. They should stay | 112 // ReportEventW() takes an array of raw string pointers. They should stay |
| 115 // valid for the duration of the call. | 113 // valid for the duration of the call. |
| 116 std::vector<const WCHAR*> raw_strings(strings.size()); | 114 std::vector<const WCHAR*> raw_strings(strings.size()); |
| 115 std::vector<string16> utf16_strings(strings.size()); |
| 117 for (size_t i = 0; i < strings.size(); ++i) { | 116 for (size_t i = 0; i < strings.size(); ++i) { |
| 118 raw_strings[i] = strings[i].c_str(); | 117 utf16_strings[i] = UTF8ToUTF16(strings[i]); |
| 118 raw_strings[i] = utf16_strings[i].c_str(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 if (!ReportEventW(event_log_, | 121 if (!ReportEventW(event_log_, |
| 122 type, | 122 type, |
| 123 HOST_CATEGORY, | 123 HOST_CATEGORY, |
| 124 event_id, | 124 event_id, |
| 125 NULL, | 125 NULL, |
| 126 static_cast<WORD>(raw_strings.size()), | 126 static_cast<WORD>(raw_strings.size()), |
| 127 0, | 127 0, |
| 128 &raw_strings[0], | 128 &raw_strings[0], |
| 129 NULL)) { | 129 NULL)) { |
| 130 LOG_GETLASTERROR(ERROR) << "Failed to write an event to the event log"; | 130 LOG_GETLASTERROR(ERROR) << "Failed to write an event to the event log"; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 void HostEventLoggerWin::LogString(WORD type, | 134 void HostEventLoggerWin::LogString(WORD type, |
| 135 DWORD event_id, | 135 DWORD event_id, |
| 136 const std::string& string) { | 136 const std::string& string) { |
| 137 std::vector<string16> strings; | 137 std::vector<std::string> strings; |
| 138 strings.push_back(ASCIIToUTF16(string)); | 138 strings.push_back(string); |
| 139 Log(type, event_id, strings); | 139 Log(type, event_id, strings); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 scoped_ptr<HostEventLogger> HostEventLogger::Create( | 143 scoped_ptr<HostEventLogger> HostEventLogger::Create( |
| 144 ChromotingHost* host, const std::string& application_name) { | 144 ChromotingHost* host, const std::string& application_name) { |
| 145 return scoped_ptr<HostEventLogger>( | 145 return scoped_ptr<HostEventLogger>( |
| 146 new HostEventLoggerWin(host, application_name)); | 146 new HostEventLoggerWin(host, application_name)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace remoting | 149 } // namespace remoting |
| OLD | NEW |