| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/log_to_server.h" | 5 #include "remoting/host/log_to_server.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/host/chromoting_host.h" | 10 #include "remoting/host/chromoting_host.h" |
| 11 #include "remoting/host/server_log_entry.h" | 11 #include "remoting/host/server_log_entry.h" |
| 12 #include "remoting/jingle_glue/iq_sender.h" | 12 #include "remoting/jingle_glue/iq_sender.h" |
| 13 #include "remoting/jingle_glue/jingle_thread.h" | 13 #include "remoting/jingle_glue/jingle_thread.h" |
| 14 #include "remoting/jingle_glue/signal_strategy.h" | 14 #include "remoting/jingle_glue/signal_strategy.h" |
| 15 #include "remoting/protocol/transport.h" | 15 #include "remoting/protocol/transport.h" |
| 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 17 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 17 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 18 | 18 |
| 19 using buzz::QName; | 19 using buzz::QName; |
| 20 using buzz::XmlElement; | 20 using buzz::XmlElement; |
| 21 | 21 |
| 22 namespace remoting { | 22 namespace remoting { |
| 23 | 23 |
| 24 LogToServer::LogToServer(ChromotingHost* host, | 24 LogToServer::LogToServer(ChromotingHost* host, |
| 25 ServerLogEntry::Mode mode, | 25 ServerLogEntry::Mode mode, |
| 26 SignalStrategy* signal_strategy) | 26 SignalStrategy* signal_strategy) |
| 27 : host_(host), | 27 : host_(host), |
| 28 mode_(mode), | 28 mode_(mode), |
| 29 signal_strategy_(signal_strategy), | 29 signal_strategy_(signal_strategy) { |
| 30 connection_type_set_(false) { | |
| 31 signal_strategy_->AddListener(this); | 30 signal_strategy_->AddListener(this); |
| 32 | 31 |
| 33 // |host| may be NULL in tests. | 32 // |host| may be NULL in tests. |
| 34 if (host_) | 33 if (host_) |
| 35 host_->AddStatusObserver(this); | 34 host_->AddStatusObserver(this); |
| 36 } | 35 } |
| 37 | 36 |
| 38 LogToServer::~LogToServer() { | 37 LogToServer::~LogToServer() { |
| 39 signal_strategy_->RemoveListener(this); | 38 signal_strategy_->RemoveListener(this); |
| 40 if (host_) | 39 if (host_) |
| 41 host_->RemoveStatusObserver(this); | 40 host_->RemoveStatusObserver(this); |
| 42 } | 41 } |
| 43 | 42 |
| 44 void LogToServer::LogSessionStateChange(bool connected) { | 43 void LogToServer::LogSessionStateChange(const std::string& jid, |
| 44 bool connected) { |
| 45 DCHECK(CalledOnValidThread()); | 45 DCHECK(CalledOnValidThread()); |
| 46 | 46 |
| 47 scoped_ptr<ServerLogEntry> entry( | 47 scoped_ptr<ServerLogEntry> entry( |
| 48 ServerLogEntry::MakeForSessionStateChange(connected)); | 48 ServerLogEntry::MakeForSessionStateChange(connected)); |
| 49 entry->AddHostFields(); | 49 entry->AddHostFields(); |
| 50 entry->AddModeField(mode_); | 50 entry->AddModeField(mode_); |
| 51 | 51 |
| 52 if (connected) { | 52 if (connected) { |
| 53 DCHECK(connection_type_set_); | 53 DCHECK(connection_route_type_.count(jid) == 1); |
| 54 entry->AddConnectionTypeField(connection_type_); | 54 entry->AddConnectionTypeField(connection_route_type_[jid]); |
| 55 } | 55 } |
| 56 Log(*entry.get()); | 56 Log(*entry.get()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { | 59 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { |
| 60 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
| 61 | 61 |
| 62 if (state == SignalStrategy::CONNECTED) { | 62 if (state == SignalStrategy::CONNECTED) { |
| 63 iq_sender_.reset(new IqSender(signal_strategy_)); | 63 iq_sender_.reset(new IqSender(signal_strategy_)); |
| 64 SendPendingEntries(); | 64 SendPendingEntries(); |
| 65 } else if (state == SignalStrategy::DISCONNECTED) { | 65 } else if (state == SignalStrategy::DISCONNECTED) { |
| 66 iq_sender_.reset(); | 66 iq_sender_.reset(); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void LogToServer::OnClientConnected(const std::string& jid) { | 70 void LogToServer::OnClientConnected(const std::string& jid) { |
| 71 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
| 72 LogSessionStateChange(true); | 72 LogSessionStateChange(jid, true); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void LogToServer::OnClientDisconnected(const std::string& jid) { | 75 void LogToServer::OnClientDisconnected(const std::string& jid) { |
| 76 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
| 77 LogSessionStateChange(false); | 77 LogSessionStateChange(jid, false); |
| 78 connection_type_set_ = false; | 78 connection_route_type_.erase(jid); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void LogToServer::OnClientRouteChange(const std::string& jid, | 81 void LogToServer::OnClientRouteChange(const std::string& jid, |
| 82 const std::string& channel_name, | 82 const std::string& channel_name, |
| 83 const protocol::TransportRoute& route) { | 83 const protocol::TransportRoute& route) { |
| 84 // Store connection type for the video channel. It is logged later | 84 // Store connection type for the video channel. It is logged later |
| 85 // when client authentication is finished. | 85 // when client authentication is finished. |
| 86 if (channel_name == kVideoChannelName) { | 86 if (channel_name == kVideoChannelName) { |
| 87 connection_type_ = route.type; | 87 connection_route_type_[jid] = route.type; |
| 88 connection_type_set_ = true; | |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 void LogToServer::Log(const ServerLogEntry& entry) { | 91 void LogToServer::Log(const ServerLogEntry& entry) { |
| 93 pending_entries_.push_back(entry); | 92 pending_entries_.push_back(entry); |
| 94 SendPendingEntries(); | 93 SendPendingEntries(); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void LogToServer::SendPendingEntries() { | 96 void LogToServer::SendPendingEntries() { |
| 98 if (iq_sender_ == NULL) { | 97 if (iq_sender_ == NULL) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 } | 109 } |
| 111 // Send the stanza to the server. | 110 // Send the stanza to the server. |
| 112 scoped_ptr<IqRequest> req = iq_sender_->SendIq( | 111 scoped_ptr<IqRequest> req = iq_sender_->SendIq( |
| 113 buzz::STR_SET, kChromotingBotJid, stanza.Pass(), | 112 buzz::STR_SET, kChromotingBotJid, stanza.Pass(), |
| 114 IqSender::ReplyCallback()); | 113 IqSender::ReplyCallback()); |
| 115 // We ignore any response, so let the IqRequest be destroyed. | 114 // We ignore any response, so let the IqRequest be destroyed. |
| 116 return; | 115 return; |
| 117 } | 116 } |
| 118 | 117 |
| 119 } // namespace remoting | 118 } // namespace remoting |
| OLD | NEW |