| 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_CHANNEL_H_ | 5 #ifndef REMOTING_PROTOCOL_ICE_TRANSPORT_CHANNEL_H_ |
| 6 #define REMOTING_PROTOCOL_ICE_TRANSPORT_CHANNEL_H_ | 6 #define REMOTING_PROTOCOL_ICE_TRANSPORT_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "remoting/protocol/network_settings.h" | 14 #include "remoting/protocol/network_settings.h" |
| 15 #include "remoting/protocol/transport.h" | 15 #include "remoting/protocol/transport.h" |
| 16 #include "third_party/webrtc/base/sigslot.h" | 16 #include "third_party/webrtc/base/sigslot.h" |
| 17 | 17 |
| 18 namespace cricket { | 18 namespace cricket { |
| 19 class Candidate; | 19 class Candidate; |
| 20 class P2PTransportChannel; | 20 class P2PTransportChannel; |
| 21 class PortAllocator; | 21 class PortAllocator; |
| 22 class TransportChannel; | 22 class TransportChannel; |
| 23 class TransportChannelImpl; | 23 class TransportChannelImpl; |
| 24 } // namespace cricket | 24 } // namespace cricket |
| 25 | 25 |
| 26 namespace remoting { | 26 namespace remoting { |
| 27 namespace protocol { | 27 namespace protocol { |
| 28 | 28 |
| 29 class TransportContext; |
| 30 |
| 29 class IceTransportChannel : public sigslot::has_slots<> { | 31 class IceTransportChannel : public sigslot::has_slots<> { |
| 30 public: | 32 public: |
| 31 class Delegate { | 33 class Delegate { |
| 32 public: | 34 public: |
| 33 Delegate() {}; | 35 Delegate() {}; |
| 34 virtual ~Delegate() {}; | 36 virtual ~Delegate() {}; |
| 35 | 37 |
| 36 // Called to pass ICE credentials to the session. Used only for STANDARD | 38 // Called to pass ICE credentials to the session. Used only for STANDARD |
| 37 // version of ICE, see SetIceVersion(). | 39 // version of ICE, see SetIceVersion(). |
| 38 virtual void OnTransportIceCredentials(IceTransportChannel* transport, | 40 virtual void OnTransportIceCredentials(IceTransportChannel* transport, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 // Called when when the transport has failed to connect or reconnect. | 55 // Called when when the transport has failed to connect or reconnect. |
| 54 virtual void OnTransportFailed(IceTransportChannel* transport) = 0; | 56 virtual void OnTransportFailed(IceTransportChannel* transport) = 0; |
| 55 | 57 |
| 56 // Called when the transport is about to be deleted. | 58 // Called when the transport is about to be deleted. |
| 57 virtual void OnTransportDeleted(IceTransportChannel* transport) = 0; | 59 virtual void OnTransportDeleted(IceTransportChannel* transport) = 0; |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 typedef base::Callback<void(scoped_ptr<P2PDatagramSocket>)> ConnectedCallback; | 62 typedef base::Callback<void(scoped_ptr<P2PDatagramSocket>)> ConnectedCallback; |
| 61 | 63 |
| 62 IceTransportChannel(cricket::PortAllocator* port_allocator, | 64 explicit IceTransportChannel( |
| 63 const NetworkSettings& network_settings, | 65 scoped_refptr<TransportContext> transport_context); |
| 64 TransportRole role); | |
| 65 ~IceTransportChannel() override; | 66 ~IceTransportChannel() override; |
| 66 | 67 |
| 67 // Called by IceTransport when it has fresh Jingle info. | |
| 68 void OnCanStart(); | |
| 69 | |
| 70 // Connects the channel and calls the |callback| after that. | 68 // Connects the channel and calls the |callback| after that. |
| 71 void Connect(const std::string& name, | 69 void Connect(const std::string& name, |
| 72 Delegate* delegate, | 70 Delegate* delegate, |
| 73 const ConnectedCallback& callback); | 71 const ConnectedCallback& callback); |
| 74 | 72 |
| 75 // Sets remote ICE credentials. | 73 // Sets remote ICE credentials. |
| 76 void SetRemoteCredentials(const std::string& ufrag, | 74 void SetRemoteCredentials(const std::string& ufrag, |
| 77 const std::string& password); | 75 const std::string& password); |
| 78 | 76 |
| 79 // Adds |candidate| received from the peer. | 77 // Adds |candidate| received from the peer. |
| 80 void AddRemoteCandidate(const cricket::Candidate& candidate); | 78 void AddRemoteCandidate(const cricket::Candidate& candidate); |
| 81 | 79 |
| 82 // Name of the channel. Used to identify the channel and disambiguate | 80 // Name of the channel. Used to identify the channel and disambiguate |
| 83 // candidates it generates from candidates generated by parallel connections. | 81 // candidates it generates from candidates generated by parallel connections. |
| 84 const std::string& name() const; | 82 const std::string& name() const; |
| 85 | 83 |
| 86 // Returns true if the channel is already connected. | 84 // Returns true if the channel is already connected. |
| 87 bool is_connected() const; | 85 bool is_connected() const; |
| 88 | 86 |
| 89 private: | 87 private: |
| 90 void DoStart(); | 88 void OnPortAllocatorCreated( |
| 89 scoped_ptr<cricket::PortAllocator> port_allocator); |
| 90 |
| 91 void NotifyConnected(); | 91 void NotifyConnected(); |
| 92 | 92 |
| 93 // Signal handlers for cricket::TransportChannel. | 93 // Signal handlers for cricket::TransportChannel. |
| 94 void OnCandidateGathered(cricket::TransportChannelImpl* channel, | 94 void OnCandidateGathered(cricket::TransportChannelImpl* channel, |
| 95 const cricket::Candidate& candidate); | 95 const cricket::Candidate& candidate); |
| 96 void OnRouteChange(cricket::TransportChannel* channel, | 96 void OnRouteChange(cricket::TransportChannel* channel, |
| 97 const cricket::Candidate& candidate); | 97 const cricket::Candidate& candidate); |
| 98 void OnReceivingState(cricket::TransportChannel* channel); | 98 void OnReceivingState(cricket::TransportChannel* channel); |
| 99 void OnWritableState(cricket::TransportChannel* channel); | 99 void OnWritableState(cricket::TransportChannel* channel); |
| 100 | 100 |
| 101 // Callback for TransportChannelSocketAdapter to notify when the socket is | 101 // Callback for TransportChannelSocketAdapter to notify when the socket is |
| 102 // destroyed. | 102 // destroyed. |
| 103 void OnChannelDestroyed(); | 103 void OnChannelDestroyed(); |
| 104 | 104 |
| 105 void NotifyRouteChanged(); | 105 void NotifyRouteChanged(); |
| 106 | 106 |
| 107 // Tries to connect by restarting ICE. Called by |reconnect_timer_|. | 107 // Tries to connect by restarting ICE. Called by |reconnect_timer_|. |
| 108 void TryReconnect(); | 108 void TryReconnect(); |
| 109 | 109 |
| 110 cricket::PortAllocator* port_allocator_; | 110 scoped_refptr<TransportContext> transport_context_; |
| 111 NetworkSettings network_settings_; | |
| 112 TransportRole role_; | |
| 113 | 111 |
| 114 std::string name_; | 112 std::string name_; |
| 115 Delegate* delegate_; | 113 Delegate* delegate_ = nullptr; |
| 116 ConnectedCallback callback_; | 114 ConnectedCallback callback_; |
| 117 std::string ice_username_fragment_; | 115 std::string ice_username_fragment_; |
| 118 | 116 |
| 119 bool can_start_; | 117 scoped_ptr<cricket::PortAllocator> port_allocator_; |
| 120 | 118 |
| 121 std::string remote_ice_username_fragment_; | 119 std::string remote_ice_username_fragment_; |
| 122 std::string remote_ice_password_; | 120 std::string remote_ice_password_; |
| 123 std::list<cricket::Candidate> pending_candidates_; | 121 std::list<cricket::Candidate> pending_candidates_; |
| 124 scoped_ptr<cricket::P2PTransportChannel> channel_; | 122 scoped_ptr<cricket::P2PTransportChannel> channel_; |
| 125 int connect_attempts_left_; | 123 int connect_attempts_left_; |
| 126 base::RepeatingTimer reconnect_timer_; | 124 base::RepeatingTimer reconnect_timer_; |
| 127 | 125 |
| 128 base::ThreadChecker thread_checker_; | 126 base::ThreadChecker thread_checker_; |
| 129 | 127 |
| 130 base::WeakPtrFactory<IceTransportChannel> weak_factory_; | 128 base::WeakPtrFactory<IceTransportChannel> weak_factory_; |
| 131 | 129 |
| 132 DISALLOW_COPY_AND_ASSIGN(IceTransportChannel); | 130 DISALLOW_COPY_AND_ASSIGN(IceTransportChannel); |
| 133 }; | 131 }; |
| 134 | 132 |
| 135 } // namespace protocol | 133 } // namespace protocol |
| 136 } // namespace remoting | 134 } // namespace remoting |
| 137 | 135 |
| 138 #endif // REMOTING_PROTOCOL_ICE_TRANSPORT_CHANNEL_H_ | 136 #endif // REMOTING_PROTOCOL_ICE_TRANSPORT_CHANNEL_H_ |
| OLD | NEW |