Index: remoting/host/host_event_logger_win.cc |
diff --git a/remoting/host/host_event_logger_win.cc b/remoting/host/host_event_logger_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fefe21f814176bb0536540c6c87054ba02a0500c |
--- /dev/null |
+++ b/remoting/host/host_event_logger_win.cc |
@@ -0,0 +1,143 @@ |
+// Copyright (c) 2012 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. |
+ |
+#include "remoting/host/host_event_logger.h" |
+ |
+#include <windows.h> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/string16.h" |
+#include "base/utf_string_conversions.h" |
+#include "net/base/ip_endpoint.h" |
+#include "remoting/host/chromoting_host.h" |
+#include "remoting/host/host_status_observer.h" |
+ |
+#include "remoting_host.h" |
+ |
+namespace remoting { |
+ |
+namespace { |
+ |
+class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver { |
+ public: |
+ HostEventLoggerWin(ChromotingHost* host, |
+ const std::string& application_name); |
+ |
+ virtual ~HostEventLoggerWin(); |
+ |
+ // HostStatusObserver implementation. These methods will be called from the |
+ // network thread. |
+ virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; |
+ virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; |
+ virtual void OnAccessDenied(const std::string& jid) OVERRIDE; |
+ virtual void OnClientRouteChange( |
+ const std::string& jid, |
+ const std::string& channel_name, |
+ const net::IPEndPoint& remote_end_point, |
+ const net::IPEndPoint& local_end_point) OVERRIDE; |
+ virtual void OnShutdown() OVERRIDE; |
+ |
+ private: |
+ void Log(DWORD event_id, const std::string& string); |
+ void Log(DWORD event_id, const std::vector<string16>& strings); |
Lambros
2012/03/01 21:15:41
Style guide generally prohibits overloading. Bett
alexeypa (please no reviews)
2012/03/01 22:32:41
Done.
|
+ |
+ scoped_refptr<ChromotingHost> host_; |
+ |
+ // The handle of the application event log. |
+ HANDLE event_log_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); |
+}; |
+ |
+} //namespace |
+ |
+HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, |
+ const std::string& application_name) |
+ : host_(host), |
+ event_log_(NULL) { |
+ event_log_ = RegisterEventSourceW(NULL, |
+ ASCIIToUTF16(application_name).c_str()); |
+ if (event_log_ != NULL) { |
+ host_->AddStatusObserver(this); |
+ } else { |
+ LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " |
+ << application_name; |
+ } |
+} |
+ |
+HostEventLoggerWin::~HostEventLoggerWin() { |
+ if (event_log_ != NULL) { |
+ host_->RemoveStatusObserver(this); |
+ DeregisterEventSource(event_log_); |
+ } |
+} |
+ |
+void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { |
+ Log(MSG_HOST_CLIENT_CONNECTED, jid); |
+} |
+ |
+void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) { |
+ Log(MSG_HOST_CLIENT_DISCONNECTED, jid); |
+} |
+ |
+void HostEventLoggerWin::OnAccessDenied(const std::string& jid) { |
+ Log(MSG_HOST_CLIENT_ACCESS_DENIED, jid); |
+} |
+ |
+void HostEventLoggerWin::OnClientRouteChange( |
+ const std::string& jid, |
+ const std::string& channel_name, |
+ const net::IPEndPoint& remote_end_point, |
+ const net::IPEndPoint& local_end_point) { |
+ std::vector<string16> strings(4); |
+ strings[0] = ASCIIToUTF16(jid); |
+ strings[1] = ASCIIToUTF16(remote_end_point.ToString()); |
+ strings[2] = ASCIIToUTF16(local_end_point.ToString()); |
+ strings[3] = ASCIIToUTF16(channel_name); |
+ Log(MSG_HOST_CLIENT_ROUTING_CHANGED, strings); |
+} |
+ |
+void HostEventLoggerWin::OnShutdown() { |
+} |
+ |
+void HostEventLoggerWin::Log(DWORD event_id, |
+ const std::vector<string16>& strings) { |
+ if (event_log_ == NULL) |
+ return; |
+ |
+ std::vector<const WCHAR*> raw_strings(strings.size()); |
+ for (size_t i = 0; i < strings.size(); ++i) { |
+ raw_strings[i] = strings[i].c_str(); |
Wez
2012/03/01 18:03:06
nit: Add comment to clarify that each string16 ret
alexeypa (please no reviews)
2012/03/01 20:33:58
Done.
|
+ } |
+ |
+ if (!ReportEventW(event_log_, |
+ EVENTLOG_INFORMATION_TYPE, |
Wez
2012/03/01 18:03:06
nit: This should arguably be EVENTLOG_ERROR_TYPE f
alexeypa (please no reviews)
2012/03/01 20:33:58
Done.
|
+ HOST_CATEGORY, |
+ event_id, |
+ NULL, |
+ static_cast<WORD>(raw_strings.size()), |
+ 0, |
+ &raw_strings[0], |
+ NULL)) { |
+ LOG_GETLASTERROR(ERROR) << "Failed to write an event to the event log"; |
+ } |
+} |
+ |
+void HostEventLoggerWin::Log(DWORD event_id, const std::string& string) { |
+ std::vector<string16> strings; |
+ strings.push_back(ASCIIToUTF16(string)); |
+ Log(event_id, strings); |
+} |
+ |
+// static |
+scoped_ptr<HostEventLogger> HostEventLogger::Create( |
+ ChromotingHost* host, const std::string& application_name) { |
+ return scoped_ptr<HostEventLogger>( |
+ new HostEventLoggerWin(host, application_name)); |
+} |
+ |
+} // namespace remoting |