| 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" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_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/host_status_monitor.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, const std::string& application_name); | 28 HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor, |
| 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 protocol::TransportRoute& route) OVERRIDE; | 41 const protocol::TransportRoute& route) OVERRIDE; |
| 41 virtual void OnStart(const std::string& xmpp_login) OVERRIDE; | 42 virtual void OnStart(const std::string& xmpp_login) OVERRIDE; |
| 42 virtual void OnShutdown() OVERRIDE; | 43 virtual void OnShutdown() OVERRIDE; |
| 43 | 44 |
| 44 private: | 45 private: |
| 45 void LogString(WORD type, DWORD event_id, const std::string& string); | 46 void LogString(WORD type, DWORD event_id, const std::string& string); |
| 46 void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings); | 47 void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings); |
| 47 | 48 |
| 48 scoped_refptr<ChromotingHost> host_; | 49 base::WeakPtr<HostStatusMonitor> monitor_; |
| 49 | 50 |
| 50 // The handle of the application event log. | 51 // The handle of the application event log. |
| 51 HANDLE event_log_; | 52 HANDLE event_log_; |
| 52 | 53 |
| 53 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); | 54 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerWin); |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 } //namespace | 57 } //namespace |
| 57 | 58 |
| 58 HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host, | 59 HostEventLoggerWin::HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor, |
| 59 const std::string& application_name) | 60 const std::string& application_name) |
| 60 : host_(host), | 61 : monitor_(monitor), |
| 61 event_log_(NULL) { | 62 event_log_(NULL) { |
| 62 event_log_ = RegisterEventSourceW(NULL, | 63 event_log_ = RegisterEventSourceW(NULL, |
| 63 UTF8ToUTF16(application_name).c_str()); | 64 UTF8ToUTF16(application_name).c_str()); |
| 64 if (event_log_ != NULL) { | 65 if (event_log_ != NULL) { |
| 65 host_->AddStatusObserver(this); | 66 monitor_->AddStatusObserver(this); |
| 66 } else { | 67 } else { |
| 67 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " | 68 LOG_GETLASTERROR(ERROR) << "Failed to register the event source: " |
| 68 << application_name; | 69 << application_name; |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 HostEventLoggerWin::~HostEventLoggerWin() { | 73 HostEventLoggerWin::~HostEventLoggerWin() { |
| 73 if (event_log_ != NULL) { | 74 if (event_log_ != NULL) { |
| 74 host_->RemoveStatusObserver(this); | 75 if (monitor_) |
| 76 monitor_->RemoveStatusObserver(this); |
| 75 DeregisterEventSource(event_log_); | 77 DeregisterEventSource(event_log_); |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { | 81 void HostEventLoggerWin::OnClientAuthenticated(const std::string& jid) { |
| 80 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid); | 82 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_CONNECTED, jid); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) { | 85 void HostEventLoggerWin::OnClientDisconnected(const std::string& jid) { |
| 84 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid); | 86 LogString(EVENTLOG_INFORMATION_TYPE, MSG_HOST_CLIENT_DISCONNECTED, jid); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 void HostEventLoggerWin::LogString(WORD type, | 142 void HostEventLoggerWin::LogString(WORD type, |
| 141 DWORD event_id, | 143 DWORD event_id, |
| 142 const std::string& string) { | 144 const std::string& string) { |
| 143 std::vector<std::string> strings; | 145 std::vector<std::string> strings; |
| 144 strings.push_back(string); | 146 strings.push_back(string); |
| 145 Log(type, event_id, strings); | 147 Log(type, event_id, strings); |
| 146 } | 148 } |
| 147 | 149 |
| 148 // static | 150 // static |
| 149 scoped_ptr<HostEventLogger> HostEventLogger::Create( | 151 scoped_ptr<HostEventLogger> HostEventLogger::Create( |
| 150 ChromotingHost* host, const std::string& application_name) { | 152 base::WeakPtr<HostStatusMonitor> monitor, |
| 153 const std::string& application_name) { |
| 151 return scoped_ptr<HostEventLogger>( | 154 return scoped_ptr<HostEventLogger>( |
| 152 new HostEventLoggerWin(host, application_name)); | 155 new HostEventLoggerWin(monitor, application_name)); |
| 153 } | 156 } |
| 154 | 157 |
| 155 } // namespace remoting | 158 } // namespace remoting |
| OLD | NEW |