Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 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 #include "webrtc/api/quicdatatransport.h" | 11 #include "webrtc/api/quicdatatransport.h" |
| 12 | 12 |
| 13 #include "webrtc/base/bind.h" | |
| 13 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/p2p/quic/quictransportchannel.h" | 15 #include "webrtc/p2p/quic/quictransportchannel.h" |
| 15 #include "webrtc/p2p/quic/reliablequicstream.h" | 16 #include "webrtc/p2p/quic/reliablequicstream.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 QuicDataTransport::QuicDataTransport(rtc::Thread* signaling_thread, | 20 QuicDataTransport::QuicDataTransport( |
| 20 rtc::Thread* worker_thread, | 21 rtc::Thread* signaling_thread, |
| 21 rtc::Thread* network_thread) | 22 rtc::Thread* worker_thread, |
| 23 rtc::Thread* network_thread, | |
| 24 cricket::TransportController* transport_controller) | |
| 22 : signaling_thread_(signaling_thread), | 25 : signaling_thread_(signaling_thread), |
| 23 worker_thread_(worker_thread), | 26 worker_thread_(worker_thread), |
| 24 network_thread_(network_thread) { | 27 network_thread_(network_thread), |
| 28 transport_controller_(transport_controller) { | |
| 25 RTC_DCHECK(signaling_thread_); | 29 RTC_DCHECK(signaling_thread_); |
| 26 RTC_DCHECK(worker_thread_); | 30 RTC_DCHECK(worker_thread_); |
| 27 RTC_DCHECK(network_thread_); | 31 RTC_DCHECK(network_thread_); |
| 28 } | 32 } |
| 29 | 33 |
| 30 QuicDataTransport::~QuicDataTransport() {} | 34 QuicDataTransport::~QuicDataTransport() { |
| 35 DestroyTransportChannels(); | |
|
pthatcher1
2016/07/27 23:21:49
DestroyTransportChannel(quic_transport_channel_);
Zhi Huang
2016/08/01 05:12:28
Done.
| |
| 36 LOG(LS_INFO) << "Destroyed the QUIC data transport."; | |
| 37 } | |
| 38 | |
| 39 bool QuicDataTransport::SetTransport(const std::string& transport_name) { | |
| 40 if (transport_name_ == transport_name) { | |
| 41 // Nothing to do if transport name isn't changing | |
| 42 return true; | |
| 43 } | |
| 44 | |
|
pthatcher1
2016/07/27 23:21:49
tc = CreateTransportChannel(transport_name);
if (!
| |
| 45 SetTransportChannel(CreateTransportChannel(transport_name)); | |
| 46 | |
| 47 if (!quic_transport_channel_) { | |
| 48 return false; | |
| 49 } | |
|
pthatcher1
2016/07/27 23:21:49
You don't need this if you have the "return false"
Zhi Huang
2016/08/01 05:12:28
Done.
| |
| 50 | |
| 51 transport_name_ = transport_name; | |
| 52 return true; | |
| 53 } | |
| 31 | 54 |
| 32 bool QuicDataTransport::SetTransportChannel( | 55 bool QuicDataTransport::SetTransportChannel( |
| 33 cricket::QuicTransportChannel* channel) { | 56 cricket::QuicTransportChannel* channel) { |
| 34 if (!channel) { | 57 if (!channel) { |
| 35 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel."; | 58 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel."; |
| 36 return false; | 59 return false; |
| 37 } | 60 } |
| 38 if (quic_transport_channel_) { | 61 if (quic_transport_channel_) { |
| 39 if (channel == quic_transport_channel_) { | 62 if (channel == quic_transport_channel_) { |
| 40 LOG(LS_WARNING) << "Ignoring duplicate transport channel."; | 63 LOG(LS_WARNING) << "Ignoring duplicate transport channel."; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 return; | 163 return; |
| 141 } | 164 } |
| 142 QuicDataChannel* data_channel = data_channel_kv->second; | 165 QuicDataChannel* data_channel = data_channel_kv->second; |
| 143 QuicDataChannel::Message message; | 166 QuicDataChannel::Message message; |
| 144 message.id = message_id; | 167 message.id = message_id; |
| 145 message.buffer = rtc::CopyOnWriteBuffer(data, len); | 168 message.buffer = rtc::CopyOnWriteBuffer(data, len); |
| 146 message.stream = stream; | 169 message.stream = stream; |
| 147 data_channel->OnIncomingMessage(std::move(message)); | 170 data_channel->OnIncomingMessage(std::move(message)); |
| 148 } | 171 } |
| 149 | 172 |
| 173 cricket::QuicTransportChannel* QuicDataTransport::CreateTransportChannel( | |
| 174 const std::string& transport_name) { | |
| 175 cricket::TransportChannel* transport_channel = | |
| 176 network_thread_->Invoke<cricket::TransportChannel*>( | |
| 177 RTC_FROM_HERE, | |
| 178 rtc::Bind(&cricket::TransportController::CreateTransportChannel_n, | |
| 179 transport_controller_, transport_name, | |
| 180 cricket::ICE_CANDIDATE_COMPONENT_DEFAULT)); | |
| 181 if (!transport_channel) { | |
| 182 return nullptr; | |
| 183 } | |
|
pthatcher1
2016/07/27 23:21:49
You don't need this
Zhi Huang
2016/08/01 05:12:28
Done.
| |
| 184 return static_cast<cricket::QuicTransportChannel*>(transport_channel); | |
| 185 } | |
| 186 | |
| 187 void QuicDataTransport::DestroyTransportChannels() { | |
|
pthatcher1
2016/07/27 23:21:49
DestroyTransportChannel(TransportChannel* tc)
| |
| 188 if (quic_transport_channel_) { | |
|
pthatcher1
2016/07/27 23:21:49
if (!tc) {
return;
}
network_thread_->Invoke<voi
| |
| 189 network_thread_->Invoke<void>( | |
| 190 RTC_FROM_HERE, | |
| 191 rtc::Bind(&cricket::TransportController::DestroyTransportChannel_n, | |
| 192 transport_controller_, transport_name_, | |
| 193 cricket::ICE_CANDIDATE_COMPONENT_DEFAULT)); | |
| 194 } | |
| 195 } | |
| 196 | |
| 150 } // namespace webrtc | 197 } // namespace webrtc |
| OLD | NEW |