| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 const char kLogCommand[] = "log"; | 25 const char kLogCommand[] = "log"; |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 LogToServer::LogToServer(ChromotingHost* host, | 28 LogToServer::LogToServer(ChromotingHost* host, |
| 29 ServerLogEntry::Mode mode, | 29 ServerLogEntry::Mode mode, |
| 30 SignalStrategy* signal_strategy) | 30 SignalStrategy* signal_strategy) |
| 31 : host_(host), | 31 : host_(host), |
| 32 mode_(mode), | 32 mode_(mode), |
| 33 signal_strategy_(signal_strategy), | 33 signal_strategy_(signal_strategy) { |
| 34 connection_type_set_(false) { | |
| 35 signal_strategy_->AddListener(this); | 34 signal_strategy_->AddListener(this); |
| 36 | 35 |
| 37 // |host| may be NULL in tests. | 36 // |host| may be NULL in tests. |
| 38 if (host_) | 37 if (host_) |
| 39 host_->AddStatusObserver(this); | 38 host_->AddStatusObserver(this); |
| 40 } | 39 } |
| 41 | 40 |
| 42 LogToServer::~LogToServer() { | 41 LogToServer::~LogToServer() { |
| 43 signal_strategy_->RemoveListener(this); | 42 signal_strategy_->RemoveListener(this); |
| 44 if (host_) | 43 if (host_) |
| 45 host_->RemoveStatusObserver(this); | 44 host_->RemoveStatusObserver(this); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void LogToServer::LogSessionStateChange(bool connected) { | 47 void LogToServer::LogSessionStateChange(const std::string& jid, |
| 48 bool connected) { |
| 49 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
| 50 | 50 |
| 51 scoped_ptr<ServerLogEntry> entry( | 51 scoped_ptr<ServerLogEntry> entry( |
| 52 ServerLogEntry::MakeSessionStateChange(connected)); | 52 ServerLogEntry::MakeSessionStateChange(connected)); |
| 53 entry->AddHostFields(); | 53 entry->AddHostFields(); |
| 54 entry->AddModeField(mode_); | 54 entry->AddModeField(mode_); |
| 55 | 55 |
| 56 if (connected) { | 56 if (connected) { |
| 57 DCHECK(connection_type_set_); | 57 DCHECK(connection_route_type_.count(jid) == 1); |
| 58 entry->AddConnectionTypeField(connection_type_); | 58 entry->AddConnectionTypeField(connection_route_type_[jid]); |
| 59 } | 59 } |
| 60 Log(*entry.get()); | 60 Log(*entry.get()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { | 63 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { |
| 64 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 65 | 65 |
| 66 if (state == SignalStrategy::CONNECTED) { | 66 if (state == SignalStrategy::CONNECTED) { |
| 67 iq_sender_.reset(new IqSender(signal_strategy_)); | 67 iq_sender_.reset(new IqSender(signal_strategy_)); |
| 68 SendPendingEntries(); | 68 SendPendingEntries(); |
| 69 } else if (state == SignalStrategy::DISCONNECTED) { | 69 } else if (state == SignalStrategy::DISCONNECTED) { |
| 70 iq_sender_.reset(); | 70 iq_sender_.reset(); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void LogToServer::OnClientAuthenticated(const std::string& jid) { | 74 void LogToServer::OnClientAuthenticated(const std::string& jid) { |
| 75 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
| 76 LogSessionStateChange(true); | 76 LogSessionStateChange(jid, true); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void LogToServer::OnClientDisconnected(const std::string& jid) { | 79 void LogToServer::OnClientDisconnected(const std::string& jid) { |
| 80 DCHECK(CalledOnValidThread()); | 80 DCHECK(CalledOnValidThread()); |
| 81 LogSessionStateChange(false); | 81 LogSessionStateChange(jid, false); |
| 82 connection_type_set_ = false; | 82 connection_route_type_.erase(jid); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void LogToServer::OnAccessDenied(const std::string& jid) { | 85 void LogToServer::OnAccessDenied(const std::string& jid) { |
| 86 } | 86 } |
| 87 | 87 |
| 88 void LogToServer::OnClientRouteChange(const std::string& jid, | 88 void LogToServer::OnClientRouteChange(const std::string& jid, |
| 89 const std::string& channel_name, | 89 const std::string& channel_name, |
| 90 const protocol::TransportRoute& route) { | 90 const protocol::TransportRoute& route) { |
| 91 // Store connection type for the video channel. It is logged later | 91 // Store connection type for the video channel. It is logged later |
| 92 // when client authentication is finished. | 92 // when client authentication is finished. |
| 93 if (channel_name == kVideoChannelName) { | 93 if (channel_name == kVideoChannelName) { |
| 94 connection_type_ = route.type; | 94 connection_route_type_[jid] = route.type; |
| 95 connection_type_set_ = true; | |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 void LogToServer::OnShutdown() { | 98 void LogToServer::OnShutdown() { |
| 100 } | 99 } |
| 101 | 100 |
| 102 void LogToServer::Log(const ServerLogEntry& entry) { | 101 void LogToServer::Log(const ServerLogEntry& entry) { |
| 103 pending_entries_.push_back(entry); | 102 pending_entries_.push_back(entry); |
| 104 SendPendingEntries(); | 103 SendPendingEntries(); |
| 105 } | 104 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 } | 120 } |
| 122 // Send the stanza to the server. | 121 // Send the stanza to the server. |
| 123 scoped_ptr<IqRequest> req = iq_sender_->SendIq( | 122 scoped_ptr<IqRequest> req = iq_sender_->SendIq( |
| 124 buzz::STR_SET, kChromotingBotJid, stanza.Pass(), | 123 buzz::STR_SET, kChromotingBotJid, stanza.Pass(), |
| 125 IqSender::ReplyCallback()); | 124 IqSender::ReplyCallback()); |
| 126 // We ignore any response, so let the IqRequest be destroyed. | 125 // We ignore any response, so let the IqRequest be destroyed. |
| 127 return; | 126 return; |
| 128 } | 127 } |
| 129 | 128 |
| 130 } // namespace remoting | 129 } // namespace remoting |
| OLD | NEW |