12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/ipc_host_event_logger.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ipc/ipc_sender.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/ip_endpoint.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/chromoting_messages.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/host/host_status_monitor.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "remoting/protocol/transport.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace remoting {
15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IpcHostEventLogger::IpcHostEventLogger(base::WeakPtr<HostStatusMonitor> monitor,
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       IPC::Sender* daemon_channel)
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : daemon_channel_(daemon_channel),
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      monitor_(monitor) {
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  monitor_->AddStatusObserver(this);
21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)IpcHostEventLogger::~IpcHostEventLogger() {
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(CalledOnValidThread());
25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (monitor_.get())
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    monitor_->RemoveStatusObserver(this);
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void IpcHostEventLogger::OnAccessDenied(const std::string& jid) {
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(CalledOnValidThread());
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  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