Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/libjingle_transport_factory.h" | 5 #include "remoting/protocol/libjingle_transport_factory.h" |
| 6 | 6 |
| 7 #include "base/message_loop_proxy.h" | |
| 7 #include "jingle/glue/channel_socket_adapter.h" | 8 #include "jingle/glue/channel_socket_adapter.h" |
| 8 #include "jingle/glue/pseudotcp_adapter.h" | 9 #include "jingle/glue/pseudotcp_adapter.h" |
| 9 #include "jingle/glue/utils.h" | 10 #include "jingle/glue/utils.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "remoting/protocol/channel_authenticator.h" | 12 #include "remoting/protocol/channel_authenticator.h" |
| 12 #include "remoting/protocol/transport_config.h" | 13 #include "remoting/protocol/transport_config.h" |
| 13 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | 14 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" |
| 14 #include "third_party/libjingle/source/talk/base/network.h" | 15 #include "third_party/libjingle/source/talk/base/network.h" |
| 15 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" | 16 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" |
| 16 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h" | 17 #include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 std::string name_; | 71 std::string name_; |
| 71 TransportConfig config_; | 72 TransportConfig config_; |
| 72 EventHandler* event_handler_; | 73 EventHandler* event_handler_; |
| 73 StreamTransport::ConnectedCallback callback_; | 74 StreamTransport::ConnectedCallback callback_; |
| 74 scoped_ptr<ChannelAuthenticator> authenticator_; | 75 scoped_ptr<ChannelAuthenticator> authenticator_; |
| 75 | 76 |
| 76 scoped_ptr<cricket::PortAllocator> port_allocator_; | 77 scoped_ptr<cricket::PortAllocator> port_allocator_; |
| 77 cricket::HttpPortAllocator* http_port_allocator_; | 78 cricket::HttpPortAllocator* http_port_allocator_; |
| 78 scoped_ptr<cricket::P2PTransportChannel> channel_; | 79 scoped_ptr<cricket::P2PTransportChannel> channel_; |
| 79 | 80 |
| 81 jingle_glue::TransportChannelSocketAdapter* channel_adapter_; | |
|
Wez
2012/02/23 19:33:42
Is this needed?
Sergey Ulanov
2012/02/23 22:10:06
No. Removed.
| |
| 82 | |
| 80 // We own |socket_| until it is connected. | 83 // We own |socket_| until it is connected. |
| 81 scoped_ptr<jingle_glue::PseudoTcpAdapter> socket_; | 84 scoped_ptr<jingle_glue::PseudoTcpAdapter> socket_; |
| 82 | 85 |
| 83 DISALLOW_COPY_AND_ASSIGN(LibjingleStreamTransport); | 86 DISALLOW_COPY_AND_ASSIGN(LibjingleStreamTransport); |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 LibjingleStreamTransport::LibjingleStreamTransport( | 89 LibjingleStreamTransport::LibjingleStreamTransport( |
| 87 talk_base::NetworkManager* network_manager, | 90 talk_base::NetworkManager* network_manager, |
| 88 talk_base::PacketSocketFactory* socket_factory) | 91 talk_base::PacketSocketFactory* socket_factory) |
| 89 : network_manager_(network_manager), | 92 : network_manager_(network_manager), |
| 90 socket_factory_(socket_factory), | 93 socket_factory_(socket_factory), |
| 91 event_handler_(NULL), | 94 event_handler_(NULL), |
| 92 http_port_allocator_(NULL) { | 95 http_port_allocator_(NULL) { |
| 93 } | 96 } |
| 94 | 97 |
| 95 LibjingleStreamTransport::~LibjingleStreamTransport() { | 98 LibjingleStreamTransport::~LibjingleStreamTransport() { |
| 96 DCHECK(event_handler_); | 99 DCHECK(event_handler_); |
| 97 event_handler_->OnTransportDeleted(this); | 100 event_handler_->OnTransportDeleted(this); |
| 98 // Channel should be already destroyed if we were connected. | 101 // Channel should be already destroyed if we were connected. |
| 99 DCHECK(!is_connected() || socket_.get() == NULL); | 102 DCHECK(!is_connected() || socket_.get() == NULL); |
| 103 | |
| 104 if (channel_.get()) { | |
| 105 base::MessageLoopProxy::current()->DeleteSoon( | |
| 106 FROM_HERE, channel_.release()); | |
| 107 } | |
| 108 if (port_allocator_.get()) { | |
| 109 base::MessageLoopProxy::current()->DeleteSoon( | |
| 110 FROM_HERE, port_allocator_.release()); | |
| 111 } | |
| 100 } | 112 } |
| 101 | 113 |
| 102 void LibjingleStreamTransport::Initialize( | 114 void LibjingleStreamTransport::Initialize( |
| 103 const std::string& name, | 115 const std::string& name, |
| 104 const TransportConfig& config, | 116 const TransportConfig& config, |
| 105 Transport::EventHandler* event_handler, | 117 Transport::EventHandler* event_handler, |
| 106 scoped_ptr<ChannelAuthenticator> authenticator) { | 118 scoped_ptr<ChannelAuthenticator> authenticator) { |
| 107 DCHECK(CalledOnValidThread()); | 119 DCHECK(CalledOnValidThread()); |
| 108 | 120 |
| 109 DCHECK(!name.empty()); | 121 DCHECK(!name.empty()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 channel_->SignalCandidateReady.connect( | 165 channel_->SignalCandidateReady.connect( |
| 154 this, &LibjingleStreamTransport::OnCandidateReady); | 166 this, &LibjingleStreamTransport::OnCandidateReady); |
| 155 channel_->SignalRouteChange.connect( | 167 channel_->SignalRouteChange.connect( |
| 156 this, &LibjingleStreamTransport::OnRouteChange); | 168 this, &LibjingleStreamTransport::OnRouteChange); |
| 157 | 169 |
| 158 channel_->Connect(); | 170 channel_->Connect(); |
| 159 | 171 |
| 160 // Create net::Socket adapter for the P2PTransportChannel. | 172 // Create net::Socket adapter for the P2PTransportChannel. |
| 161 scoped_ptr<jingle_glue::TransportChannelSocketAdapter> channel_adapter( | 173 scoped_ptr<jingle_glue::TransportChannelSocketAdapter> channel_adapter( |
| 162 new jingle_glue::TransportChannelSocketAdapter(channel_.get())); | 174 new jingle_glue::TransportChannelSocketAdapter(channel_.get())); |
| 163 channel_adapter->SetOnDestroyedCallback(base::Bind( | |
| 164 &LibjingleStreamTransport::OnChannelDestroyed, base::Unretained(this))); | |
| 165 | 175 |
| 166 // Configure and connect PseudoTCP adapter. | 176 // Configure and connect PseudoTCP adapter. |
| 167 socket_.reset( | 177 socket_.reset( |
| 168 new jingle_glue::PseudoTcpAdapter(channel_adapter.release())); | 178 new jingle_glue::PseudoTcpAdapter(channel_adapter.release())); |
| 169 socket_->SetSendBufferSize(kTcpSendBufferSize); | 179 socket_->SetSendBufferSize(kTcpSendBufferSize); |
| 170 socket_->SetReceiveBufferSize(kTcpReceiveBufferSize); | 180 socket_->SetReceiveBufferSize(kTcpReceiveBufferSize); |
| 171 socket_->SetNoDelay(true); | 181 socket_->SetNoDelay(true); |
| 172 socket_->SetAckDelay(kTcpAckDelayMilliseconds); | 182 socket_->SetAckDelay(kTcpAckDelayMilliseconds); |
| 173 | 183 |
| 184 socket_->SetOnDestroyedCallback(base::Bind( | |
| 185 &LibjingleStreamTransport::OnChannelDestroyed, base::Unretained(this))); | |
| 186 | |
| 174 int result = socket_->Connect( | 187 int result = socket_->Connect( |
| 175 base::Bind(&LibjingleStreamTransport::OnTcpConnected, | 188 base::Bind(&LibjingleStreamTransport::OnTcpConnected, |
| 176 base::Unretained(this))); | 189 base::Unretained(this))); |
| 177 if (result != net::ERR_IO_PENDING) | 190 if (result != net::ERR_IO_PENDING) |
| 178 OnTcpConnected(result); | 191 OnTcpConnected(result); |
| 179 } | 192 } |
| 180 | 193 |
| 181 void LibjingleStreamTransport::AddRemoteCandidate( | 194 void LibjingleStreamTransport::AddRemoteCandidate( |
| 182 const cricket::Candidate& candidate) { | 195 const cricket::Candidate& candidate) { |
| 183 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 void LibjingleStreamTransport::OnChannelDestroyed() { | 279 void LibjingleStreamTransport::OnChannelDestroyed() { |
| 267 if (is_connected()) { | 280 if (is_connected()) { |
| 268 // The connection socket is being deleted, so delete the transport too. | 281 // The connection socket is being deleted, so delete the transport too. |
| 269 delete this; | 282 delete this; |
| 270 } | 283 } |
| 271 } | 284 } |
| 272 | 285 |
| 273 void LibjingleStreamTransport::NotifyConnected( | 286 void LibjingleStreamTransport::NotifyConnected( |
| 274 scoped_ptr<net::StreamSocket> socket) { | 287 scoped_ptr<net::StreamSocket> socket) { |
| 275 DCHECK(!is_connected()); | 288 DCHECK(!is_connected()); |
| 276 callback_.Run(socket.Pass()); | 289 StreamTransport::ConnectedCallback callback = callback_; |
| 277 callback_.Reset(); | 290 callback_.Reset(); |
| 291 callback.Run(socket.Pass()); | |
| 278 } | 292 } |
| 279 | 293 |
| 280 void LibjingleStreamTransport::NotifyConnectFailed() { | 294 void LibjingleStreamTransport::NotifyConnectFailed() { |
| 295 DCHECK(!is_connected()); | |
| 296 | |
| 281 socket_.reset(); | 297 socket_.reset(); |
| 282 channel_.reset(); | 298 |
| 299 if (channel_.get()) { | |
|
Wez
2012/02/22 22:51:38
Comment to clarify that we can't delete |channel_|
Sergey Ulanov
2012/02/22 23:36:32
Done.
| |
| 300 base::MessageLoopProxy::current()->DeleteSoon( | |
| 301 FROM_HERE, channel_.release()); | |
|
Wez
2012/02/22 22:51:38
Isn't there a risk that we'll end up processing so
Sergey Ulanov
2012/02/22 23:36:32
sigslot::has_slots<> disconnects signals automatic
Wez
2012/02/23 19:33:42
Right, but it does that when it's deleted, i.e. wh
Sergey Ulanov
2012/02/23 22:10:06
LibjingleStreamTransport doesn't have any signal h
| |
| 302 } | |
| 303 if (port_allocator_.get()) { | |
|
Wez
2012/02/22 22:51:38
We might end up here due to a |channel_| signal tr
Sergey Ulanov
2012/02/22 23:36:32
Yes, or channel_ may try to access port_allocator_
| |
| 304 base::MessageLoopProxy::current()->DeleteSoon( | |
| 305 FROM_HERE, port_allocator_.release()); | |
| 306 } | |
| 307 | |
| 283 authenticator_.reset(); | 308 authenticator_.reset(); |
| 284 | 309 |
| 285 NotifyConnected(scoped_ptr<net::StreamSocket>(NULL)); | 310 NotifyConnected(scoped_ptr<net::StreamSocket>(NULL)); |
| 286 } | 311 } |
| 287 | 312 |
| 288 } // namespace | 313 } // namespace |
| 289 | 314 |
| 290 LibjingleTransportFactory::LibjingleTransportFactory() | 315 LibjingleTransportFactory::LibjingleTransportFactory() |
| 291 : network_manager_(new talk_base::BasicNetworkManager()), | 316 : network_manager_(new talk_base::BasicNetworkManager()), |
| 292 socket_factory_(new talk_base::BasicPacketSocketFactory( | 317 socket_factory_(new talk_base::BasicPacketSocketFactory( |
| 293 talk_base::Thread::Current())) { | 318 talk_base::Thread::Current())) { |
| 294 } | 319 } |
| 295 | 320 |
| 296 LibjingleTransportFactory::~LibjingleTransportFactory() { | 321 LibjingleTransportFactory::~LibjingleTransportFactory() { |
| 322 base::MessageLoopProxy::current()->DeleteSoon( | |
|
Wez
2012/02/22 22:51:38
Is the worry that LibjingleTransportFactory might
Sergey Ulanov
2012/02/22 23:36:32
Yes. Added comments
| |
| 323 FROM_HERE, socket_factory_.release()); | |
| 324 base::MessageLoopProxy::current()->DeleteSoon( | |
| 325 FROM_HERE, network_manager_.release()); | |
| 297 } | 326 } |
| 298 | 327 |
| 299 scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() { | 328 scoped_ptr<StreamTransport> LibjingleTransportFactory::CreateStreamTransport() { |
| 300 return scoped_ptr<StreamTransport>( | 329 return scoped_ptr<StreamTransport>( |
| 301 new LibjingleStreamTransport(network_manager_.get(), | 330 new LibjingleStreamTransport(network_manager_.get(), |
| 302 socket_factory_.get())); | 331 socket_factory_.get())); |
| 303 } | 332 } |
| 304 | 333 |
| 305 scoped_ptr<DatagramTransport> | 334 scoped_ptr<DatagramTransport> |
| 306 LibjingleTransportFactory::CreateDatagramTransport() { | 335 LibjingleTransportFactory::CreateDatagramTransport() { |
| 307 NOTIMPLEMENTED(); | 336 NOTIMPLEMENTED(); |
| 308 return scoped_ptr<DatagramTransport>(NULL); | 337 return scoped_ptr<DatagramTransport>(NULL); |
| 309 } | 338 } |
| 310 | 339 |
| 311 | 340 |
| 312 } // namespace protocol | 341 } // namespace protocol |
| 313 } // namespace remoting | 342 } // namespace remoting |
| OLD | NEW |