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 #ifndef REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ |
6 #define REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ | 6 #define REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
13 #include "remoting/protocol/datagram_channel_factory.h" | 14 #include "remoting/protocol/datagram_channel_factory.h" |
| 15 #include "remoting/protocol/ice_transport_channel.h" |
14 #include "remoting/protocol/jingle_messages.h" | 16 #include "remoting/protocol/jingle_messages.h" |
15 #include "remoting/protocol/transport.h" | 17 #include "remoting/protocol/transport.h" |
16 | 18 |
17 namespace remoting { | 19 namespace remoting { |
18 namespace protocol { | 20 namespace protocol { |
19 | 21 |
20 class ChannelMultiplexer; | 22 class ChannelMultiplexer; |
21 class LibjingleTransportFactory; | |
22 class PseudoTcpChannelFactory; | 23 class PseudoTcpChannelFactory; |
23 class SecureChannelFactory; | 24 class SecureChannelFactory; |
24 | 25 |
25 class IceTransportSession : public TransportSession, | 26 class IceTransportSession : public TransportSession, |
26 public Transport::EventHandler, | 27 public IceTransportChannel::Delegate, |
27 public DatagramChannelFactory { | 28 public DatagramChannelFactory { |
28 public: | 29 public: |
29 // |transport_factory| must outlive the session. | 30 // |port_allocator| must outlive the session. |
30 IceTransportSession(LibjingleTransportFactory* libjingle_transport_factory); | 31 IceTransportSession(cricket::PortAllocator* port_allocator, |
| 32 const NetworkSettings& network_settings, |
| 33 TransportRole role); |
31 ~IceTransportSession() override; | 34 ~IceTransportSession() override; |
32 | 35 |
| 36 // Returns a closure that must be called before transport channels start |
| 37 // connecting . |
| 38 base::Closure GetCanStartClosure(); |
| 39 |
33 // TransportSession interface. | 40 // TransportSession interface. |
34 void Start(TransportSession::EventHandler* event_handler, | 41 void Start(TransportSession::EventHandler* event_handler, |
35 Authenticator* authenticator) override; | 42 Authenticator* authenticator) override; |
36 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; | 43 bool ProcessTransportInfo(buzz::XmlElement* transport_info) override; |
37 DatagramChannelFactory* GetDatagramChannelFactory() override; | 44 DatagramChannelFactory* GetDatagramChannelFactory() override; |
38 StreamChannelFactory* GetStreamChannelFactory() override; | 45 StreamChannelFactory* GetStreamChannelFactory() override; |
39 StreamChannelFactory* GetMultiplexedChannelFactory() override; | 46 StreamChannelFactory* GetMultiplexedChannelFactory() override; |
40 | 47 |
41 private: | 48 private: |
42 typedef std::map<std::string, Transport*> ChannelsMap; | 49 typedef std::map<std::string, IceTransportChannel*> ChannelsMap; |
| 50 |
| 51 void OnCanStart(); |
43 | 52 |
44 // DatagramChannelFactory interface. | 53 // DatagramChannelFactory interface. |
45 void CreateChannel(const std::string& name, | 54 void CreateChannel(const std::string& name, |
46 const ChannelCreatedCallback& callback) override; | 55 const ChannelCreatedCallback& callback) override; |
47 void CancelChannelCreation(const std::string& name) override; | 56 void CancelChannelCreation(const std::string& name) override; |
48 | 57 |
49 // Passes transport info to a new |channel| in case it was received before the | 58 // Passes transport info to a new |channel| in case it was received before the |
50 // channel was created. | 59 // channel was created. |
51 void AddPendingRemoteTransportInfo(Transport* channel); | 60 void AddPendingRemoteTransportInfo(IceTransportChannel* channel); |
52 | 61 |
53 // Transport::EventHandler interface. | 62 // IceTransportChannel::Delegate interface. |
54 void OnTransportIceCredentials(Transport* transport, | 63 void OnTransportIceCredentials(IceTransportChannel* transport, |
55 const std::string& ufrag, | 64 const std::string& ufrag, |
56 const std::string& password) override; | 65 const std::string& password) override; |
57 void OnTransportCandidate(Transport* transport, | 66 void OnTransportCandidate(IceTransportChannel* transport, |
58 const cricket::Candidate& candidate) override; | 67 const cricket::Candidate& candidate) override; |
59 void OnTransportRouteChange(Transport* transport, | 68 void OnTransportRouteChange(IceTransportChannel* transport, |
60 const TransportRoute& route) override; | 69 const TransportRoute& route) override; |
61 void OnTransportFailed(Transport* transport) override; | 70 void OnTransportFailed(IceTransportChannel* transport) override; |
62 void OnTransportDeleted(Transport* transport) override; | 71 void OnTransportDeleted(IceTransportChannel* transport) override; |
63 | 72 |
64 // Creates empty |pending_transport_info_message_| and schedules timer for | 73 // Creates empty |pending_transport_info_message_| and schedules timer for |
65 // SentTransportInfo() to sent the message later. | 74 // SentTransportInfo() to sent the message later. |
66 void EnsurePendingTransportInfoMessage(); | 75 void EnsurePendingTransportInfoMessage(); |
67 | 76 |
68 // Sends transport-info message with candidates from |pending_candidates_|. | 77 // Sends transport-info message with candidates from |pending_candidates_|. |
69 void SendTransportInfo(); | 78 void SendTransportInfo(); |
70 | 79 |
71 LibjingleTransportFactory* libjingle_transport_factory_; | 80 cricket::PortAllocator* port_allocator_; |
| 81 NetworkSettings network_settings_; |
| 82 TransportRole role_; |
| 83 |
| 84 bool can_start_ = false; |
72 | 85 |
73 TransportSession::EventHandler* event_handler_ = nullptr; | 86 TransportSession::EventHandler* event_handler_ = nullptr; |
74 | 87 |
75 ChannelsMap channels_; | 88 ChannelsMap channels_; |
76 scoped_ptr<PseudoTcpChannelFactory> pseudotcp_channel_factory_; | 89 scoped_ptr<PseudoTcpChannelFactory> pseudotcp_channel_factory_; |
77 scoped_ptr<SecureChannelFactory> secure_channel_factory_; | 90 scoped_ptr<SecureChannelFactory> secure_channel_factory_; |
78 scoped_ptr<ChannelMultiplexer> channel_multiplexer_; | 91 scoped_ptr<ChannelMultiplexer> channel_multiplexer_; |
79 | 92 |
80 // Pending remote transport info received before the local channels were | 93 // Pending remote transport info received before the local channels were |
81 // created. | 94 // created. |
82 std::list<IceTransportInfo::IceCredentials> pending_remote_ice_credentials_; | 95 std::list<IceTransportInfo::IceCredentials> pending_remote_ice_credentials_; |
83 std::list<IceTransportInfo::NamedCandidate> pending_remote_candidates_; | 96 std::list<IceTransportInfo::NamedCandidate> pending_remote_candidates_; |
84 | 97 |
85 scoped_ptr<IceTransportInfo> pending_transport_info_message_; | 98 scoped_ptr<IceTransportInfo> pending_transport_info_message_; |
86 base::OneShotTimer transport_info_timer_; | 99 base::OneShotTimer transport_info_timer_; |
87 | 100 |
| 101 base::WeakPtrFactory<IceTransportSession> weak_factory_; |
| 102 |
88 DISALLOW_COPY_AND_ASSIGN(IceTransportSession); | 103 DISALLOW_COPY_AND_ASSIGN(IceTransportSession); |
89 }; | 104 }; |
90 | 105 |
91 } // namespace protocol | 106 } // namespace protocol |
92 } // namespace remoting | 107 } // namespace remoting |
93 | 108 |
94 #endif // REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ | 109 #endif // REMOTING_PROTOCOL_ICE_TRANSPORT_SESSION_H_ |
95 | 110 |
OLD | NEW |