| 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 | 14 |
| 14 namespace remoting { | 15 namespace remoting { |
| 15 namespace protocol { | 16 namespace protocol { |
| 16 | 17 |
| 17 // Delay after candidate creation before sending transport-info message to | 18 // Delay after candidate creation before sending transport-info message to |
| 18 // accumulate multiple candidates. This is an optimization to reduce number of | 19 // accumulate multiple candidates. This is an optimization to reduce number of |
| 19 // transport-info messages. | 20 // transport-info messages. |
| 20 const int kTransportInfoSendDelayMs = 20; | 21 const int kTransportInfoSendDelayMs = 20; |
| 21 | 22 |
| 22 // Name of the multiplexed channel. | 23 // Name of the multiplexed channel. |
| 23 static const char kMuxChannelName[] = "mux"; | 24 static const char kMuxChannelName[] = "mux"; |
| 24 | 25 |
| 25 IceTransport::IceTransport(cricket::PortAllocator* port_allocator, | 26 IceTransport::IceTransport(scoped_refptr<TransportContext> transport_context) |
| 26 const NetworkSettings& network_settings, | 27 : transport_context_(transport_context), weak_factory_(this) { |
| 27 TransportRole role) | 28 transport_context->Prepare(); |
| 28 : port_allocator_(port_allocator), | 29 } |
| 29 network_settings_(network_settings), | |
| 30 role_(role), | |
| 31 weak_factory_(this) {} | |
| 32 | 30 |
| 33 IceTransport::~IceTransport() { | 31 IceTransport::~IceTransport() { |
| 34 channel_multiplexer_.reset(); | 32 channel_multiplexer_.reset(); |
| 35 DCHECK(channels_.empty()); | 33 DCHECK(channels_.empty()); |
| 36 } | 34 } |
| 37 | 35 |
| 38 base::Closure IceTransport::GetCanStartClosure() { | |
| 39 return base::Bind(&IceTransport::OnCanStart, | |
| 40 weak_factory_.GetWeakPtr()); | |
| 41 } | |
| 42 | |
| 43 void IceTransport::Start(Transport::EventHandler* event_handler, | 36 void IceTransport::Start(Transport::EventHandler* event_handler, |
| 44 Authenticator* authenticator) { | 37 Authenticator* authenticator) { |
| 45 DCHECK(event_handler); | 38 DCHECK(event_handler); |
| 46 DCHECK(!event_handler_); | 39 DCHECK(!event_handler_); |
| 47 | 40 |
| 48 event_handler_ = event_handler; | 41 event_handler_ = event_handler; |
| 49 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | 42 pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); |
| 50 secure_channel_factory_.reset(new SecureChannelFactory( | 43 secure_channel_factory_.reset(new SecureChannelFactory( |
| 51 pseudotcp_channel_factory_.get(), authenticator)); | 44 pseudotcp_channel_factory_.get(), authenticator)); |
| 52 } | 45 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 81 } |
| 89 | 82 |
| 90 StreamChannelFactory* IceTransport::GetMultiplexedChannelFactory() { | 83 StreamChannelFactory* IceTransport::GetMultiplexedChannelFactory() { |
| 91 if (!channel_multiplexer_.get()) { | 84 if (!channel_multiplexer_.get()) { |
| 92 channel_multiplexer_.reset( | 85 channel_multiplexer_.reset( |
| 93 new ChannelMultiplexer(GetStreamChannelFactory(), kMuxChannelName)); | 86 new ChannelMultiplexer(GetStreamChannelFactory(), kMuxChannelName)); |
| 94 } | 87 } |
| 95 return channel_multiplexer_.get(); | 88 return channel_multiplexer_.get(); |
| 96 } | 89 } |
| 97 | 90 |
| 98 void IceTransport::OnCanStart() { | |
| 99 DCHECK(!can_start_); | |
| 100 | |
| 101 can_start_ = true; | |
| 102 for (ChannelsMap::iterator it = channels_.begin(); it != channels_.end(); | |
| 103 ++it) { | |
| 104 it->second->OnCanStart(); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void IceTransport::CreateChannel(const std::string& name, | 91 void IceTransport::CreateChannel(const std::string& name, |
| 109 const ChannelCreatedCallback& callback) { | 92 const ChannelCreatedCallback& callback) { |
| 110 DCHECK(!channels_[name]); | 93 DCHECK(!channels_[name]); |
| 111 | 94 |
| 112 scoped_ptr<IceTransportChannel> channel( | 95 scoped_ptr<IceTransportChannel> channel( |
| 113 new IceTransportChannel(port_allocator_, network_settings_, role_)); | 96 new IceTransportChannel(transport_context_)); |
| 114 if (can_start_) | |
| 115 channel->OnCanStart(); | |
| 116 channel->Connect(name, this, callback); | 97 channel->Connect(name, this, callback); |
| 117 AddPendingRemoteTransportInfo(channel.get()); | 98 AddPendingRemoteTransportInfo(channel.get()); |
| 118 channels_[name] = channel.release(); | 99 channels_[name] = channel.release(); |
| 119 } | 100 } |
| 120 | 101 |
| 121 void IceTransport::CancelChannelCreation(const std::string& name) { | 102 void IceTransport::CancelChannelCreation(const std::string& name) { |
| 122 ChannelsMap::iterator it = channels_.find(name); | 103 ChannelsMap::iterator it = channels_.find(name); |
| 123 if (it != channels_.end()) { | 104 if (it != channels_.end()) { |
| 124 DCHECK(!it->second->is_connected()); | 105 DCHECK(!it->second->is_connected()); |
| 125 delete it->second; | 106 delete it->second; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 179 } |
| 199 } | 180 } |
| 200 | 181 |
| 201 void IceTransport::SendTransportInfo() { | 182 void IceTransport::SendTransportInfo() { |
| 202 DCHECK(pending_transport_info_message_); | 183 DCHECK(pending_transport_info_message_); |
| 203 event_handler_->OnOutgoingTransportInfo( | 184 event_handler_->OnOutgoingTransportInfo( |
| 204 pending_transport_info_message_->ToXml()); | 185 pending_transport_info_message_->ToXml()); |
| 205 pending_transport_info_message_.reset(); | 186 pending_transport_info_message_.reset(); |
| 206 } | 187 } |
| 207 | 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 } |
| 198 |
| 208 } // namespace protocol | 199 } // namespace protocol |
| 209 } // namespace remoting | 200 } // namespace remoting |
| OLD | NEW |