Chromium Code Reviews| Index: webrtc/api/peerconnection.cc | 
| diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc | 
| index 70a386ec14f8905382893b266589b17afefc5456..fd98ca7839cc451b7f2afa571a704acc8c757060 100644 | 
| --- a/webrtc/api/peerconnection.cc | 
| +++ b/webrtc/api/peerconnection.cc | 
| @@ -66,6 +66,9 @@ static const char kTransport[] = "transport"; | 
| // NOTE: Must be in the same order as the ServiceType enum. | 
| static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"}; | 
| +// The length of CNAME | 
| 
 
Taylor Brandstetter
2016/04/13 23:03:06
nit: Change to "The length of generated CNAMEs."
 
 | 
| +static const int kCnameLength = 16; | 
| + | 
| // NOTE: A loop below assumes that the first value of this enum is 0 and all | 
| // other values are incremental. | 
| enum ServiceType { | 
| @@ -377,6 +380,15 @@ void AddSendStreams( | 
| namespace webrtc { | 
| +// Generate a CNAME when the PeerConnection are created. | 
| +std::string GenerateCname() { | 
| + std::string cname; | 
| + if (!rtc::CreateRandomString(kCnameLength, &cname)) { | 
| + LOG(LS_ERROR) << "Failed to generate CNAME."; | 
| + } | 
| + return cname; | 
| +} | 
| + | 
| bool ExtractMediaSessionOptions( | 
| const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 
| bool is_offer, | 
| @@ -508,6 +520,7 @@ PeerConnection::PeerConnection(PeerConnectionFactory* factory) | 
| ice_state_(kIceNew), | 
| ice_connection_state_(kIceConnectionNew), | 
| ice_gathering_state_(kIceGatheringNew), | 
| + cname_(GenerateCname()), | 
| local_streams_(StreamCollection::Create()), | 
| remote_streams_(StreamCollection::Create()) {} | 
| @@ -1503,6 +1516,8 @@ bool PeerConnection::GetOptionsForOffer( | 
| if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { | 
| session_options->data_channel_type = cricket::DCT_SCTP; | 
| } | 
| + | 
| + session_options->cname = cname_; | 
| return true; | 
| } | 
| @@ -1540,6 +1555,8 @@ bool PeerConnection::GetOptionsForAnswer( | 
| if (!ParseConstraintsForAnswer(constraints, session_options)) { | 
| return false; | 
| } | 
| + session_options->cname = cname_; | 
| + | 
| FinishOptionsForAnswer(session_options); | 
| return true; | 
| } | 
| @@ -1552,6 +1569,8 @@ bool PeerConnection::GetOptionsForAnswer( | 
| if (!ExtractMediaSessionOptions(options, false, session_options)) { | 
| return false; | 
| } | 
| + session_options->cname = cname_; | 
| + | 
| FinishOptionsForAnswer(session_options); | 
| return true; | 
| } |