Chromium Code Reviews| 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 #include "remoting/protocol/libjingle_transport_factory.h" | 5 #include "remoting/protocol/libjingle_transport_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 void SetRemoteCredentials(const std::string& ufrag, | 71 void SetRemoteCredentials(const std::string& ufrag, |
| 72 const std::string& password) override; | 72 const std::string& password) override; |
| 73 void AddRemoteCandidate(const cricket::Candidate& candidate) override; | 73 void AddRemoteCandidate(const cricket::Candidate& candidate) override; |
| 74 const std::string& name() const override; | 74 const std::string& name() const override; |
| 75 bool is_connected() const override; | 75 bool is_connected() const override; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 void DoStart(); | 78 void DoStart(); |
| 79 void NotifyConnected(); | 79 void NotifyConnected(); |
| 80 | 80 |
| 81 // Signal handlers for cricket::TransportChannel. | 81 void OnCandidateGathered(cricket::TransportChannelImpl* channel, |
| 82 void OnRequestSignaling(cricket::TransportChannelImpl* channel); | |
| 83 void OnCandidateReady(cricket::TransportChannelImpl* channel, | |
| 84 const cricket::Candidate& candidate); | 82 const cricket::Candidate& candidate); |
|
Sergey Ulanov
2015/09/04 18:37:32
update indentation please
Taylor_Brandstetter
2015/09/04 18:58:59
Done.
| |
| 85 void OnRouteChange(cricket::TransportChannel* channel, | 83 void OnRouteChange(cricket::TransportChannel* channel, |
| 86 const cricket::Candidate& candidate); | 84 const cricket::Candidate& candidate); |
| 87 void OnWritableState(cricket::TransportChannel* channel); | 85 void OnWritableState(cricket::TransportChannel* channel); |
| 88 | 86 |
| 89 // Callback for TransportChannelSocketAdapter to notify when the socket is | 87 // Callback for TransportChannelSocketAdapter to notify when the socket is |
| 90 // destroyed. | 88 // destroyed. |
| 91 void OnChannelDestroyed(); | 89 void OnChannelDestroyed(); |
| 92 | 90 |
| 93 void NotifyRouteChanged(); | 91 void NotifyRouteChanged(); |
| 94 | 92 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 if (!callback_.is_null()) | 152 if (!callback_.is_null()) |
| 155 DoStart(); | 153 DoStart(); |
| 156 | 154 |
| 157 // Pass pending ICE credentials and candidates to the channel. | 155 // Pass pending ICE credentials and candidates to the channel. |
| 158 if (!remote_ice_username_fragment_.empty()) { | 156 if (!remote_ice_username_fragment_.empty()) { |
| 159 channel_->SetRemoteIceCredentials(remote_ice_username_fragment_, | 157 channel_->SetRemoteIceCredentials(remote_ice_username_fragment_, |
| 160 remote_ice_password_); | 158 remote_ice_password_); |
| 161 } | 159 } |
| 162 | 160 |
| 163 while (!pending_candidates_.empty()) { | 161 while (!pending_candidates_.empty()) { |
| 164 channel_->OnCandidate(pending_candidates_.front()); | 162 channel_->AddRemoteCandidate(pending_candidates_.front()); |
| 165 pending_candidates_.pop_front(); | 163 pending_candidates_.pop_front(); |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 | 166 |
| 169 void LibjingleTransport::Connect( | 167 void LibjingleTransport::Connect( |
| 170 const std::string& name, | 168 const std::string& name, |
| 171 Transport::EventHandler* event_handler, | 169 Transport::EventHandler* event_handler, |
| 172 const Transport::ConnectedCallback& callback) { | 170 const Transport::ConnectedCallback& callback) { |
| 173 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
| 174 DCHECK(!name.empty()); | 172 DCHECK(!name.empty()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 191 // TODO(sergeyu): Specify correct component ID for the channel. | 189 // TODO(sergeyu): Specify correct component ID for the channel. |
| 192 channel_.reset(new cricket::P2PTransportChannel( | 190 channel_.reset(new cricket::P2PTransportChannel( |
| 193 std::string(), 0, nullptr, port_allocator_)); | 191 std::string(), 0, nullptr, port_allocator_)); |
| 194 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); | 192 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); |
| 195 channel_->SetIceRole((role_ == TransportRole::CLIENT) | 193 channel_->SetIceRole((role_ == TransportRole::CLIENT) |
| 196 ? cricket::ICEROLE_CONTROLLING | 194 ? cricket::ICEROLE_CONTROLLING |
| 197 : cricket::ICEROLE_CONTROLLED); | 195 : cricket::ICEROLE_CONTROLLED); |
| 198 event_handler_->OnTransportIceCredentials(this, ice_username_fragment_, | 196 event_handler_->OnTransportIceCredentials(this, ice_username_fragment_, |
| 199 ice_password); | 197 ice_password); |
| 200 channel_->SetIceCredentials(ice_username_fragment_, ice_password); | 198 channel_->SetIceCredentials(ice_username_fragment_, ice_password); |
| 201 channel_->SignalRequestSignaling.connect( | 199 channel_->SignalCandidateGathered.connect( |
| 202 this, &LibjingleTransport::OnRequestSignaling); | 200 this, &LibjingleTransport::OnCandidateGathered); |
| 203 channel_->SignalCandidateReady.connect( | |
| 204 this, &LibjingleTransport::OnCandidateReady); | |
| 205 channel_->SignalRouteChange.connect( | 201 channel_->SignalRouteChange.connect( |
| 206 this, &LibjingleTransport::OnRouteChange); | 202 this, &LibjingleTransport::OnRouteChange); |
| 207 channel_->SignalWritableState.connect( | 203 channel_->SignalWritableState.connect( |
| 208 this, &LibjingleTransport::OnWritableState); | 204 this, &LibjingleTransport::OnWritableState); |
| 209 channel_->set_incoming_only( | 205 channel_->set_incoming_only( |
| 210 !(network_settings_.flags & NetworkSettings::NAT_TRAVERSAL_OUTGOING)); | 206 !(network_settings_.flags & NetworkSettings::NAT_TRAVERSAL_OUTGOING)); |
| 211 | 207 |
| 212 channel_->Connect(); | 208 channel_->Connect(); |
| 213 | 209 |
| 214 --connect_attempts_left_; | 210 --connect_attempts_left_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 DCHECK(CalledOnValidThread()); | 244 DCHECK(CalledOnValidThread()); |
| 249 | 245 |
| 250 // To enforce the no-relay setting, it's not enough to not produce relay | 246 // To enforce the no-relay setting, it's not enough to not produce relay |
| 251 // candidates. It's also necessary to discard remote relay candidates. | 247 // candidates. It's also necessary to discard remote relay candidates. |
| 252 bool relay_allowed = (network_settings_.flags & | 248 bool relay_allowed = (network_settings_.flags & |
| 253 NetworkSettings::NAT_TRAVERSAL_RELAY) != 0; | 249 NetworkSettings::NAT_TRAVERSAL_RELAY) != 0; |
| 254 if (!relay_allowed && candidate.type() == cricket::RELAY_PORT_TYPE) | 250 if (!relay_allowed && candidate.type() == cricket::RELAY_PORT_TYPE) |
| 255 return; | 251 return; |
| 256 | 252 |
| 257 if (channel_) { | 253 if (channel_) { |
| 258 channel_->OnCandidate(candidate); | 254 channel_->AddRemoteCandidate(candidate); |
| 259 } else { | 255 } else { |
| 260 pending_candidates_.push_back(candidate); | 256 pending_candidates_.push_back(candidate); |
| 261 } | 257 } |
| 262 } | 258 } |
| 263 | 259 |
| 264 const std::string& LibjingleTransport::name() const { | 260 const std::string& LibjingleTransport::name() const { |
| 265 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
| 266 return name_; | 262 return name_; |
| 267 } | 263 } |
| 268 | 264 |
| 269 bool LibjingleTransport::is_connected() const { | 265 bool LibjingleTransport::is_connected() const { |
| 270 DCHECK(CalledOnValidThread()); | 266 DCHECK(CalledOnValidThread()); |
| 271 return callback_.is_null(); | 267 return callback_.is_null(); |
| 272 } | 268 } |
| 273 | 269 |
| 274 void LibjingleTransport::OnRequestSignaling( | 270 void LibjingleTransport::OnCandidateGathered( |
| 275 cricket::TransportChannelImpl* channel) { | |
| 276 DCHECK(CalledOnValidThread()); | |
| 277 channel_->OnSignalingReady(); | |
| 278 } | |
| 279 | |
| 280 void LibjingleTransport::OnCandidateReady( | |
| 281 cricket::TransportChannelImpl* channel, | 271 cricket::TransportChannelImpl* channel, |
| 282 const cricket::Candidate& candidate) { | 272 const cricket::Candidate& candidate) { |
| 283 DCHECK(CalledOnValidThread()); | 273 DCHECK(CalledOnValidThread()); |
| 284 event_handler_->OnTransportCandidate(this, candidate); | 274 event_handler_->OnTransportCandidate(this, candidate); |
| 285 } | 275 } |
| 286 | 276 |
| 287 void LibjingleTransport::OnRouteChange( | 277 void LibjingleTransport::OnRouteChange( |
| 288 cricket::TransportChannel* channel, | 278 cricket::TransportChannel* channel, |
| 289 const cricket::Candidate& candidate) { | 279 const cricket::Candidate& candidate) { |
| 290 // Ignore notifications if the channel is not writable. | 280 // Ignore notifications if the channel is not writable. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 last_jingle_info_update_time_ = base::TimeTicks::Now(); | 435 last_jingle_info_update_time_ = base::TimeTicks::Now(); |
| 446 | 436 |
| 447 while (!on_jingle_info_callbacks_.empty()) { | 437 while (!on_jingle_info_callbacks_.empty()) { |
| 448 on_jingle_info_callbacks_.begin()->Run(); | 438 on_jingle_info_callbacks_.begin()->Run(); |
| 449 on_jingle_info_callbacks_.pop_front(); | 439 on_jingle_info_callbacks_.pop_front(); |
| 450 } | 440 } |
| 451 } | 441 } |
| 452 | 442 |
| 453 } // namespace protocol | 443 } // namespace protocol |
| 454 } // namespace remoting | 444 } // namespace remoting |
| OLD | NEW |