| Index: webrtc/p2p/base/port.cc | 
| diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc | 
| index 842a26e8260df55b740eed7527c13a22698a7309..388b2d09d4f77de502a96811cfe4c2c7c4d96134 100644 | 
| --- a/webrtc/p2p/base/port.cc | 
| +++ b/webrtc/p2p/base/port.cc | 
| @@ -801,7 +801,8 @@ Connection::Connection(Port* port, | 
| sent_packets_total_(0), | 
| reported_(false), | 
| state_(STATE_WAITING), | 
| -      receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT) { | 
| +      receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT), | 
| +      time_created_ms_(rtc::Time()) { | 
| // All of our connections start in WAITING state. | 
| // TODO(mallinath) - Start connections from STATE_FROZEN. | 
| // Wire up to send stun packets | 
| @@ -849,7 +850,6 @@ void Connection::set_write_state(WriteState value) { | 
| LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " | 
| << value; | 
| SignalStateChange(this); | 
| -    CheckTimeout(); | 
| } | 
| } | 
|  | 
| @@ -858,7 +858,6 @@ void Connection::set_receiving(bool value) { | 
| LOG_J(LS_VERBOSE, this) << "set_receiving to " << value; | 
| receiving_ = value; | 
| SignalStateChange(this); | 
| -    CheckTimeout(); | 
| } | 
| } | 
|  | 
| @@ -1089,6 +1088,9 @@ void Connection::UpdateState(uint32 now) { | 
| uint32 last_recv_time = last_received(); | 
| bool receiving = now <= last_recv_time + receiving_timeout_; | 
| set_receiving(receiving); | 
| +  if (Dead(now)) { | 
| +    Destroy(); | 
| +  } | 
| } | 
|  | 
| void Connection::Ping(uint32 now) { | 
| @@ -1119,6 +1121,28 @@ void Connection::ReceivedPingResponse() { | 
| last_ping_response_received_ = rtc::Time(); | 
| } | 
|  | 
| +bool Connection::Dead(uint32 now) const { | 
| +  if (now < (time_created_ms_ + MIN_CONNECTION_LIFETIME)) { | 
| +    // A connection that hasn't passed its minimum lifetime is still alive. | 
| +    // We do this to prevent connections from being pruned too quickly | 
| +    // during a network change event when two networks would be up | 
| +    // simultaneously but only for a brief period. | 
| +    return false; | 
| +  } | 
| + | 
| +  if (receiving_) { | 
| +    // A connection that is receiving is alive. | 
| +    return false; | 
| +  } | 
| + | 
| +  // A connection is alive until it is inactive. | 
| +  return !Active(); | 
| + | 
| +  // TODO(honghaiz): Move from using the write state to using the receiving | 
| +  // state with something like the following: | 
| +  // return (now > (last_received() + DEAD_CONNECTION_RECEIVE_TIMEOUT)); | 
| +} | 
| + | 
| std::string Connection::ToDebugId() const { | 
| std::stringstream ss; | 
| ss << std::hex << this; | 
| @@ -1251,13 +1275,6 @@ void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 
| << ", use_candidate=" << use_candidate; | 
| } | 
|  | 
| -void Connection::CheckTimeout() { | 
| -  // If write has timed out and it is not receiving, remove the connection. | 
| -  if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) { | 
| -    Destroy(); | 
| -  } | 
| -} | 
| - | 
| void Connection::HandleRoleConflictFromPeer() { | 
| port_->SignalRoleConflict(port_); | 
| } | 
|  |