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