1 // Copyright 2014 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/host_status_logger.h" 6 7 #include "base/bind.h" 8 #include "base/message_loop/message_loop_proxy.h" 9 #include "remoting/base/constants.h" 10 #include "remoting/host/host_status_monitor.h" 11 #include "remoting/host/server_log_entry_host.h" 12 #include "remoting/protocol/transport.h" 13 #include "remoting/signaling/server_log_entry.h" 14 15 namespace remoting { 16 17 HostStatusLogger::HostStatusLogger(base::WeakPtr<HostStatusMonitor> monitor, 18 ServerLogEntry::Mode mode, 19 SignalStrategy* signal_strategy, 20 const std::string& directory_bot_jid) 21 : log_to_server_(mode, signal_strategy, directory_bot_jid), 22 monitor_(monitor) { 23 monitor_->AddStatusObserver(this); 24 } 25 26 HostStatusLogger::~HostStatusLogger() { 27 if (monitor_.get()) 28 monitor_->RemoveStatusObserver(this); 29 } 30 31 void HostStatusLogger::LogSessionStateChange(const std::string& jid, 32 bool connected) { 33 DCHECK(CalledOnValidThread()); 34 35 scoped_ptr<ServerLogEntry> entry( 36 MakeLogEntryForSessionStateChange(connected)); 37 AddHostFieldsToLogEntry(entry.get()); 38 entry->AddModeField(log_to_server_.mode()); 39 40 if (connected) { 41 DCHECK_EQ(connection_route_type_.count(jid), 1u); 42 AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]); 43 } 44 log_to_server_.Log(*entry.get()); 45 } 46 47 void HostStatusLogger::OnClientConnected(const std::string& jid) { 48 DCHECK(CalledOnValidThread()); 49 LogSessionStateChange(jid, true); 50 } 51 52 void HostStatusLogger::OnClientDisconnected(const std::string& jid) { 53 DCHECK(CalledOnValidThread()); 54 LogSessionStateChange(jid, false); 55 connection_route_type_.erase(jid); 56 } 57 58 void HostStatusLogger::OnClientRouteChange( 59 const std::string& jid, 60 const std::string& channel_name, 61 const protocol::TransportRoute& route) { 62 // Store connection type for the video channel. It is logged later 63 // when client authentication is finished. 64 if (channel_name == kVideoChannelName) { 65 connection_route_type_[jid] = route.type; 66 } 67 } 68 69 void HostStatusLogger::SetSignalingStateForTest(SignalStrategy::State state) { 70 log_to_server_.OnSignalStrategyStateChange(state); 71 } 72 73 } // namespace remoting 74