Move sessiondescription.h/cc from p2p/base to pc/

SDP is a detail of PeerConnection and is not used by anything in p2p, so
it belongs in the pc/ directory. This also allows
MediaContentDescription to be inlined in the future.

Bug: webrtc:8620
Change-Id: I38b65ede9942e29eb15035ab29f2be988da1e5ce
Reviewed-on: https://webrtc-review.googlesource.com/33781
Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21376}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 1b39aaa..c51a6a2 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -32,7 +32,6 @@
   'modules/media_file',
   'modules/utility',
   'modules/video_capture',
-  'p2p/base/sessiondescription.cc',
   'p2p/base/session.cc',
   'p2p/base/session.h',
   'p2p/base/pseudotcp.cc',
diff --git a/media/base/fakemediaengine.h b/media/base/fakemediaengine.h
index 38458f2..609b62f 100644
--- a/media/base/fakemediaengine.h
+++ b/media/base/fakemediaengine.h
@@ -27,7 +27,6 @@
 #include "media/base/streamparams.h"
 #include "media/engine/webrtcvideoengine.h"
 #include "modules/audio_processing/include/audio_processing.h"
-#include "p2p/base/sessiondescription.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/copyonwritebuffer.h"
 #include "rtc_base/networkroute.h"
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index f2173f4..f80352d 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -57,8 +57,6 @@
     "base/relayport.h",
     "base/session.cc",
     "base/session.h",
-    "base/sessiondescription.cc",
-    "base/sessiondescription.h",
     "base/stun.cc",
     "base/stun.h",
     "base/stunport.cc",
diff --git a/p2p/DEPS b/p2p/DEPS
index 94f4bcb..718aa63 100644
--- a/p2p/DEPS
+++ b/p2p/DEPS
@@ -2,3 +2,11 @@
   "+net",
   "+system_wrappers",
 ]
+
+specific_include_rules = {
+  # TODO(steveanton): Remove this forwarding header once downstream projects
+  # have updated to include the file in its new location.
+  "sessiondescription\.h": [
+    "+pc/sessiondescription.h",
+  ],
+}
diff --git a/p2p/base/sessiondescription.h b/p2p/base/sessiondescription.h
index 2de0838..07d2ec1 100644
--- a/p2p/base/sessiondescription.h
+++ b/p2p/base/sessiondescription.h
@@ -11,182 +11,8 @@
 #ifndef P2P_BASE_SESSIONDESCRIPTION_H_
 #define P2P_BASE_SESSIONDESCRIPTION_H_
 
-#include <string>
-#include <vector>
-
-#include "p2p/base/transportinfo.h"
-#include "rtc_base/constructormagic.h"
-
-namespace cricket {
-
-// Describes a session content. Individual content types inherit from
-// this class.  Analagous to a <jingle><content><description> or
-// <session><description>.
-class ContentDescription {
- public:
-  virtual ~ContentDescription() {}
-  virtual ContentDescription* Copy() const = 0;
-};
-
-// Analagous to a <jingle><content> or <session><description>.
-// name = name of <content name="...">
-// type = xmlns of <content>
-struct ContentInfo {
-  ContentInfo() {}
-  ContentInfo(const std::string& name,
-              const std::string& type,
-              ContentDescription* description)
-      : name(name), type(type), description(description) {}
-  ContentInfo(const std::string& name,
-              const std::string& type,
-              bool rejected,
-              ContentDescription* description) :
-      name(name), type(type), rejected(rejected), description(description) {}
-  ContentInfo(const std::string& name,
-              const std::string& type,
-              bool rejected,
-              bool bundle_only,
-              ContentDescription* description)
-      : name(name),
-        type(type),
-        rejected(rejected),
-        bundle_only(bundle_only),
-        description(description) {}
-  std::string name;
-  std::string type;
-  bool rejected = false;
-  bool bundle_only = false;
-  ContentDescription* description = nullptr;
-};
-
-typedef std::vector<std::string> ContentNames;
-
-// This class provides a mechanism to aggregate different media contents into a
-// group. This group can also be shared with the peers in a pre-defined format.
-// GroupInfo should be populated only with the |content_name| of the
-// MediaDescription.
-class ContentGroup {
- public:
-  explicit ContentGroup(const std::string& semantics);
-  ContentGroup(const ContentGroup&);
-  ContentGroup(ContentGroup&&);
-  ContentGroup& operator=(const ContentGroup&);
-  ContentGroup& operator=(ContentGroup&&);
-  ~ContentGroup();
-
-  const std::string& semantics() const { return semantics_; }
-  const ContentNames& content_names() const { return content_names_; }
-
-  const std::string* FirstContentName() const;
-  bool HasContentName(const std::string& content_name) const;
-  void AddContentName(const std::string& content_name);
-  bool RemoveContentName(const std::string& content_name);
-
- private:
-  std::string semantics_;
-  ContentNames content_names_;
-};
-
-typedef std::vector<ContentInfo> ContentInfos;
-typedef std::vector<ContentGroup> ContentGroups;
-
-const ContentInfo* FindContentInfoByName(
-    const ContentInfos& contents, const std::string& name);
-const ContentInfo* FindContentInfoByType(
-    const ContentInfos& contents, const std::string& type);
-
-// Describes a collection of contents, each with its own name and
-// type.  Analogous to a <jingle> or <session> stanza.  Assumes that
-// contents are unique be name, but doesn't enforce that.
-class SessionDescription {
- public:
-  SessionDescription();
-  explicit SessionDescription(const ContentInfos& contents);
-  SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
-  SessionDescription(const ContentInfos& contents,
-                     const TransportInfos& transports,
-                     const ContentGroups& groups);
-  ~SessionDescription();
-
-  SessionDescription* Copy() const;
-
-  // Content accessors.
-  const ContentInfos& contents() const { return contents_; }
-  ContentInfos& contents() { return contents_; }
-  const ContentInfo* GetContentByName(const std::string& name) const;
-  ContentInfo* GetContentByName(const std::string& name);
-  const ContentDescription* GetContentDescriptionByName(
-      const std::string& name) const;
-  ContentDescription* GetContentDescriptionByName(const std::string& name);
-  const ContentInfo* FirstContentByType(const std::string& type) const;
-  const ContentInfo* FirstContent() const;
-
-  // Content mutators.
-  // Adds a content to this description. Takes ownership of ContentDescription*.
-  void AddContent(const std::string& name,
-                  const std::string& type,
-                  ContentDescription* description);
-  void AddContent(const std::string& name,
-                  const std::string& type,
-                  bool rejected,
-                  ContentDescription* description);
-  void AddContent(const std::string& name,
-                  const std::string& type,
-                  bool rejected,
-                  bool bundle_only,
-                  ContentDescription* description);
-  bool RemoveContentByName(const std::string& name);
-
-  // Transport accessors.
-  const TransportInfos& transport_infos() const { return transport_infos_; }
-  TransportInfos& transport_infos() { return transport_infos_; }
-  const TransportInfo* GetTransportInfoByName(
-      const std::string& name) const;
-  TransportInfo* GetTransportInfoByName(const std::string& name);
-  const TransportDescription* GetTransportDescriptionByName(
-      const std::string& name) const {
-    const TransportInfo* tinfo = GetTransportInfoByName(name);
-    return tinfo ? &tinfo->description : NULL;
-  }
-
-  // Transport mutators.
-  void set_transport_infos(const TransportInfos& transport_infos) {
-    transport_infos_ = transport_infos;
-  }
-  // Adds a TransportInfo to this description.
-  // Returns false if a TransportInfo with the same name already exists.
-  bool AddTransportInfo(const TransportInfo& transport_info);
-  bool RemoveTransportInfoByName(const std::string& name);
-
-  // Group accessors.
-  const ContentGroups& groups() const { return content_groups_; }
-  const ContentGroup* GetGroupByName(const std::string& name) const;
-  bool HasGroup(const std::string& name) const;
-
-  // Group mutators.
-  void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
-  // Remove the first group with the same semantics specified by |name|.
-  void RemoveGroupByName(const std::string& name);
-
-  // Global attributes.
-  void set_msid_supported(bool supported) { msid_supported_ = supported; }
-  bool msid_supported() const { return msid_supported_; }
-
- private:
-  SessionDescription(const SessionDescription&);
-
-  ContentInfos contents_;
-  TransportInfos transport_infos_;
-  ContentGroups content_groups_;
-  bool msid_supported_ = true;
-};
-
-// Indicates whether a ContentDescription was sent by the local client
-// or received from the remote client.
-enum ContentSource {
-  CS_LOCAL, CS_REMOTE
-};
-
-}  // namespace cricket
+// TODO(steveanton): Remove this forwarding header once downstream projects
+// have updated to include the file in its new location.
+#include "pc/sessiondescription.h"
 
 #endif  // P2P_BASE_SESSIONDESCRIPTION_H_
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index aa5a5f4..a429290 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -56,6 +56,8 @@
     "rtptransport.h",
     "rtptransportinternal.h",
     "rtptransportinternaladapter.h",
+    "sessiondescription.cc",
+    "sessiondescription.h",
     "srtpfilter.cc",
     "srtpfilter.h",
     "srtpsession.cc",
diff --git a/pc/jsepsessiondescription_unittest.cc b/pc/jsepsessiondescription_unittest.cc
index 952fff9..1835f29 100644
--- a/pc/jsepsessiondescription_unittest.cc
+++ b/pc/jsepsessiondescription_unittest.cc
@@ -16,8 +16,8 @@
 #include "api/jsepsessiondescription.h"
 #include "p2p/base/p2pconstants.h"
 #include "p2p/base/port.h"
-#include "p2p/base/sessiondescription.h"
 #include "pc/mediasession.h"
+#include "pc/sessiondescription.h"
 #include "pc/webrtcsdp.h"
 #include "rtc_base/gunit.h"
 #include "rtc_base/ptr_util.h"
diff --git a/pc/jseptransport.h b/pc/jseptransport.h
index 068078b..972f91b 100644
--- a/pc/jseptransport.h
+++ b/pc/jseptransport.h
@@ -21,8 +21,8 @@
 #include "api/optional.h"
 #include "p2p/base/dtlstransport.h"
 #include "p2p/base/p2pconstants.h"
-#include "p2p/base/sessiondescription.h"
 #include "p2p/base/transportinfo.h"
+#include "pc/sessiondescription.h"
 #include "rtc_base/constructormagic.h"
 #include "rtc_base/messagequeue.h"
 #include "rtc_base/rtccertificate.h"
diff --git a/pc/mediasession.h b/pc/mediasession.h
index 784aad8..7f4e9cf 100644
--- a/pc/mediasession.h
+++ b/pc/mediasession.h
@@ -26,9 +26,9 @@
 #include "media/base/mediaconstants.h"
 #include "media/base/mediaengine.h"  // For DataChannelType
 #include "media/base/streamparams.h"
-#include "p2p/base/sessiondescription.h"
 #include "p2p/base/transportdescriptionfactory.h"
 #include "pc/jseptransport.h"
+#include "pc/sessiondescription.h"
 
 namespace cricket {
 
diff --git a/pc/peerconnection_integrationtest.cc b/pc/peerconnection_integrationtest.cc
index d301d98..6ae4a92 100644
--- a/pc/peerconnection_integrationtest.cc
+++ b/pc/peerconnection_integrationtest.cc
@@ -33,7 +33,6 @@
 #include "media/engine/fakewebrtcvideoengine.h"
 #include "p2p/base/p2pconstants.h"
 #include "p2p/base/portinterface.h"
-#include "p2p/base/sessiondescription.h"
 #include "p2p/base/teststunserver.h"
 #include "p2p/base/testturncustomizer.h"
 #include "p2p/base/testturnserver.h"
@@ -43,6 +42,7 @@
 #include "pc/mediasession.h"
 #include "pc/peerconnection.h"
 #include "pc/peerconnectionfactory.h"
+#include "pc/sessiondescription.h"
 #include "pc/test/fakeaudiocapturemodule.h"
 #include "pc/test/fakeperiodicvideocapturer.h"
 #include "pc/test/fakertccertificategenerator.h"
diff --git a/pc/rtcpmuxfilter.h b/pc/rtcpmuxfilter.h
index c2dad5b..55b6ea6 100644
--- a/pc/rtcpmuxfilter.h
+++ b/pc/rtcpmuxfilter.h
@@ -11,7 +11,7 @@
 #ifndef PC_RTCPMUXFILTER_H_
 #define PC_RTCPMUXFILTER_H_
 
-#include "p2p/base/sessiondescription.h"
+#include "pc/sessiondescription.h"
 
 namespace cricket {
 
diff --git a/pc/sdputils.h b/pc/sdputils.h
index 0b9fa35..0d2d304 100644
--- a/pc/sdputils.h
+++ b/pc/sdputils.h
@@ -16,7 +16,7 @@
 #include <string>
 
 #include "api/jsep.h"
-#include "p2p/base/sessiondescription.h"
+#include "pc/sessiondescription.h"
 
 namespace webrtc {
 
diff --git a/p2p/base/sessiondescription.cc b/pc/sessiondescription.cc
similarity index 88%
rename from p2p/base/sessiondescription.cc
rename to pc/sessiondescription.cc
index afe9a9a..6e90ac8 100644
--- a/p2p/base/sessiondescription.cc
+++ b/pc/sessiondescription.cc
@@ -8,23 +8,26 @@
  *  be found in the AUTHORS file in the root of the source tree.
  */
 
-#include "p2p/base/sessiondescription.h"
+#include "pc/sessiondescription.h"
 
 namespace cricket {
+namespace {
 
-ContentInfo* FindContentInfoByName(
-    ContentInfos& contents, const std::string& name) {
-  for (ContentInfos::iterator content = contents.begin();
-       content != contents.end(); ++content) {
-    if (content->name == name) {
-      return &(*content);
+ContentInfo* FindContentInfoByName(ContentInfos* contents,
+                                   const std::string& name) {
+  RTC_DCHECK(contents);
+  for (ContentInfo& content : *contents) {
+    if (content.name == name) {
+      return &content;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
-const ContentInfo* FindContentInfoByName(
-    const ContentInfos& contents, const std::string& name) {
+}  // namespace
+
+const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
+                                         const std::string& name) {
   for (ContentInfos::const_iterator content = contents.begin();
        content != contents.end(); ++content) {
     if (content->name == name) {
@@ -34,8 +37,8 @@
   return NULL;
 }
 
-const ContentInfo* FindContentInfoByType(
-    const ContentInfos& contents, const std::string& type) {
+const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
+                                         const std::string& type) {
   for (ContentInfos::const_iterator content = contents.begin();
        content != contents.end(); ++content) {
     if (content->type == type) {
@@ -70,8 +73,8 @@
 }
 
 bool ContentGroup::RemoveContentName(const std::string& content_name) {
-  ContentNames::iterator iter = std::find(
-      content_names_.begin(), content_names_.end(), content_name);
+  ContentNames::iterator iter =
+      std::find(content_names_.begin(), content_names_.end(), content_name);
   if (iter == content_names_.end()) {
     return false;
   }
@@ -108,7 +111,7 @@
   SessionDescription* copy = new SessionDescription(*this);
   // Copy all ContentDescriptions.
   for (ContentInfos::iterator content = copy->contents_.begin();
-      content != copy->contents().end(); ++content) {
+       content != copy->contents().end(); ++content) {
     content->description = content->description->Copy();
   }
   return copy;
@@ -119,9 +122,8 @@
   return FindContentInfoByName(contents_, name);
 }
 
-ContentInfo* SessionDescription::GetContentByName(
-    const std::string& name)  {
-  return FindContentInfoByName(contents_, name);
+ContentInfo* SessionDescription::GetContentByName(const std::string& name) {
+  return FindContentInfoByName(&contents_, name);
 }
 
 const ContentDescription* SessionDescription::GetContentDescriptionByName(
@@ -136,7 +138,7 @@
 
 ContentDescription* SessionDescription::GetContentDescriptionByName(
     const std::string& name) {
-  ContentInfo* cinfo = FindContentInfoByName(contents_, name);
+  ContentInfo* cinfo = FindContentInfoByName(&contents_, name);
   if (cinfo == NULL) {
     return NULL;
   }
diff --git a/pc/sessiondescription.h b/pc/sessiondescription.h
new file mode 100644
index 0000000..c959f2a
--- /dev/null
+++ b/pc/sessiondescription.h
@@ -0,0 +1,189 @@
+/*
+ *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef PC_SESSIONDESCRIPTION_H_
+#define PC_SESSIONDESCRIPTION_H_
+
+#include <string>
+#include <vector>
+
+#include "p2p/base/transportinfo.h"
+#include "rtc_base/constructormagic.h"
+
+namespace cricket {
+
+// Describes a session content. Individual content types inherit from
+// this class.  Analagous to a <jingle><content><description> or
+// <session><description>.
+class ContentDescription {
+ public:
+  virtual ~ContentDescription() {}
+  virtual ContentDescription* Copy() const = 0;
+};
+
+// Analagous to a <jingle><content> or <session><description>.
+// name = name of <content name="...">
+// type = xmlns of <content>
+struct ContentInfo {
+  ContentInfo() {}
+  ContentInfo(const std::string& name,
+              const std::string& type,
+              ContentDescription* description)
+      : name(name), type(type), description(description) {}
+  ContentInfo(const std::string& name,
+              const std::string& type,
+              bool rejected,
+              ContentDescription* description)
+      : name(name), type(type), rejected(rejected), description(description) {}
+  ContentInfo(const std::string& name,
+              const std::string& type,
+              bool rejected,
+              bool bundle_only,
+              ContentDescription* description)
+      : name(name),
+        type(type),
+        rejected(rejected),
+        bundle_only(bundle_only),
+        description(description) {}
+  std::string name;
+  std::string type;
+  bool rejected = false;
+  bool bundle_only = false;
+  ContentDescription* description = nullptr;
+};
+
+typedef std::vector<std::string> ContentNames;
+
+// This class provides a mechanism to aggregate different media contents into a
+// group. This group can also be shared with the peers in a pre-defined format.
+// GroupInfo should be populated only with the |content_name| of the
+// MediaDescription.
+class ContentGroup {
+ public:
+  explicit ContentGroup(const std::string& semantics);
+  ContentGroup(const ContentGroup&);
+  ContentGroup(ContentGroup&&);
+  ContentGroup& operator=(const ContentGroup&);
+  ContentGroup& operator=(ContentGroup&&);
+  ~ContentGroup();
+
+  const std::string& semantics() const { return semantics_; }
+  const ContentNames& content_names() const { return content_names_; }
+
+  const std::string* FirstContentName() const;
+  bool HasContentName(const std::string& content_name) const;
+  void AddContentName(const std::string& content_name);
+  bool RemoveContentName(const std::string& content_name);
+
+ private:
+  std::string semantics_;
+  ContentNames content_names_;
+};
+
+typedef std::vector<ContentInfo> ContentInfos;
+typedef std::vector<ContentGroup> ContentGroups;
+
+const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
+                                         const std::string& name);
+const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
+                                         const std::string& type);
+
+// Describes a collection of contents, each with its own name and
+// type.  Analogous to a <jingle> or <session> stanza.  Assumes that
+// contents are unique be name, but doesn't enforce that.
+class SessionDescription {
+ public:
+  SessionDescription();
+  explicit SessionDescription(const ContentInfos& contents);
+  SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
+  SessionDescription(const ContentInfos& contents,
+                     const TransportInfos& transports,
+                     const ContentGroups& groups);
+  ~SessionDescription();
+
+  SessionDescription* Copy() const;
+
+  // Content accessors.
+  const ContentInfos& contents() const { return contents_; }
+  ContentInfos& contents() { return contents_; }
+  const ContentInfo* GetContentByName(const std::string& name) const;
+  ContentInfo* GetContentByName(const std::string& name);
+  const ContentDescription* GetContentDescriptionByName(
+      const std::string& name) const;
+  ContentDescription* GetContentDescriptionByName(const std::string& name);
+  const ContentInfo* FirstContentByType(const std::string& type) const;
+  const ContentInfo* FirstContent() const;
+
+  // Content mutators.
+  // Adds a content to this description. Takes ownership of ContentDescription*.
+  void AddContent(const std::string& name,
+                  const std::string& type,
+                  ContentDescription* description);
+  void AddContent(const std::string& name,
+                  const std::string& type,
+                  bool rejected,
+                  ContentDescription* description);
+  void AddContent(const std::string& name,
+                  const std::string& type,
+                  bool rejected,
+                  bool bundle_only,
+                  ContentDescription* description);
+  bool RemoveContentByName(const std::string& name);
+
+  // Transport accessors.
+  const TransportInfos& transport_infos() const { return transport_infos_; }
+  TransportInfos& transport_infos() { return transport_infos_; }
+  const TransportInfo* GetTransportInfoByName(const std::string& name) const;
+  TransportInfo* GetTransportInfoByName(const std::string& name);
+  const TransportDescription* GetTransportDescriptionByName(
+      const std::string& name) const {
+    const TransportInfo* tinfo = GetTransportInfoByName(name);
+    return tinfo ? &tinfo->description : NULL;
+  }
+
+  // Transport mutators.
+  void set_transport_infos(const TransportInfos& transport_infos) {
+    transport_infos_ = transport_infos;
+  }
+  // Adds a TransportInfo to this description.
+  // Returns false if a TransportInfo with the same name already exists.
+  bool AddTransportInfo(const TransportInfo& transport_info);
+  bool RemoveTransportInfoByName(const std::string& name);
+
+  // Group accessors.
+  const ContentGroups& groups() const { return content_groups_; }
+  const ContentGroup* GetGroupByName(const std::string& name) const;
+  bool HasGroup(const std::string& name) const;
+
+  // Group mutators.
+  void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
+  // Remove the first group with the same semantics specified by |name|.
+  void RemoveGroupByName(const std::string& name);
+
+  // Global attributes.
+  void set_msid_supported(bool supported) { msid_supported_ = supported; }
+  bool msid_supported() const { return msid_supported_; }
+
+ private:
+  SessionDescription(const SessionDescription&);
+
+  ContentInfos contents_;
+  TransportInfos transport_infos_;
+  ContentGroups content_groups_;
+  bool msid_supported_ = true;
+};
+
+// Indicates whether a ContentDescription was sent by the local client
+// or received from the remote client.
+enum ContentSource { CS_LOCAL, CS_REMOTE };
+
+}  // namespace cricket
+
+#endif  // PC_SESSIONDESCRIPTION_H_
diff --git a/pc/srtpfilter.h b/pc/srtpfilter.h
index 1cfc122..e89a68a 100644
--- a/pc/srtpfilter.h
+++ b/pc/srtpfilter.h
@@ -19,7 +19,7 @@
 
 #include "api/cryptoparams.h"
 #include "api/optional.h"
-#include "p2p/base/sessiondescription.h"
+#include "pc/sessiondescription.h"
 #include "rtc_base/basictypes.h"
 #include "rtc_base/buffer.h"
 #include "rtc_base/constructormagic.h"