Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: webrtc/p2p/base/transportcontroller.h

Issue 2571683004: Fixing possible crash due to RefCountedChannel assignment operator. (Closed)
Patch Set: Use RefCountedObject instead of custom class. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 11 #ifndef WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 12 #define WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/asyncinvoker.h" 19 #include "webrtc/base/asyncinvoker.h"
20 #include "webrtc/base/constructormagic.h"
21 #include "webrtc/base/refcountedobject.h"
20 #include "webrtc/base/sigslot.h" 22 #include "webrtc/base/sigslot.h"
21 #include "webrtc/base/sslstreamadapter.h" 23 #include "webrtc/base/sslstreamadapter.h"
22 #include "webrtc/p2p/base/candidate.h" 24 #include "webrtc/p2p/base/candidate.h"
23 #include "webrtc/p2p/base/dtlstransportchannel.h" 25 #include "webrtc/p2p/base/dtlstransportchannel.h"
24 #include "webrtc/p2p/base/jseptransport.h" 26 #include "webrtc/p2p/base/jseptransport.h"
25 #include "webrtc/p2p/base/p2ptransportchannel.h" 27 #include "webrtc/p2p/base/p2ptransportchannel.h"
26 28
27 namespace rtc { 29 namespace rtc {
28 class Thread; 30 class Thread;
29 class PacketTransportInterface; 31 class PacketTransportInterface;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 const std::string& transport_name, 158 const std::string& transport_name,
157 int component); 159 int component);
158 virtual TransportChannelImpl* CreateDtlsTransportChannel_n( 160 virtual TransportChannelImpl* CreateDtlsTransportChannel_n(
159 const std::string& transport_name, 161 const std::string& transport_name,
160 int component, 162 int component,
161 TransportChannelImpl* ice); 163 TransportChannelImpl* ice);
162 164
163 private: 165 private:
164 void OnMessage(rtc::Message* pmsg) override; 166 void OnMessage(rtc::Message* pmsg) override;
165 167
166 // This structure groups the DTLS and ICE channels, and helps keep track of 168 class ChannelPair;
167 // how many external objects (BaseChannels) reference each channel. 169 typedef rtc::RefCountedObject<ChannelPair> RefCountedChannel;
168 struct RefCountedChannel {
169 RefCountedChannel() = default;
170 // TODO(deadbeef): Change the types of |dtls| and |ice| to
171 // DtlsTransportChannelWrapper and P2PTransportChannelWrapper,
172 // once TransportChannelImpl is removed.
173 explicit RefCountedChannel(TransportChannelImpl* dtls,
174 TransportChannelImpl* ice)
175 : ice_(ice), dtls_(dtls), ref_(0) {}
176
177 void AddRef() { ++ref_; }
178 void DecRef() {
179 ASSERT(ref_ > 0);
180 --ref_;
181 }
182 int ref() const { return ref_; }
183
184 // Currently, all ICE-related calls still go through this DTLS channel. But
185 // that will change once we get rid of TransportChannelImpl, and the DTLS
186 // channel interface no longer includes ICE-specific methods.
187 const TransportChannelImpl* dtls() const { return dtls_.get(); }
188 TransportChannelImpl* dtls() { return dtls_.get(); }
189 const TransportChannelImpl* ice() const { return ice_.get(); }
190 TransportChannelImpl* ice() { return ice_.get(); }
191
192 private:
193 std::unique_ptr<TransportChannelImpl> ice_;
194 std::unique_ptr<TransportChannelImpl> dtls_;
195 int ref_ = 0;
196 };
197 170
198 // Helper functions to get a channel or transport, or iterator to it (in case 171 // Helper functions to get a channel or transport, or iterator to it (in case
199 // it needs to be erased). 172 // it needs to be erased).
200 std::vector<RefCountedChannel>::iterator GetChannelIterator_n( 173 std::vector<RefCountedChannel*>::iterator GetChannelIterator_n(
201 const std::string& transport_name, 174 const std::string& transport_name,
202 int component); 175 int component);
203 std::vector<RefCountedChannel>::const_iterator GetChannelIterator_n( 176 std::vector<RefCountedChannel*>::const_iterator GetChannelIterator_n(
204 const std::string& transport_name, 177 const std::string& transport_name,
205 int component) const; 178 int component) const;
206 const JsepTransport* GetJsepTransport_n( 179 const JsepTransport* GetJsepTransport_n(
207 const std::string& transport_name) const; 180 const std::string& transport_name) const;
208 JsepTransport* GetJsepTransport_n(const std::string& transport_name); 181 JsepTransport* GetJsepTransport_n(const std::string& transport_name);
209 const RefCountedChannel* GetChannel_n(const std::string& transport_name, 182 const RefCountedChannel* GetChannel_n(const std::string& transport_name,
210 int component) const; 183 int component) const;
211 RefCountedChannel* GetChannel_n(const std::string& transport_name, 184 RefCountedChannel* GetChannel_n(const std::string& transport_name,
212 int component); 185 int component);
213 186
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 230
258 void UpdateAggregateStates_n(); 231 void UpdateAggregateStates_n();
259 232
260 void OnDtlsHandshakeError(rtc::SSLHandshakeError error); 233 void OnDtlsHandshakeError(rtc::SSLHandshakeError error);
261 234
262 rtc::Thread* const signaling_thread_ = nullptr; 235 rtc::Thread* const signaling_thread_ = nullptr;
263 rtc::Thread* const network_thread_ = nullptr; 236 rtc::Thread* const network_thread_ = nullptr;
264 PortAllocator* const port_allocator_ = nullptr; 237 PortAllocator* const port_allocator_ = nullptr;
265 238
266 std::map<std::string, std::unique_ptr<JsepTransport>> transports_; 239 std::map<std::string, std::unique_ptr<JsepTransport>> transports_;
267 std::vector<RefCountedChannel> channels_; 240 std::vector<RefCountedChannel*> channels_;
268 241
269 // Aggregate state for TransportChannelImpls. 242 // Aggregate state for TransportChannelImpls.
270 IceConnectionState connection_state_ = kIceConnectionConnecting; 243 IceConnectionState connection_state_ = kIceConnectionConnecting;
271 bool receiving_ = false; 244 bool receiving_ = false;
272 IceGatheringState gathering_state_ = kIceGatheringNew; 245 IceGatheringState gathering_state_ = kIceGatheringNew;
273 246
274 IceConfig ice_config_; 247 IceConfig ice_config_;
275 IceRole ice_role_ = ICEROLE_CONTROLLING; 248 IceRole ice_role_ = ICEROLE_CONTROLLING;
276 bool redetermine_role_on_ice_restart_; 249 bool redetermine_role_on_ice_restart_;
277 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64(); 250 uint64_t ice_tiebreaker_ = rtc::CreateRandomId64();
278 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 251 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
279 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 252 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
280 rtc::AsyncInvoker invoker_; 253 rtc::AsyncInvoker invoker_;
281 // True if QUIC is used instead of DTLS. 254 // True if QUIC is used instead of DTLS.
282 bool quic_ = false; 255 bool quic_ = false;
283 256
284 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; 257 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
258
259 RTC_DISALLOW_COPY_AND_ASSIGN(TransportController);
285 }; 260 };
286 261
287 } // namespace cricket 262 } // namespace cricket
288 263
289 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_ 264 #endif // WEBRTC_P2P_BASE_TRANSPORTCONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/transportcontroller.cc » ('j') | webrtc/p2p/base/transportcontroller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698