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 "base/memory/ref_counted.h" | |
8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/weak_ptr.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
11 #include "remoting/host/chromoting_host.h" | 11 #include "remoting/host/host_status_monitor.h" |
12 #include "remoting/host/host_status_observer.h" | 12 #include "remoting/host/host_status_observer.h" |
13 #include "remoting/protocol/transport.h" | 13 #include "remoting/protocol/transport.h" |
14 | 14 |
15 // Included here, since the #define for LOG_USER in syslog.h conflicts with the | 15 // Included here, since the #define for LOG_USER in syslog.h conflicts with the |
16 // constants in base/logging.h, and this source file should use the version in | 16 // constants in base/logging.h, and this source file should use the version in |
17 // syslog.h. | 17 // syslog.h. |
18 #include <syslog.h> | 18 #include <syslog.h> |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver { | 24 class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver { |
25 public: | 25 public: |
26 HostEventLoggerPosix(ChromotingHost* host, | 26 HostEventLoggerPosix(base::WeakPtr<HostStatusMonitor> monitor, |
27 const std::string& application_name); | 27 const std::string& application_name); |
28 | 28 |
29 virtual ~HostEventLoggerPosix(); | 29 virtual ~HostEventLoggerPosix(); |
30 | 30 |
31 // HostStatusObserver implementation. These methods will be called from the | 31 // HostStatusObserver implementation. These methods will be called from the |
32 // network thread. | 32 // network thread. |
33 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; | 33 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; |
34 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; | 34 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; |
35 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; | 35 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; |
36 virtual void OnClientRouteChange( | 36 virtual void OnClientRouteChange( |
37 const std::string& jid, | 37 const std::string& jid, |
38 const std::string& channel_name, | 38 const std::string& channel_name, |
39 const protocol::TransportRoute& route) OVERRIDE; | 39 const protocol::TransportRoute& route) OVERRIDE; |
40 virtual void OnStart(const std::string& xmpp_login) OVERRIDE; | 40 virtual void OnStart(const std::string& xmpp_login) OVERRIDE; |
41 virtual void OnShutdown() OVERRIDE; | 41 virtual void OnShutdown() OVERRIDE; |
42 | 42 |
43 private: | 43 private: |
44 void Log(const std::string& message); | 44 void Log(const std::string& message); |
45 | 45 |
46 scoped_refptr<ChromotingHost> host_; | 46 base::WeakPtr<HostStatusMonitor> monitor_; |
47 std::string application_name_; | 47 std::string application_name_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerPosix); | 49 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerPosix); |
50 }; | 50 }; |
51 | 51 |
52 } //namespace | 52 } //namespace |
53 | 53 |
54 HostEventLoggerPosix::HostEventLoggerPosix(ChromotingHost* host, | 54 HostEventLoggerPosix::HostEventLoggerPosix( |
55 const std::string& application_name) | 55 base::WeakPtr<HostStatusMonitor> monitor, |
56 : host_(host), | 56 const std::string& application_name) |
| 57 : monitor_(monitor), |
57 application_name_(application_name) { | 58 application_name_(application_name) { |
58 openlog(application_name_.c_str(), 0, LOG_USER); | 59 openlog(application_name_.c_str(), 0, LOG_USER); |
59 host_->AddStatusObserver(this); | 60 monitor_->AddStatusObserver(this); |
60 } | 61 } |
61 | 62 |
62 HostEventLoggerPosix::~HostEventLoggerPosix() { | 63 HostEventLoggerPosix::~HostEventLoggerPosix() { |
63 host_->RemoveStatusObserver(this); | 64 if (monitor_) |
| 65 monitor_->RemoveStatusObserver(this); |
64 closelog(); | 66 closelog(); |
65 } | 67 } |
66 | 68 |
67 void HostEventLoggerPosix::OnClientAuthenticated(const std::string& jid) { | 69 void HostEventLoggerPosix::OnClientAuthenticated(const std::string& jid) { |
68 Log("Client connected: " + jid); | 70 Log("Client connected: " + jid); |
69 } | 71 } |
70 | 72 |
71 void HostEventLoggerPosix::OnClientDisconnected(const std::string& jid) { | 73 void HostEventLoggerPosix::OnClientDisconnected(const std::string& jid) { |
72 Log("Client disconnected: " + jid); | 74 Log("Client disconnected: " + jid); |
73 } | 75 } |
(...skipping 21 matching lines...) Expand all Loading... |
95 void HostEventLoggerPosix::OnStart(const std::string& xmpp_login) { | 97 void HostEventLoggerPosix::OnStart(const std::string& xmpp_login) { |
96 Log("Host started for user: " + xmpp_login); | 98 Log("Host started for user: " + xmpp_login); |
97 } | 99 } |
98 | 100 |
99 void HostEventLoggerPosix::Log(const std::string& message) { | 101 void HostEventLoggerPosix::Log(const std::string& message) { |
100 syslog(LOG_USER | LOG_NOTICE, "%s", message.c_str()); | 102 syslog(LOG_USER | LOG_NOTICE, "%s", message.c_str()); |
101 } | 103 } |
102 | 104 |
103 // static | 105 // static |
104 scoped_ptr<HostEventLogger> HostEventLogger::Create( | 106 scoped_ptr<HostEventLogger> HostEventLogger::Create( |
105 ChromotingHost* host, const std::string& application_name) { | 107 base::WeakPtr<HostStatusMonitor> monitor, |
| 108 const std::string& application_name) { |
106 return scoped_ptr<HostEventLogger>( | 109 return scoped_ptr<HostEventLogger>( |
107 new HostEventLoggerPosix(host, application_name)); | 110 new HostEventLoggerPosix(monitor, application_name)); |
108 } | 111 } |
109 | 112 |
110 } // namespace remoting | 113 } // namespace remoting |
OLD | NEW |