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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCDataChannel.mm

Issue 1957523006: Fixed a crash in Objective-C clients when data channel becomes closed. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 rtc::scoped_refptr<webrtc::DataChannelInterface> _nativeDataChannel; 88 rtc::scoped_refptr<webrtc::DataChannelInterface> _nativeDataChannel;
89 std::unique_ptr<webrtc::DataChannelDelegateAdapter> _observer; 89 std::unique_ptr<webrtc::DataChannelDelegateAdapter> _observer;
90 BOOL _isObserverRegistered; 90 BOOL _isObserverRegistered;
91 } 91 }
92 92
93 @synthesize delegate = _delegate; 93 @synthesize delegate = _delegate;
94 94
95 - (void)dealloc { 95 - (void)dealloc {
96 // Handles unregistering the observer properly. We need to do this because 96 // Handles unregistering the observer properly. We need to do this because
97 // there may still be other references to the underlying data channel. 97 // there may still be other references to the underlying data channel.
98 self.delegate = nil; 98 _nativeDataChannel->UnregisterObserver();
99 } 99 }
100 100
101 - (NSString *)label { 101 - (NSString *)label {
102 return [NSString stringForStdString:_nativeDataChannel->label()]; 102 return [NSString stringForStdString:_nativeDataChannel->label()];
103 } 103 }
104 104
105 - (BOOL)isReliable { 105 - (BOOL)isReliable {
106 return _nativeDataChannel->reliable(); 106 return _nativeDataChannel->reliable();
107 } 107 }
108 108
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 - (RTCDataChannelState)readyState { 141 - (RTCDataChannelState)readyState {
142 return [[self class] dataChannelStateForNativeState: 142 return [[self class] dataChannelStateForNativeState:
143 _nativeDataChannel->state()]; 143 _nativeDataChannel->state()];
144 } 144 }
145 145
146 - (uint64_t)bufferedAmount { 146 - (uint64_t)bufferedAmount {
147 return _nativeDataChannel->buffered_amount(); 147 return _nativeDataChannel->buffered_amount();
148 } 148 }
149 149
150 - (void)setDelegate:(id<RTCDataChannelDelegate>)delegate {
151 if (_delegate == delegate) {
152 return;
153 }
154 if (_isObserverRegistered) {
155 _nativeDataChannel->UnregisterObserver();
156 _isObserverRegistered = NO;
157 }
158 _delegate = delegate;
159 if (_delegate) {
160 _nativeDataChannel->RegisterObserver(_observer.get());
161 _isObserverRegistered = YES;
162 }
163 }
164
165 - (void)close { 150 - (void)close {
166 _nativeDataChannel->Close(); 151 _nativeDataChannel->Close();
167 } 152 }
168 153
169 - (BOOL)sendData:(RTCDataBuffer *)data { 154 - (BOOL)sendData:(RTCDataBuffer *)data {
170 return _nativeDataChannel->Send(*data.nativeDataBuffer); 155 return _nativeDataChannel->Send(*data.nativeDataBuffer);
171 } 156 }
172 157
173 - (NSString *)description { 158 - (NSString *)description {
174 return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@", 159 return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@",
175 (long)self.channelId, 160 (long)self.channelId,
176 self.label, 161 self.label,
177 [[self class] 162 [[self class]
178 stringForState:self.readyState]]; 163 stringForState:self.readyState]];
179 } 164 }
180 165
181 #pragma mark - Private 166 #pragma mark - Private
182 167
183 - (instancetype)initWithNativeDataChannel: 168 - (instancetype)initWithNativeDataChannel:
184 (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel { 169 (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel {
185 NSParameterAssert(nativeDataChannel); 170 NSParameterAssert(nativeDataChannel);
186 if (self = [super init]) { 171 if (self = [super init]) {
187 _nativeDataChannel = nativeDataChannel; 172 _nativeDataChannel = nativeDataChannel;
188 _observer.reset(new webrtc::DataChannelDelegateAdapter(self)); 173 _observer.reset(new webrtc::DataChannelDelegateAdapter(self));
174 _nativeDataChannel->RegisterObserver(_observer.get());
189 } 175 }
190 return self; 176 return self;
191 } 177 }
192 178
193 + (webrtc::DataChannelInterface::DataState) 179 + (webrtc::DataChannelInterface::DataState)
194 nativeDataChannelStateForState:(RTCDataChannelState)state { 180 nativeDataChannelStateForState:(RTCDataChannelState)state {
195 switch (state) { 181 switch (state) {
196 case RTCDataChannelStateConnecting: 182 case RTCDataChannelStateConnecting:
197 return webrtc::DataChannelInterface::DataState::kConnecting; 183 return webrtc::DataChannelInterface::DataState::kConnecting;
198 case RTCDataChannelStateOpen: 184 case RTCDataChannelStateOpen:
(...skipping 26 matching lines...) Expand all
225 case RTCDataChannelStateOpen: 211 case RTCDataChannelStateOpen:
226 return @"Open"; 212 return @"Open";
227 case RTCDataChannelStateClosing: 213 case RTCDataChannelStateClosing:
228 return @"Closing"; 214 return @"Closing";
229 case RTCDataChannelStateClosed: 215 case RTCDataChannelStateClosed:
230 return @"Closed"; 216 return @"Closed";
231 } 217 }
232 } 218 }
233 219
234 @end 220 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698