OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ice_transport.h" | 5 #include "remoting/protocol/ice_transport.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "remoting/protocol/channel_authenticator.h" | 8 #include "remoting/protocol/channel_authenticator.h" |
9 #include "remoting/protocol/channel_multiplexer.h" | 9 #include "remoting/protocol/channel_multiplexer.h" |
10 #include "remoting/protocol/pseudotcp_channel_factory.h" | 10 #include "remoting/protocol/pseudotcp_channel_factory.h" |
11 #include "remoting/protocol/secure_channel_factory.h" | 11 #include "remoting/protocol/secure_channel_factory.h" |
12 #include "remoting/protocol/stream_channel_factory.h" | 12 #include "remoting/protocol/stream_channel_factory.h" |
13 #include "remoting/protocol/transport_context.h" | 13 #include "remoting/protocol/transport_context.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 namespace protocol { | 16 namespace protocol { |
17 | 17 |
18 // Delay after candidate creation before sending transport-info message to | 18 // Delay after candidate creation before sending transport-info message to |
19 // accumulate multiple candidates. This is an optimization to reduce number of | 19 // accumulate multiple candidates. This is an optimization to reduce number of |
20 // transport-info messages. | 20 // transport-info messages. |
21 const int kTransportInfoSendDelayMs = 20; | 21 const int kTransportInfoSendDelayMs = 20; |
22 | 22 |
23 // Name of the multiplexed channel. | 23 // Name of the multiplexed channel. |
24 static const char kMuxChannelName[] = "mux"; | 24 static const char kMuxChannelName[] = "mux"; |
25 | 25 |
26 IceTransport::IceTransport(scoped_refptr<TransportContext> transport_context) | 26 IceTransport::IceTransport(scoped_refptr<TransportContext> transport_context, |
27 : transport_context_(transport_context), weak_factory_(this) { | 27 EventHandler* event_handler) |
| 28 : transport_context_(transport_context), |
| 29 event_handler_(event_handler), |
| 30 weak_factory_(this) { |
28 transport_context->Prepare(); | 31 transport_context->Prepare(); |
29 } | 32 } |
30 | 33 |
31 IceTransport::~IceTransport() { | 34 IceTransport::~IceTransport() { |
32 channel_multiplexer_.reset(); | 35 channel_multiplexer_.reset(); |
33 DCHECK(channels_.empty()); | 36 DCHECK(channels_.empty()); |
34 } | 37 } |
35 | 38 |
36 void IceTransport::Start(Transport::EventHandler* event_handler, | 39 void IceTransport::Start( |
37 Authenticator* authenticator) { | 40 Authenticator* authenticator, |
38 DCHECK(event_handler); | 41 SendTransportInfoCallback send_transport_info_callback) { |
39 DCHECK(!event_handler_); | 42 DCHECK(!pseudotcp_channel_factory_); |
40 | 43 |
41 event_handler_ = event_handler; | 44 send_transport_info_callback_ = std::move(send_transport_info_callback); |
42 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | 45 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); |
43 secure_channel_factory_.reset(new SecureChannelFactory( | 46 secure_channel_factory_.reset(new SecureChannelFactory( |
44 pseudotcp_channel_factory_.get(), authenticator)); | 47 pseudotcp_channel_factory_.get(), authenticator)); |
45 } | 48 } |
46 | 49 |
47 bool IceTransport::ProcessTransportInfo(buzz::XmlElement* transport_info_xml) { | 50 bool IceTransport::ProcessTransportInfo(buzz::XmlElement* transport_info_xml) { |
48 IceTransportInfo transport_info; | 51 IceTransportInfo transport_info; |
49 if (!transport_info.ParseXml(transport_info_xml)) | 52 if (!transport_info.ParseXml(transport_info_xml)) |
50 return false; | 53 return false; |
51 | 54 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 while (candidate != pending_remote_candidates_.end()) { | 128 while (candidate != pending_remote_candidates_.end()) { |
126 if (candidate->name == channel->name()) { | 129 if (candidate->name == channel->name()) { |
127 channel->AddRemoteCandidate(candidate->candidate); | 130 channel->AddRemoteCandidate(candidate->candidate); |
128 candidate = pending_remote_candidates_.erase(candidate); | 131 candidate = pending_remote_candidates_.erase(candidate); |
129 } else { | 132 } else { |
130 ++candidate; | 133 ++candidate; |
131 } | 134 } |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 void IceTransport::OnTransportIceCredentials(IceTransportChannel* channel, | 138 void IceTransport::OnChannelIceCredentials(IceTransportChannel* channel, |
136 const std::string& ufrag, | 139 const std::string& ufrag, |
137 const std::string& password) { | 140 const std::string& password) { |
138 EnsurePendingTransportInfoMessage(); | 141 EnsurePendingTransportInfoMessage(); |
139 pending_transport_info_message_->ice_credentials.push_back( | 142 pending_transport_info_message_->ice_credentials.push_back( |
140 IceTransportInfo::IceCredentials(channel->name(), ufrag, password)); | 143 IceTransportInfo::IceCredentials(channel->name(), ufrag, password)); |
141 } | 144 } |
142 | 145 |
143 void IceTransport::OnTransportCandidate(IceTransportChannel* channel, | 146 void IceTransport::OnChannelCandidate(IceTransportChannel* channel, |
144 const cricket::Candidate& candidate) { | 147 const cricket::Candidate& candidate) { |
145 EnsurePendingTransportInfoMessage(); | 148 EnsurePendingTransportInfoMessage(); |
146 pending_transport_info_message_->candidates.push_back( | 149 pending_transport_info_message_->candidates.push_back( |
147 IceTransportInfo::NamedCandidate(channel->name(), candidate)); | 150 IceTransportInfo::NamedCandidate(channel->name(), candidate)); |
148 } | 151 } |
149 | 152 |
150 void IceTransport::OnTransportRouteChange(IceTransportChannel* channel, | 153 void IceTransport::OnChannelRouteChange(IceTransportChannel* channel, |
151 const TransportRoute& route) { | 154 const TransportRoute& route) { |
152 if (event_handler_) | 155 if (event_handler_) |
153 event_handler_->OnTransportRouteChange(channel->name(), route); | 156 event_handler_->OnIceTransportRouteChange(channel->name(), route); |
154 } | 157 } |
155 | 158 |
156 void IceTransport::OnTransportFailed(IceTransportChannel* channel) { | 159 void IceTransport::OnChannelFailed(IceTransportChannel* channel) { |
157 event_handler_->OnTransportError(CHANNEL_CONNECTION_ERROR); | 160 event_handler_->OnIceTransportError(CHANNEL_CONNECTION_ERROR); |
158 } | 161 } |
159 | 162 |
160 void IceTransport::OnTransportDeleted(IceTransportChannel* channel) { | 163 void IceTransport::OnChannelDeleted(IceTransportChannel* channel) { |
161 ChannelsMap::iterator it = channels_.find(channel->name()); | 164 ChannelsMap::iterator it = channels_.find(channel->name()); |
162 DCHECK_EQ(it->second, channel); | 165 DCHECK_EQ(it->second, channel); |
163 channels_.erase(it); | 166 channels_.erase(it); |
164 } | 167 } |
165 | 168 |
166 void IceTransport::EnsurePendingTransportInfoMessage() { | 169 void IceTransport::EnsurePendingTransportInfoMessage() { |
167 // |transport_info_timer_| must be running iff | 170 // |transport_info_timer_| must be running iff |
168 // |pending_transport_info_message_| exists. | 171 // |pending_transport_info_message_| exists. |
169 DCHECK_EQ(pending_transport_info_message_ != nullptr, | 172 DCHECK_EQ(pending_transport_info_message_ != nullptr, |
170 transport_info_timer_.IsRunning()); | 173 transport_info_timer_.IsRunning()); |
171 | 174 |
172 if (!pending_transport_info_message_) { | 175 if (!pending_transport_info_message_) { |
173 pending_transport_info_message_.reset(new IceTransportInfo()); | 176 pending_transport_info_message_.reset(new IceTransportInfo()); |
174 // Delay sending the new candidates in case we get more candidates | 177 // Delay sending the new candidates in case we get more candidates |
175 // that we can send in one message. | 178 // that we can send in one message. |
176 transport_info_timer_.Start( | 179 transport_info_timer_.Start( |
177 FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs), | 180 FROM_HERE, base::TimeDelta::FromMilliseconds(kTransportInfoSendDelayMs), |
178 this, &IceTransport::SendTransportInfo); | 181 this, &IceTransport::SendTransportInfo); |
179 } | 182 } |
180 } | 183 } |
181 | 184 |
182 void IceTransport::SendTransportInfo() { | 185 void IceTransport::SendTransportInfo() { |
183 DCHECK(pending_transport_info_message_); | 186 DCHECK(pending_transport_info_message_); |
184 event_handler_->OnOutgoingTransportInfo( | 187 |
185 pending_transport_info_message_->ToXml()); | 188 scoped_ptr<buzz::XmlElement> transport_info_xml = |
| 189 pending_transport_info_message_->ToXml(); |
186 pending_transport_info_message_.reset(); | 190 pending_transport_info_message_.reset(); |
187 } | 191 send_transport_info_callback_.Run(std::move(transport_info_xml)); |
188 | |
189 IceTransportFactory::IceTransportFactory( | |
190 scoped_refptr<TransportContext> transport_context) | |
191 : transport_context_(transport_context) {} | |
192 | |
193 IceTransportFactory::~IceTransportFactory() {} | |
194 | |
195 scoped_ptr<Transport> IceTransportFactory::CreateTransport() { | |
196 return make_scoped_ptr(new IceTransport(transport_context_.get())); | |
197 } | 192 } |
198 | 193 |
199 } // namespace protocol | 194 } // namespace protocol |
200 } // namespace remoting | 195 } // namespace remoting |
OLD | NEW |