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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 1411103012: A little cleanup in the p2ptransportchannel. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month 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 | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/transportchannel.h » ('j') | 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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 bool all_connections_timedout = true; 984 bool all_connections_timedout = true;
985 for (size_t i = 0; i < connections_.size(); ++i) { 985 for (size_t i = 0; i < connections_.size(); ++i) {
986 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) { 986 if (connections_[i]->write_state() != Connection::STATE_WRITE_TIMEOUT) {
987 all_connections_timedout = false; 987 all_connections_timedout = false;
988 break; 988 break;
989 } 989 }
990 } 990 }
991 991
992 // Now update the writable state of the channel with the information we have 992 // Now update the writable state of the channel with the information we have
993 // so far. 993 // so far.
994 if (best_connection_ && best_connection_->writable()) { 994 if (all_connections_timedout) {
995 HandleWritable();
996 } else if (all_connections_timedout) {
997 HandleAllTimedOut(); 995 HandleAllTimedOut();
998 } else {
999 HandleNotWritable();
1000 } 996 }
1001 997
1002 // Update the state of this channel. This method is called whenever the 998 // Update the state of this channel. This method is called whenever the
1003 // state of any connection changes, so this is a good place to do this. 999 // state of any connection changes, so this is a good place to do this.
1004 UpdateChannelState(); 1000 UpdateChannelState();
1005 } 1001 }
1006 1002
1007 Connection* P2PTransportChannel::best_nominated_connection() const { 1003 Connection* P2PTransportChannel::best_nominated_connection() const {
1008 return (best_connection_ && best_connection_->nominated()) ? best_connection_ 1004 return (best_connection_ && best_connection_->nominated()) ? best_connection_
1009 : nullptr; 1005 : nullptr;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 } 1051 }
1056 LOG_J(LS_INFO, this) << "New best connection: " 1052 LOG_J(LS_INFO, this) << "New best connection: "
1057 << best_connection_->ToString(); 1053 << best_connection_->ToString();
1058 SignalRouteChange(this, best_connection_->remote_candidate()); 1054 SignalRouteChange(this, best_connection_->remote_candidate());
1059 } else { 1055 } else {
1060 LOG_J(LS_INFO, this) << "No best connection"; 1056 LOG_J(LS_INFO, this) << "No best connection";
1061 } 1057 }
1062 } 1058 }
1063 1059
1064 void P2PTransportChannel::UpdateChannelState() { 1060 void P2PTransportChannel::UpdateChannelState() {
1065 // The Handle* functions already set the writable state. We'll just double-
1066 // check it here.
1067 bool writable = best_connection_ && best_connection_->writable(); 1061 bool writable = best_connection_ && best_connection_->writable();
1068 ASSERT(writable == this->writable()); 1062 set_writable(writable);
1069 if (writable != this->writable())
1070 LOG(LS_ERROR) << "UpdateChannelState: writable state mismatch";
1071 1063
1072 bool receiving = false; 1064 bool receiving = false;
1073 for (const Connection* connection : connections_) { 1065 for (const Connection* connection : connections_) {
1074 if (connection->receiving()) { 1066 if (connection->receiving()) {
1075 receiving = true; 1067 receiving = true;
1076 break; 1068 break;
1077 } 1069 }
1078 } 1070 }
1079 set_receiving(receiving); 1071 set_receiving(receiving);
1080 } 1072 }
(...skipping 10 matching lines...) Expand all
1091 // If gathering continually, keep the last session running so that it 1083 // If gathering continually, keep the last session running so that it
1092 // will gather candidates if the networks change. 1084 // will gather candidates if the networks change.
1093 if (gather_continually_ && session == allocator_sessions_.back()) { 1085 if (gather_continually_ && session == allocator_sessions_.back()) {
1094 session->ClearGettingPorts(); 1086 session->ClearGettingPorts();
1095 break; 1087 break;
1096 } 1088 }
1097 session->StopGettingPorts(); 1089 session->StopGettingPorts();
1098 } 1090 }
1099 } 1091 }
1100 1092
1101 // Go into the writable state and notify upper layer if it was not before.
1102 void P2PTransportChannel::HandleWritable() {
1103 ASSERT(worker_thread_ == rtc::Thread::Current());
1104 if (!writable()) {
1105 set_writable(true);
1106 }
1107 }
1108
1109 // Notify upper layer about channel not writable state, if it was before.
1110 void P2PTransportChannel::HandleNotWritable() {
1111 ASSERT(worker_thread_ == rtc::Thread::Current());
1112 if (writable()) {
1113 set_writable(false);
1114 }
1115 }
1116
1117 // If all connections timed out, delete them all. 1093 // If all connections timed out, delete them all.
1118 void P2PTransportChannel::HandleAllTimedOut() { 1094 void P2PTransportChannel::HandleAllTimedOut() {
1119 for (Connection* connection : connections_) { 1095 for (Connection* connection : connections_) {
1120 connection->Destroy(); 1096 connection->Destroy();
1121 } 1097 }
1122 } 1098 }
1123 1099
1124 bool P2PTransportChannel::weak() const { 1100 bool P2PTransportChannel::weak() const {
1125 return !best_connection_ || best_connection_->weak(); 1101 return !best_connection_ || best_connection_->weak();
1126 } 1102 }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 SignalSentPacket(this, sent_packet); 1361 SignalSentPacket(this, sent_packet);
1386 } 1362 }
1387 1363
1388 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1364 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1389 if (connection == best_connection_ && writable()) { 1365 if (connection == best_connection_ && writable()) {
1390 SignalReadyToSend(this); 1366 SignalReadyToSend(this);
1391 } 1367 }
1392 } 1368 }
1393 1369
1394 } // namespace cricket 1370 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/transportchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698