1// Copyright (c) 2013 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.
4
5#include "remoting/host/ipc_host_event_logger.h"
6
7#include "base/logging.h"
8#include "ipc/ipc_sender.h"
9#include "net/base/ip_endpoint.h"
10#include "remoting/host/chromoting_messages.h"
11#include "remoting/host/host_status_monitor.h"
12#include "remoting/protocol/transport.h"
13
14namespace remoting {
15
16IpcHostEventLogger::IpcHostEventLogger(base::WeakPtr<HostStatusMonitor> monitor,
17                                       IPC::Sender* daemon_channel)
18    : daemon_channel_(daemon_channel),
19      monitor_(monitor) {
20  monitor_->AddStatusObserver(this);
21}
22
23IpcHostEventLogger::~IpcHostEventLogger() {
24  DCHECK(CalledOnValidThread());
25
26  if (monitor_.get())
27    monitor_->RemoveStatusObserver(this);
28}
29
30void IpcHostEventLogger::OnAccessDenied(const std::string& jid) {
31  DCHECK(CalledOnValidThread());
32
33  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_AccessDenied(jid));
34}
35
36void IpcHostEventLogger::OnClientAuthenticated(const std::string& jid) {
37  DCHECK(CalledOnValidThread());
38
39  daemon_channel_->Send(
40      new ChromotingNetworkDaemonMsg_ClientAuthenticated(jid));
41}
42
43void IpcHostEventLogger::OnClientConnected(const std::string& jid) {
44  DCHECK(CalledOnValidThread());
45
46  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_ClientConnected(jid));
47}
48
49void IpcHostEventLogger::OnClientDisconnected(const std::string& jid) {
50  DCHECK(CalledOnValidThread());
51
52  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_ClientDisconnected(jid));
53}
54
55void IpcHostEventLogger::OnClientRouteChange(
56    const std::string& jid,
57    const std::string& channel_name,
58    const protocol::TransportRoute& route) {
59  DCHECK(CalledOnValidThread());
60
61  SerializedTransportRoute serialized_route;
62  serialized_route.type = route.type;
63  serialized_route.remote_address = route.remote_address.address();
64  serialized_route.remote_port = route.remote_address.port();
65  serialized_route.local_address = route.local_address.address();
66  serialized_route.local_port = route.local_address.port();
67
68  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_ClientRouteChange(
69      jid, channel_name, serialized_route));
70}
71
72void IpcHostEventLogger::OnShutdown() {
73  DCHECK(CalledOnValidThread());
74
75  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_HostShutdown());
76}
77
78void IpcHostEventLogger::OnStart(const std::string& xmpp_login) {
79  DCHECK(CalledOnValidThread());
80
81  daemon_channel_->Send(new ChromotingNetworkDaemonMsg_HostStarted(xmpp_login));
82}
83
84}  // namespace remoting
85