Update SplitString calls to new form
[chromium-blink-merge.git] / remoting / host / host_status_logger.cc
blobd2407eeb8b0d94f16296fee4344a32881991f0ee
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.
5 #include "remoting/host/host_status_logger.h"
7 #include "base/bind.h"
8 #include "remoting/base/constants.h"
9 #include "remoting/host/host_status_monitor.h"
10 #include "remoting/host/server_log_entry_host.h"
11 #include "remoting/protocol/transport.h"
12 #include "remoting/signaling/server_log_entry.h"
14 namespace remoting {
16 HostStatusLogger::HostStatusLogger(base::WeakPtr<HostStatusMonitor> monitor,
17 ServerLogEntry::Mode mode,
18 SignalStrategy* signal_strategy,
19 const std::string& directory_bot_jid)
20 : log_to_server_(mode, signal_strategy, directory_bot_jid),
21 monitor_(monitor) {
22 monitor_->AddStatusObserver(this);
25 HostStatusLogger::~HostStatusLogger() {
26 if (monitor_.get())
27 monitor_->RemoveStatusObserver(this);
30 void HostStatusLogger::LogSessionStateChange(const std::string& jid,
31 bool connected) {
32 DCHECK(CalledOnValidThread());
34 scoped_ptr<ServerLogEntry> entry(
35 MakeLogEntryForSessionStateChange(connected));
36 AddHostFieldsToLogEntry(entry.get());
37 entry->AddModeField(log_to_server_.mode());
39 if (connected) {
40 DCHECK_EQ(connection_route_type_.count(jid), 1u);
41 AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]);
43 log_to_server_.Log(*entry.get());
46 void HostStatusLogger::OnClientConnected(const std::string& jid) {
47 DCHECK(CalledOnValidThread());
48 LogSessionStateChange(jid, true);
51 void HostStatusLogger::OnClientDisconnected(const std::string& jid) {
52 DCHECK(CalledOnValidThread());
53 LogSessionStateChange(jid, false);
54 connection_route_type_.erase(jid);
57 void HostStatusLogger::OnClientRouteChange(
58 const std::string& jid,
59 const std::string& channel_name,
60 const protocol::TransportRoute& route) {
61 // Store connection type for the video channel. It is logged later
62 // when client authentication is finished.
63 if (channel_name == kVideoChannelName) {
64 connection_route_type_[jid] = route.type;
68 void HostStatusLogger::SetSignalingStateForTest(SignalStrategy::State state) {
69 log_to_server_.OnSignalStrategyStateChange(state);
72 } // namespace remoting