Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / remoting / host / host_status_logger.cc
blob48fe64396ebe63254921ef351e2a779ec88f42fe
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 "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"
15 namespace remoting {
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);
26 HostStatusLogger::~HostStatusLogger() {
27 if (monitor_.get())
28 monitor_->RemoveStatusObserver(this);
31 void HostStatusLogger::LogSessionStateChange(const std::string& jid,
32 bool connected) {
33 DCHECK(CalledOnValidThread());
35 scoped_ptr<ServerLogEntry> entry(
36 MakeLogEntryForSessionStateChange(connected));
37 AddHostFieldsToLogEntry(entry.get());
38 entry->AddModeField(log_to_server_.mode());
40 if (connected) {
41 DCHECK_EQ(connection_route_type_.count(jid), 1u);
42 AddConnectionTypeToLogEntry(entry.get(), connection_route_type_[jid]);
44 log_to_server_.Log(*entry.get());
47 void HostStatusLogger::OnClientConnected(const std::string& jid) {
48 DCHECK(CalledOnValidThread());
49 LogSessionStateChange(jid, true);
52 void HostStatusLogger::OnClientDisconnected(const std::string& jid) {
53 DCHECK(CalledOnValidThread());
54 LogSessionStateChange(jid, false);
55 connection_route_type_.erase(jid);
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;
69 void HostStatusLogger::SetSignalingStateForTest(SignalStrategy::State state) {
70 log_to_server_.OnSignalStrategyStateChange(state);
73 } // namespace remoting