Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: remoting/protocol/pepper_session_manager.cc

Issue 9005034: Refactor SignalStrategy so that it can be reused for multiple connections. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/iq_sender.h"
9 #include "remoting/jingle_glue/jingle_info_request.h" 9 #include "remoting/jingle_glue/jingle_info_request.h"
10 #include "remoting/jingle_glue/signal_strategy.h" 10 #include "remoting/jingle_glue/signal_strategy.h"
11 #include "remoting/protocol/authenticator.h" 11 #include "remoting/protocol/authenticator.h"
12 #include "remoting/protocol/jingle_messages.h" 12 #include "remoting/protocol/jingle_messages.h"
13 #include "remoting/protocol/pepper_session.h" 13 #include "remoting/protocol/pepper_session.h"
14 #include "third_party/libjingle/source/talk/base/socketaddress.h" 14 #include "third_party/libjingle/source/talk/base/socketaddress.h"
15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
16 16
17 using buzz::QName; 17 using buzz::QName;
18 18
19 namespace remoting { 19 namespace remoting {
20 namespace protocol { 20 namespace protocol {
21 21
22 PepperSessionManager::PepperSessionManager(pp::Instance* pp_instance) 22 PepperSessionManager::PepperSessionManager(pp::Instance* pp_instance)
23 : pp_instance_(pp_instance), 23 : pp_instance_(pp_instance),
24 signal_strategy_(NULL), 24 signal_strategy_(NULL),
25 listener_(NULL), 25 listener_(NULL),
26 allow_nat_traversal_(false) { 26 allow_nat_traversal_(false),
27 ready_(false) {
27 } 28 }
28 29
29 PepperSessionManager::~PepperSessionManager() { 30 PepperSessionManager::~PepperSessionManager() {
30 Close(); 31 Close();
31 } 32 }
32 33
33 void PepperSessionManager::Init( 34 void PepperSessionManager::Init(
34 const std::string& local_jid,
35 SignalStrategy* signal_strategy, 35 SignalStrategy* signal_strategy,
36 SessionManager::Listener* listener, 36 SessionManager::Listener* listener,
37 bool allow_nat_traversal) { 37 bool allow_nat_traversal) {
38 listener_ = listener; 38 listener_ = listener;
39 local_jid_ = local_jid;
40 signal_strategy_ = signal_strategy; 39 signal_strategy_ = signal_strategy;
41 iq_sender_.reset(new IqSender(signal_strategy_)); 40 iq_sender_.reset(new IqSender(signal_strategy_));
42 allow_nat_traversal_ = allow_nat_traversal; 41 allow_nat_traversal_ = allow_nat_traversal;
43 42
44 signal_strategy_->AddListener(this); 43 signal_strategy_->AddListener(this);
45 44
46 // If NAT traversal is enabled then we need to request STUN/Relay info. 45 OnSignalStrategyStateChange(signal_strategy_->GetState());
47 if (allow_nat_traversal) {
48 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_));
49 jingle_info_request_->Send(base::Bind(&PepperSessionManager::OnJingleInfo,
50 base::Unretained(this)));
51 } else {
52 listener_->OnSessionManagerInitialized();
53 }
54 } 46 }
55 47
56 void PepperSessionManager::OnJingleInfo( 48 void PepperSessionManager::OnJingleInfo(
57 const std::string& relay_token, 49 const std::string& relay_token,
58 const std::vector<std::string>& relay_hosts, 50 const std::vector<std::string>& relay_hosts,
59 const std::vector<talk_base::SocketAddress>& stun_hosts) { 51 const std::vector<talk_base::SocketAddress>& stun_hosts) {
60 DCHECK(CalledOnValidThread()); 52 DCHECK(CalledOnValidThread());
61 53
62 // TODO(sergeyu): Add support for multiple STUN/relay servers when 54 // TODO(sergeyu): Add support for multiple STUN/relay servers when
63 // it's implemented in libjingle and P2P Transport API. 55 // it's implemented in libjingle and P2P Transport API.
64 transport_config_.stun_server = stun_hosts[0].ToString(); 56 transport_config_.stun_server = stun_hosts[0].ToString();
65 transport_config_.relay_server = relay_hosts[0]; 57 transport_config_.relay_server = relay_hosts[0];
66 transport_config_.relay_token = relay_token; 58 transport_config_.relay_token = relay_token;
67 VLOG(1) << "STUN server: " << transport_config_.stun_server 59 VLOG(1) << "STUN server: " << transport_config_.stun_server
68 << " Relay server: " << transport_config_.relay_server 60 << " Relay server: " << transport_config_.relay_server
69 << " Relay token: " << transport_config_.relay_token; 61 << " Relay token: " << transport_config_.relay_token;
70 62
71 listener_->OnSessionManagerInitialized(); 63 if (!ready_) {
64 ready_ = true;
Wez 2011/12/21 23:35:30 Could you base "ready" on whether we already had s
Sergey Ulanov 2011/12/22 21:45:10 I don't think it is possible. transport_config_ co
65 listener_->OnSessionManagerReady();
66 }
72 } 67 }
73 68
74 Session* PepperSessionManager::Connect( 69 Session* PepperSessionManager::Connect(
75 const std::string& host_jid, 70 const std::string& host_jid,
76 Authenticator* authenticator, 71 Authenticator* authenticator,
77 CandidateSessionConfig* config, 72 CandidateSessionConfig* config,
78 const Session::StateChangeCallback& state_change_callback) { 73 const Session::StateChangeCallback& state_change_callback) {
79 PepperSession* session = new PepperSession(this); 74 PepperSession* session = new PepperSession(this);
80 session->StartConnection(host_jid, authenticator, config, 75 session->StartConnection(host_jid, authenticator, config,
81 state_change_callback); 76 state_change_callback);
(...skipping 15 matching lines...) Expand all
97 signal_strategy_ = NULL; 92 signal_strategy_ = NULL;
98 } 93 }
99 } 94 }
100 95
101 void PepperSessionManager::set_authenticator_factory( 96 void PepperSessionManager::set_authenticator_factory(
102 AuthenticatorFactory* authenticator_factory) { 97 AuthenticatorFactory* authenticator_factory) {
103 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
104 authenticator_factory_.reset(authenticator_factory); 99 authenticator_factory_.reset(authenticator_factory);
105 } 100 }
106 101
107 bool PepperSessionManager::OnIncomingStanza(const buzz::XmlElement* stanza) { 102 void PepperSessionManager::OnSignalStrategyStateChange(
103 SignalStrategy::State state) {
104 // If NAT traversal is enabled then we need to request STUN/Relay info.
105 if (state == SignalStrategy::CONNECTED) {
106 if (allow_nat_traversal_) {
107 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_));
108 jingle_info_request_->Send(base::Bind(&PepperSessionManager::OnJingleInfo,
109 base::Unretained(this)));
110 } else if (!ready_) {
111 ready_ = true;
112 listener_->OnSessionManagerReady();
113 }
114 }
115 }
116
117 bool PepperSessionManager::OnSignalStrategyIncomingStanza(
118 const buzz::XmlElement* stanza) {
108 if (!JingleMessage::IsJingleMessage(stanza)) 119 if (!JingleMessage::IsJingleMessage(stanza))
109 return false; 120 return false;
110 121
111 JingleMessage message; 122 JingleMessage message;
112 std::string error; 123 std::string error;
113 if (!message.ParseXml(stanza, &error)) { 124 if (!message.ParseXml(stanza, &error)) {
114 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST)); 125 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST));
115 return true; 126 return true;
116 } 127 }
117 128
(...skipping 21 matching lines...) Expand all
139 buzz::XmlElement* stanza = reply.ToXml(original_stanza); 150 buzz::XmlElement* stanza = reply.ToXml(original_stanza);
140 signal_strategy_->SendStanza(stanza); 151 signal_strategy_->SendStanza(stanza);
141 } 152 }
142 153
143 void PepperSessionManager::SessionDestroyed(PepperSession* session) { 154 void PepperSessionManager::SessionDestroyed(PepperSession* session) {
144 sessions_.erase(session->session_id_); 155 sessions_.erase(session->session_id_);
145 } 156 }
146 157
147 } // namespace protocol 158 } // namespace protocol
148 } // namespace remoting 159 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698