| 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/stream_message_pipe_adapter.h" | 
| 13 #include "remoting/protocol/transport_context.h" | 14 #include "remoting/protocol/transport_context.h" | 
| 14 | 15 | 
| 15 namespace remoting { | 16 namespace remoting { | 
| 16 namespace protocol { | 17 namespace protocol { | 
| 17 | 18 | 
| 18 // Delay after candidate creation before sending transport-info message to | 19 // Delay after candidate creation before sending transport-info message to | 
| 19 // accumulate multiple candidates. This is an optimization to reduce number of | 20 // accumulate multiple candidates. This is an optimization to reduce number of | 
| 20 // transport-info messages. | 21 // transport-info messages. | 
| 21 const int kTransportInfoSendDelayMs = 20; | 22 const int kTransportInfoSendDelayMs = 20; | 
| 22 | 23 | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 38 | 39 | 
| 39 void IceTransport::Start( | 40 void IceTransport::Start( | 
| 40     Authenticator* authenticator, | 41     Authenticator* authenticator, | 
| 41     SendTransportInfoCallback send_transport_info_callback) { | 42     SendTransportInfoCallback send_transport_info_callback) { | 
| 42   DCHECK(!pseudotcp_channel_factory_); | 43   DCHECK(!pseudotcp_channel_factory_); | 
| 43 | 44 | 
| 44   send_transport_info_callback_ = std::move(send_transport_info_callback); | 45   send_transport_info_callback_ = std::move(send_transport_info_callback); | 
| 45   pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | 46   pseudotcp_channel_factory_.reset(new PseudoTcpChannelFactory(this)); | 
| 46   secure_channel_factory_.reset(new SecureChannelFactory( | 47   secure_channel_factory_.reset(new SecureChannelFactory( | 
| 47       pseudotcp_channel_factory_.get(), authenticator)); | 48       pseudotcp_channel_factory_.get(), authenticator)); | 
|  | 49   message_channel_factory_.reset(new StreamMessageChannelFactoryAdapter( | 
|  | 50       secure_channel_factory_.get(), | 
|  | 51       base::Bind(&IceTransport::OnChannelError, weak_factory_.GetWeakPtr()))); | 
| 48 } | 52 } | 
| 49 | 53 | 
| 50 bool IceTransport::ProcessTransportInfo(buzz::XmlElement* transport_info_xml) { | 54 bool IceTransport::ProcessTransportInfo(buzz::XmlElement* transport_info_xml) { | 
| 51   IceTransportInfo transport_info; | 55   IceTransportInfo transport_info; | 
| 52   if (!transport_info.ParseXml(transport_info_xml)) | 56   if (!transport_info.ParseXml(transport_info_xml)) | 
| 53     return false; | 57     return false; | 
| 54 | 58 | 
| 55   for (auto it = transport_info.ice_credentials.begin(); | 59   for (auto it = transport_info.ice_credentials.begin(); | 
| 56        it != transport_info.ice_credentials.end(); ++it) { | 60        it != transport_info.ice_credentials.end(); ++it) { | 
| 57     ChannelsMap::iterator channel = channels_.find(it->channel); | 61     ChannelsMap::iterator channel = channels_.find(it->channel); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 72     } else { | 76     } else { | 
| 73       // Transport info was received before the channel was created. | 77       // Transport info was received before the channel was created. | 
| 74       // This could happen due to messages being reordered on the wire. | 78       // This could happen due to messages being reordered on the wire. | 
| 75       pending_remote_candidates_.push_back(*it); | 79       pending_remote_candidates_.push_back(*it); | 
| 76     } | 80     } | 
| 77   } | 81   } | 
| 78 | 82 | 
| 79   return true; | 83   return true; | 
| 80 } | 84 } | 
| 81 | 85 | 
| 82 StreamChannelFactory* IceTransport::GetStreamChannelFactory() { | 86 MessageChannelFactory* IceTransport::GetChannelFactory() { | 
| 83   return secure_channel_factory_.get(); | 87   return message_channel_factory_.get(); | 
| 84 } | 88 } | 
| 85 | 89 | 
| 86 StreamChannelFactory* IceTransport::GetMultiplexedChannelFactory() { | 90 MessageChannelFactory* IceTransport::GetMultiplexedChannelFactory() { | 
| 87   if (!channel_multiplexer_.get()) { | 91   if (!channel_multiplexer_) { | 
| 88     channel_multiplexer_.reset( | 92     channel_multiplexer_.reset( | 
| 89         new ChannelMultiplexer(GetStreamChannelFactory(), kMuxChannelName)); | 93         new ChannelMultiplexer(secure_channel_factory_.get(), kMuxChannelName)); | 
|  | 94     mux_channel_factory_.reset(new StreamMessageChannelFactoryAdapter( | 
|  | 95         channel_multiplexer_.get(), | 
|  | 96         base::Bind(&IceTransport::OnChannelError, weak_factory_.GetWeakPtr()))); | 
| 90   } | 97   } | 
| 91   return channel_multiplexer_.get(); | 98   return mux_channel_factory_.get(); | 
| 92 } | 99 } | 
| 93 | 100 | 
| 94 void IceTransport::CreateChannel(const std::string& name, | 101 void IceTransport::CreateChannel(const std::string& name, | 
| 95                                  const ChannelCreatedCallback& callback) { | 102                                  const ChannelCreatedCallback& callback) { | 
| 96   DCHECK(!channels_[name]); | 103   DCHECK(!channels_[name]); | 
| 97 | 104 | 
| 98   scoped_ptr<IceTransportChannel> channel( | 105   scoped_ptr<IceTransportChannel> channel( | 
| 99       new IceTransportChannel(transport_context_)); | 106       new IceTransportChannel(transport_context_)); | 
| 100   channel->Connect(name, this, callback); | 107   channel->Connect(name, this, callback); | 
| 101   AddPendingRemoteTransportInfo(channel.get()); | 108   AddPendingRemoteTransportInfo(channel.get()); | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 184 | 191 | 
| 185 void IceTransport::SendTransportInfo() { | 192 void IceTransport::SendTransportInfo() { | 
| 186   DCHECK(pending_transport_info_message_); | 193   DCHECK(pending_transport_info_message_); | 
| 187 | 194 | 
| 188   scoped_ptr<buzz::XmlElement> transport_info_xml = | 195   scoped_ptr<buzz::XmlElement> transport_info_xml = | 
| 189       pending_transport_info_message_->ToXml(); | 196       pending_transport_info_message_->ToXml(); | 
| 190   pending_transport_info_message_.reset(); | 197   pending_transport_info_message_.reset(); | 
| 191   send_transport_info_callback_.Run(std::move(transport_info_xml)); | 198   send_transport_info_callback_.Run(std::move(transport_info_xml)); | 
| 192 } | 199 } | 
| 193 | 200 | 
|  | 201 void IceTransport::OnChannelError(int error) { | 
|  | 202   LOG(ERROR) << "Data channel failed, error=" << error; | 
|  | 203   event_handler_->OnIceTransportError(CHANNEL_CONNECTION_ERROR); | 
|  | 204 } | 
|  | 205 | 
| 194 }  // namespace protocol | 206 }  // namespace protocol | 
| 195 }  // namespace remoting | 207 }  // namespace remoting | 
| OLD | NEW | 
|---|