| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/protocol/pepper_session_manager.h" | 5 #include "remoting/protocol/pepper_session_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "remoting/jingle_glue/iq_sender.h" |
| 8 #include "remoting/jingle_glue/jingle_info_request.h" | 9 #include "remoting/jingle_glue/jingle_info_request.h" |
| 9 #include "remoting/jingle_glue/signal_strategy.h" | 10 #include "remoting/jingle_glue/signal_strategy.h" |
| 10 #include "remoting/protocol/jingle_messages.h" | 11 #include "remoting/protocol/jingle_messages.h" |
| 11 #include "remoting/protocol/pepper_session.h" | 12 #include "remoting/protocol/pepper_session.h" |
| 12 #include "third_party/libjingle/source/talk/base/socketaddress.h" | 13 #include "third_party/libjingle/source/talk/base/socketaddress.h" |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 14 | 15 |
| 15 using buzz::QName; | 16 using buzz::QName; |
| 16 | 17 |
| 17 namespace remoting { | 18 namespace remoting { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 31 void PepperSessionManager::Init( | 32 void PepperSessionManager::Init( |
| 32 const std::string& local_jid, | 33 const std::string& local_jid, |
| 33 SignalStrategy* signal_strategy, | 34 SignalStrategy* signal_strategy, |
| 34 SessionManager::Listener* listener, | 35 SessionManager::Listener* listener, |
| 35 crypto::RSAPrivateKey* private_key, | 36 crypto::RSAPrivateKey* private_key, |
| 36 const std::string& certificate, | 37 const std::string& certificate, |
| 37 bool allow_nat_traversal) { | 38 bool allow_nat_traversal) { |
| 38 listener_ = listener; | 39 listener_ = listener; |
| 39 local_jid_ = local_jid; | 40 local_jid_ = local_jid; |
| 40 signal_strategy_ = signal_strategy; | 41 signal_strategy_ = signal_strategy; |
| 42 iq_sender_.reset(new IqSender(signal_strategy_)); |
| 41 private_key_.reset(private_key); | 43 private_key_.reset(private_key); |
| 42 certificate_ = certificate; | 44 certificate_ = certificate; |
| 43 allow_nat_traversal_ = allow_nat_traversal; | 45 allow_nat_traversal_ = allow_nat_traversal; |
| 44 | 46 |
| 45 signal_strategy_->SetListener(this); | 47 signal_strategy_->AddListener(this); |
| 46 | 48 |
| 47 // If NAT traversal is enabled then we need to request STUN/Relay info. | 49 // If NAT traversal is enabled then we need to request STUN/Relay info. |
| 48 if (allow_nat_traversal) { | 50 if (allow_nat_traversal) { |
| 49 jingle_info_request_.reset( | 51 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_)); |
| 50 new JingleInfoRequest(signal_strategy_->CreateIqRequest())); | 52 jingle_info_request_->Send(base::Bind(&PepperSessionManager::OnJingleInfo, |
| 51 jingle_info_request_->Send(base::Bind( | 53 base::Unretained(this))); |
| 52 &PepperSessionManager::OnJingleInfo, base::Unretained(this))); | |
| 53 } else { | 54 } else { |
| 54 listener_->OnSessionManagerInitialized(); | 55 listener_->OnSessionManagerInitialized(); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 58 void PepperSessionManager::OnJingleInfo( | 59 void PepperSessionManager::OnJingleInfo( |
| 59 const std::string& relay_token, | 60 const std::string& relay_token, |
| 60 const std::vector<std::string>& relay_hosts, | 61 const std::vector<std::string>& relay_hosts, |
| 61 const std::vector<talk_base::SocketAddress>& stun_hosts) { | 62 const std::vector<talk_base::SocketAddress>& stun_hosts) { |
| 62 DCHECK(CalledOnValidThread()); | 63 DCHECK(CalledOnValidThread()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 | 89 |
| 89 void PepperSessionManager::Close() { | 90 void PepperSessionManager::Close() { |
| 90 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 91 | 92 |
| 92 // Close() can be called only after all sessions are destroyed. | 93 // Close() can be called only after all sessions are destroyed. |
| 93 DCHECK(sessions_.empty()); | 94 DCHECK(sessions_.empty()); |
| 94 | 95 |
| 95 listener_ = NULL; | 96 listener_ = NULL; |
| 96 jingle_info_request_.reset(); | 97 jingle_info_request_.reset(); |
| 97 | 98 |
| 98 signal_strategy_->SetListener(NULL); | 99 signal_strategy_->RemoveListener(this); |
| 99 } | 100 } |
| 100 | 101 |
| 101 bool PepperSessionManager::OnIncomingStanza(const buzz::XmlElement* stanza) { | 102 bool PepperSessionManager::OnIncomingStanza(const buzz::XmlElement* stanza) { |
| 102 if (!JingleMessage::IsJingleMessage(stanza)) | 103 if (!JingleMessage::IsJingleMessage(stanza)) |
| 103 return false; | 104 return false; |
| 104 | 105 |
| 105 JingleMessage message; | 106 JingleMessage message; |
| 106 std::string error; | 107 std::string error; |
| 107 if (!message.ParseXml(stanza, &error)) { | 108 if (!message.ParseXml(stanza, &error)) { |
| 108 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST)); | 109 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 121 SendReply(stanza, JingleMessageReply(JingleMessageReply::INVALID_SID)); | 122 SendReply(stanza, JingleMessageReply(JingleMessageReply::INVALID_SID)); |
| 122 return true; | 123 return true; |
| 123 } | 124 } |
| 124 | 125 |
| 125 JingleMessageReply reply; | 126 JingleMessageReply reply; |
| 126 it->second->OnIncomingMessage(message, &reply); | 127 it->second->OnIncomingMessage(message, &reply); |
| 127 SendReply(stanza, reply); | 128 SendReply(stanza, reply); |
| 128 return true; | 129 return true; |
| 129 } | 130 } |
| 130 | 131 |
| 131 IqRequest* PepperSessionManager::CreateIqRequest() { | |
| 132 return signal_strategy_->CreateIqRequest(); | |
| 133 } | |
| 134 | |
| 135 void PepperSessionManager::SendReply(const buzz::XmlElement* original_stanza, | 132 void PepperSessionManager::SendReply(const buzz::XmlElement* original_stanza, |
| 136 const JingleMessageReply& reply) { | 133 const JingleMessageReply& reply) { |
| 137 buzz::XmlElement* stanza = reply.ToXml(original_stanza); | 134 buzz::XmlElement* stanza = reply.ToXml(original_stanza); |
| 138 signal_strategy_->SendStanza(stanza); | 135 signal_strategy_->SendStanza(stanza); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void PepperSessionManager::SessionDestroyed(PepperSession* session) { | 138 void PepperSessionManager::SessionDestroyed(PepperSession* session) { |
| 142 sessions_.erase(session->session_id_); | 139 sessions_.erase(session->session_id_); |
| 143 } | 140 } |
| 144 | 141 |
| 145 } // namespace protocol | 142 } // namespace protocol |
| 146 } // namespace remoting | 143 } // namespace remoting |
| OLD | NEW |