Fix mouse warp with 2x displays
[chromium-blink-merge.git] / remoting / host / host_event_logger_posix.cc
blob231d683f49d55d9e9158c5d1395a1a5bb5c515ab
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
3 // found in the LICENSE file.
5 #include "remoting/host/host_event_logger.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/base/ip_endpoint.h"
11 #include "remoting/host/host_status_monitor.h"
12 #include "remoting/host/host_status_observer.h"
13 #include "remoting/protocol/transport.h"
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
17 // syslog.h.
18 #include <syslog.h>
20 namespace remoting {
22 namespace {
24 class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver {
25 public:
26 HostEventLoggerPosix(base::WeakPtr<HostStatusMonitor> monitor,
27 const std::string& application_name);
29 ~HostEventLoggerPosix() override;
31 // HostStatusObserver implementation. These methods will be called from the
32 // network thread.
33 void OnClientAuthenticated(const std::string& jid) override;
34 void OnClientDisconnected(const std::string& jid) override;
35 void OnAccessDenied(const std::string& jid) override;
36 void OnClientRouteChange(const std::string& jid,
37 const std::string& channel_name,
38 const protocol::TransportRoute& route) override;
39 void OnStart(const std::string& xmpp_login) override;
40 void OnShutdown() override;
42 private:
43 void Log(const std::string& message);
45 base::WeakPtr<HostStatusMonitor> monitor_;
46 std::string application_name_;
48 DISALLOW_COPY_AND_ASSIGN(HostEventLoggerPosix);
51 } //namespace
53 HostEventLoggerPosix::HostEventLoggerPosix(
54 base::WeakPtr<HostStatusMonitor> monitor,
55 const std::string& application_name)
56 : monitor_(monitor),
57 application_name_(application_name) {
58 openlog(application_name_.c_str(), 0, LOG_USER);
59 monitor_->AddStatusObserver(this);
62 HostEventLoggerPosix::~HostEventLoggerPosix() {
63 if (monitor_.get())
64 monitor_->RemoveStatusObserver(this);
65 closelog();
68 void HostEventLoggerPosix::OnClientAuthenticated(const std::string& jid) {
69 Log("Client connected: " + jid);
72 void HostEventLoggerPosix::OnClientDisconnected(const std::string& jid) {
73 Log("Client disconnected: " + jid);
76 void HostEventLoggerPosix::OnAccessDenied(const std::string& jid) {
77 Log("Access denied for client: " + jid);
80 void HostEventLoggerPosix::OnClientRouteChange(
81 const std::string& jid,
82 const std::string& channel_name,
83 const protocol::TransportRoute& route) {
84 Log(base::StringPrintf(
85 "Channel IP for client: %s ip='%s' host_ip='%s' channel='%s' "
86 "connection='%s'",
87 jid.c_str(), route.remote_address.ToString().c_str(),
88 route.local_address.ToString().c_str(), channel_name.c_str(),
89 protocol::TransportRoute::GetTypeString(route.type).c_str()));
92 void HostEventLoggerPosix::OnShutdown() {
93 // TODO(rmsousa): Fix host shutdown to actually call this, and add a log line.
96 void HostEventLoggerPosix::OnStart(const std::string& xmpp_login) {
97 Log("Host started for user: " + xmpp_login);
100 void HostEventLoggerPosix::Log(const std::string& message) {
101 syslog(LOG_USER | LOG_NOTICE, "%s", message.c_str());
104 // static
105 scoped_ptr<HostEventLogger> HostEventLogger::Create(
106 base::WeakPtr<HostStatusMonitor> monitor,
107 const std::string& application_name) {
108 return make_scoped_ptr(new HostEventLoggerPosix(monitor, application_name));
111 } // namespace remoting