Remove JsepSessionDescription's string Initialize method

Most clients already use webrtc::CreateSessionDescription which
does the same thing and has the benefit of initializing in one
step instead of two and freeing the newly-created session
description if there was a parse error.

Bug: None
Change-Id: Ibeafdf7a6dd73eaea696700bc5eb420838371b75
Reviewed-on: https://chromium-review.googlesource.com/662402
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Original-Commit-Position: refs/heads/master@{#19808}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 6d64e9a4e0d4dcbf741584e0fc77bf8bedc50fc4
diff --git a/api/jsepsessiondescription.h b/api/jsepsessiondescription.h
index cb234b0..69945b4 100644
--- a/api/jsepsessiondescription.h
+++ b/api/jsepsessiondescription.h
@@ -35,9 +35,6 @@
   explicit JsepSessionDescription(const std::string& type);
   virtual ~JsepSessionDescription();
 
-  // |error| may be null.
-  bool Initialize(const std::string& sdp, SdpParseError* error);
-
   // Takes ownership of |description|.
   // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is
   // more clear.
diff --git a/pc/jsepsessiondescription.cc b/pc/jsepsessiondescription.cc
index 2e972ea..bdb3695 100644
--- a/pc/jsepsessiondescription.cc
+++ b/pc/jsepsessiondescription.cc
@@ -121,7 +121,7 @@
   }
 
   JsepSessionDescription* jsep_desc = new JsepSessionDescription(type);
-  if (!jsep_desc->Initialize(sdp, error)) {
+  if (!SdpDeserialize(sdp, jsep_desc, error)) {
     delete jsep_desc;
     return NULL;
   }
@@ -148,11 +148,6 @@
   return true;
 }
 
-bool JsepSessionDescription::Initialize(const std::string& sdp,
-                                        SdpParseError* error) {
-  return SdpDeserialize(sdp, this, error);
-}
-
 bool JsepSessionDescription::AddCandidate(
     const IceCandidateInterface* candidate) {
   if (!candidate || candidate->sdp_mline_index() < 0)
diff --git a/pc/jsepsessiondescription_unittest.cc b/pc/jsepsessiondescription_unittest.cc
index 4d8218a..62052af 100644
--- a/pc/jsepsessiondescription_unittest.cc
+++ b/pc/jsepsessiondescription_unittest.cc
@@ -13,6 +13,7 @@
 
 #include "webrtc/api/jsepicecandidate.h"
 #include "webrtc/api/jsepsessiondescription.h"
+#include "webrtc/api/webrtcsdp.h"
 #include "webrtc/p2p/base/candidate.h"
 #include "webrtc/p2p/base/p2pconstants.h"
 #include "webrtc/p2p/base/sessiondescription.h"
@@ -97,7 +98,7 @@
 
   SessionDescriptionInterface* DeSerialize(const std::string& sdp) {
     JsepSessionDescription* desc(new JsepSessionDescription("dummy"));
-    EXPECT_TRUE(desc->Initialize(sdp, NULL));
+    EXPECT_TRUE(webrtc::SdpDeserialize(sdp, desc, nullptr));
     return desc;
   }
 
diff --git a/pc/webrtcsession_unittest.cc b/pc/webrtcsession_unittest.cc
index 2088327..8621965 100644
--- a/pc/webrtcsession_unittest.cc
+++ b/pc/webrtcsession_unittest.cc
@@ -1218,8 +1218,9 @@
                                         kSessionVersion, current_desc);
   }
 
-  JsepSessionDescription* CreateRemoteOfferWithSctpPort(
-      const char* sctp_stream_name, int new_port,
+  SessionDescriptionInterface* CreateRemoteOfferWithSctpPort(
+      const char* sctp_stream_name,
+      int new_port,
       cricket::MediaSessionOptions options) {
     options.data_channel_type = cricket::DCT_SCTP;
     GetOptionsForRemoteOffer(&options);
@@ -1227,8 +1228,9 @@
   }
 
   // Takes ownership of offer_basis (and deletes it).
-  JsepSessionDescription* ChangeSDPSctpPort(
-      int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
+  SessionDescriptionInterface* ChangeSDPSctpPort(
+      int new_port,
+      webrtc::SessionDescriptionInterface* offer_basis) {
     // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
     // SessionDescription from the mutated string.
     const char* default_port_str = "5000";
@@ -1239,10 +1241,9 @@
     rtc::replace_substrs(default_port_str, strlen(default_port_str),
                                new_port_str, strlen(new_port_str),
                                &offer_str);
-    JsepSessionDescription* offer = new JsepSessionDescription(
-        offer_basis->type());
+    SessionDescriptionInterface* offer =
+        CreateSessionDescription(offer_basis->type(), offer_str, nullptr);
     delete offer_basis;
-    offer->Initialize(offer_str, NULL);
     return offer;
   }
 
@@ -3683,14 +3684,16 @@
   rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
                              xrtcp_mux.c_str(), xrtcp_mux.length(),
                              &offer_str);
-  JsepSessionDescription* local_offer =
-      new JsepSessionDescription(JsepSessionDescription::kOffer);
-  EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
+  SessionDescriptionInterface* local_offer = CreateSessionDescription(
+      SessionDescriptionInterface::kOffer, offer_str, nullptr);
+  ASSERT_TRUE(local_offer);
   SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
-  JsepSessionDescription* remote_offer =
-      new JsepSessionDescription(JsepSessionDescription::kOffer);
-  EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
+
+  SessionDescriptionInterface* remote_offer = CreateSessionDescription(
+      SessionDescriptionInterface::kOffer, offer_str, nullptr);
+  ASSERT_TRUE(remote_offer);
   SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
+
   // Trying unmodified SDP.
   SetLocalDescriptionWithoutError(offer);
 }
@@ -4189,8 +4192,8 @@
   // let the session description get parsed.  That'll get the proper codecs
   // into the stream.
   cricket::MediaSessionOptions options;
-  JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
-      "stream1", new_send_port, options);
+  SessionDescriptionInterface* offer =
+      CreateRemoteOfferWithSctpPort("stream1", new_send_port, options);
 
   // SetRemoteDescription will take the ownership of the offer.
   SetRemoteDescriptionWithoutError(offer);