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 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ | 5 #ifndef REMOTING_PROTOCOL_TRANSPORT_H_ |
6 #define REMOTING_PROTOCOL_TRANSPORT_H_ | 6 #define REMOTING_PROTOCOL_TRANSPORT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 static std::string GetTypeString(RouteType type); | 46 static std::string GetTypeString(RouteType type); |
47 | 47 |
48 TransportRoute(); | 48 TransportRoute(); |
49 ~TransportRoute(); | 49 ~TransportRoute(); |
50 | 50 |
51 RouteType type; | 51 RouteType type; |
52 net::IPEndPoint remote_address; | 52 net::IPEndPoint remote_address; |
53 net::IPEndPoint local_address; | 53 net::IPEndPoint local_address; |
54 }; | 54 }; |
55 | 55 |
56 // Transport objects are responsible for establishing P2P connections. | |
57 // | |
58 // TODO(sergeyu): Remove this interface and rename TransportSession interface to | |
59 // Transport. | |
60 class Transport : public base::NonThreadSafe { | |
61 public: | |
62 class EventHandler { | |
63 public: | |
64 EventHandler() {}; | |
65 virtual ~EventHandler() {}; | |
66 | |
67 // Called to pass ICE credentials to the session. Used only for STANDARD | |
68 // version of ICE, see SetIceVersion(). | |
69 virtual void OnTransportIceCredentials(Transport* transport, | |
70 const std::string& ufrag, | |
71 const std::string& password) = 0; | |
72 | |
73 // Called when the transport generates a new candidate that needs | |
74 // to be passed to the AddRemoteCandidate() method on the remote | |
75 // end of the connection. | |
76 virtual void OnTransportCandidate(Transport* transport, | |
77 const cricket::Candidate& candidate) = 0; | |
78 | |
79 // Called when transport route changes. Can be called even before | |
80 // the transport is connected. | |
81 virtual void OnTransportRouteChange(Transport* transport, | |
82 const TransportRoute& route) = 0; | |
83 | |
84 // Called when when the transport has failed to connect or reconnect. | |
85 virtual void OnTransportFailed(Transport* transport) = 0; | |
86 | |
87 // Called when the transport is about to be deleted. | |
88 virtual void OnTransportDeleted(Transport* transport) = 0; | |
89 }; | |
90 | |
91 typedef base::Callback<void(scoped_ptr<P2PDatagramSocket>)> ConnectedCallback; | |
92 | |
93 Transport() {} | |
94 virtual ~Transport() {} | |
95 | |
96 // Connects the transport and calls the |callback| after that. | |
97 virtual void Connect(const std::string& name, | |
98 Transport::EventHandler* event_handler, | |
99 const ConnectedCallback& callback) = 0; | |
100 | |
101 // Sets remote ICE credentials. | |
102 virtual void SetRemoteCredentials(const std::string& ufrag, | |
103 const std::string& password) = 0; | |
104 | |
105 // Adds |candidate| received from the peer. | |
106 virtual void AddRemoteCandidate(const cricket::Candidate& candidate) = 0; | |
107 | |
108 // Name of the channel. It is used to identify the channel and | |
109 // disambiguate candidates it generates from candidates generated by | |
110 // parallel connections. | |
111 virtual const std::string& name() const = 0; | |
112 | |
113 // Returns true if the channel is already connected. | |
114 virtual bool is_connected() const = 0; | |
115 | |
116 private: | |
117 DISALLOW_COPY_AND_ASSIGN(Transport); | |
118 }; | |
119 | |
120 // TransportSession represents a P2P connection that consists of one or more | 56 // TransportSession represents a P2P connection that consists of one or more |
121 // channels. | 57 // channels. |
122 class TransportSession { | 58 class TransportSession { |
123 public: | 59 public: |
124 class EventHandler { | 60 class EventHandler { |
125 public: | 61 public: |
126 // Called to send a transport-info message. | 62 // Called to send a transport-info message. |
127 virtual void OnOutgoingTransportInfo( | 63 virtual void OnOutgoingTransportInfo( |
128 scoped_ptr<buzz::XmlElement> message) = 0; | 64 scoped_ptr<buzz::XmlElement> message) = 0; |
129 | 65 |
(...skipping 28 matching lines...) Expand all Loading... |
158 | 94 |
159 private: | 95 private: |
160 DISALLOW_COPY_AND_ASSIGN(TransportSession); | 96 DISALLOW_COPY_AND_ASSIGN(TransportSession); |
161 }; | 97 }; |
162 | 98 |
163 class TransportFactory { | 99 class TransportFactory { |
164 public: | 100 public: |
165 TransportFactory() { } | 101 TransportFactory() { } |
166 virtual ~TransportFactory() { } | 102 virtual ~TransportFactory() { } |
167 | 103 |
168 // Called to notify transport factory that a new transport might be created | |
169 // soon, e.g. when a new session is being created. Implementation may use it | |
170 // to start asynchronous preparation, e.g. fetch a new relay token if | |
171 // necessary while the session is being authenticated. | |
172 virtual void PrepareTokens() = 0; | |
173 | |
174 // Creates a new TransportSession. The factory must outlive the session. | 104 // Creates a new TransportSession. The factory must outlive the session. |
175 virtual scoped_ptr<TransportSession> CreateTransportSession() = 0; | 105 virtual scoped_ptr<TransportSession> CreateTransportSession() = 0; |
176 | 106 |
177 private: | 107 private: |
178 DISALLOW_COPY_AND_ASSIGN(TransportFactory); | 108 DISALLOW_COPY_AND_ASSIGN(TransportFactory); |
179 }; | 109 }; |
180 | 110 |
181 } // namespace protocol | 111 } // namespace protocol |
182 } // namespace remoting | 112 } // namespace remoting |
183 | 113 |
184 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ | 114 #endif // REMOTING_PROTOCOL_TRANSPORT_H_ |
OLD | NEW |