Bug 1601561 - Move parser names to static functions. r=dminor a=jcristau
authorNico Grunbaum <na-g@nostrum.com>
Mon, 16 Dec 2019 14:07:13 +0000
changeset 566892 2cd74ee9acf07cc9f948cdc603180fb18550ccdd
parent 566891 57e9e3202fc62e7cd325937b484375af3e4a8b93
child 566893 d0ffcc2ff850b68c67e3355cc2458296a88fca1d
push id12452
push userdluca@mozilla.com
push dateThu, 19 Dec 2019 13:15:00 +0000
treeherdermozilla-beta@51983bf763d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor, jcristau
bugs1601561
milestone72.0
Bug 1601561 - Move parser names to static functions. r=dminor a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D57131
media/webrtc/signaling/src/sdp/HybridSdpParser.cpp
media/webrtc/signaling/src/sdp/HybridSdpParser.h
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.cpp
media/webrtc/signaling/src/sdp/RsdparsaSdpParser.h
media/webrtc/signaling/src/sdp/SipccSdpParser.cpp
media/webrtc/signaling/src/sdp/SipccSdpParser.h
--- a/media/webrtc/signaling/src/sdp/HybridSdpParser.cpp
+++ b/media/webrtc/signaling/src/sdp/HybridSdpParser.cpp
@@ -16,16 +16,21 @@
 #include "mozilla/Telemetry.h"
 
 #include <unordered_map>
 
 namespace mozilla {
 
 using mozilla::LogLevel;
 
+const std::string& HybridSdpParser::ParserName() {
+  const static std::string PARSER_NAME = "hybrid";
+  return PARSER_NAME;
+}
+
 HybridSdpParser::HybridSdpParser()
     : mPrimary(SdpPref::Primary()),
       mSecondary(SdpPref::Secondary()),
       mFailover(SdpPref::Failover()) {
   MOZ_ASSERT(!(mSecondary && mFailover),
              "Can not have both a secondary and failover parser!");
   MOZ_LOG(SdpLog, LogLevel::Info,
           ("Primary SDP Parser: %s", mPrimary->Name().c_str()));
@@ -67,11 +72,9 @@ auto HybridSdpParser::Parse(const std::s
       results = compare(std::move(failover->Parse(aText)));
     }
   });
 
   SdpTelemetry::RecordParse(results, mode, Role::Primary);
   return results;
 }
 
-const std::string HybridSdpParser::PARSER_NAME = "hybrid";
-
 }  // namespace mozilla
--- a/media/webrtc/signaling/src/sdp/HybridSdpParser.h
+++ b/media/webrtc/signaling/src/sdp/HybridSdpParser.h
@@ -11,26 +11,27 @@
 #include "signaling/src/sdp/SdpTelemetry.h"
 
 namespace mozilla {
 
 // This shim parser delegates parsing to WEbRTC-SDP and SIPCC, based on
 // preference flags. Additionally it handles collecting telemetry and fallback
 // behavior between the parsers.
 class HybridSdpParser : public SdpParser {
+  static const std::string& ParserName();
+
  public:
   HybridSdpParser();
   virtual ~HybridSdpParser() = default;
 
-  auto Name() const -> const std::string& override { return PARSER_NAME; }
+  auto Name() const -> const std::string& override { return ParserName(); }
   auto Parse(const std::string& aText)
       -> UniquePtr<SdpParser::Results> override;
 
  private:
   const UniquePtr<SdpParser> mPrimary;
   const Maybe<UniquePtr<SdpParser>> mSecondary;
   const Maybe<UniquePtr<SdpParser>> mFailover;
-  static const std::string PARSER_NAME;
 };
 
 }  // namespace mozilla
 
 #endif
\ No newline at end of file
--- a/media/webrtc/signaling/src/sdp/RsdparsaSdpParser.cpp
+++ b/media/webrtc/signaling/src/sdp/RsdparsaSdpParser.cpp
@@ -12,19 +12,20 @@
 #include "signaling/src/sdp/SdpEnum.h"
 #include "signaling/src/sdp/RsdparsaSdp.h"
 #include "signaling/src/sdp/RsdparsaSdpParser.h"
 #include "signaling/src/sdp/RsdparsaSdpInc.h"
 #include "signaling/src/sdp/RsdparsaSdpGlue.h"
 
 namespace mozilla {
 
-static const std::string& WEBRTC_SDP_NAME = "WEBRTCSDP";
-
-const std::string& RsdparsaSdpParser::Name() const { return WEBRTC_SDP_NAME; }
+const std::string& RsdparsaSdpParser::ParserName() {
+  static const std::string& WEBRTC_SDP_NAME = "WEBRTCSDP";
+  return WEBRTC_SDP_NAME;
+}
 
 UniquePtr<SdpParser::Results> RsdparsaSdpParser::Parse(
     const std::string& aText) {
   UniquePtr<SdpParser::InternalResults> results(
       new SdpParser::InternalResults(Name()));
   RustSdpSession* result = nullptr;
   RustSdpError* err = nullptr;
   StringView sdpTextView{aText.c_str(), aText.length()};
@@ -50,12 +51,12 @@ UniquePtr<SdpParser::Results> RsdparsaSd
   SdpOrigin origin(convertStringView(rustOrigin.username), rustOrigin.sessionId,
                    rustOrigin.sessionVersion, address.first, address.second);
 
   results->SetSdp(MakeUnique<RsdparsaSdp>(std::move(uniqueResult), origin));
   return results;
 }
 
 bool RsdparsaSdpParser::IsNamed(const std::string& aName) {
-  return aName == WEBRTC_SDP_NAME;
+  return aName == ParserName();
 }
 
 }  // namespace mozilla
--- a/media/webrtc/signaling/src/sdp/RsdparsaSdpParser.h
+++ b/media/webrtc/signaling/src/sdp/RsdparsaSdpParser.h
@@ -12,21 +12,23 @@
 #include "mozilla/UniquePtr.h"
 
 #include "signaling/src/sdp/Sdp.h"
 #include "signaling/src/sdp/SdpParser.h"
 
 namespace mozilla {
 
 class RsdparsaSdpParser final : public SdpParser {
+  static const std::string& ParserName();
+
  public:
   RsdparsaSdpParser() = default;
   virtual ~RsdparsaSdpParser() = default;
 
-  const std::string& Name() const override;
+  const std::string& Name() const override { return ParserName(); }
 
   UniquePtr<SdpParser::Results> Parse(const std::string& text) override;
 
   static bool IsNamed(const std::string& aName);
 };
 
 }  // namespace mozilla
 
--- a/media/webrtc/signaling/src/sdp/SipccSdpParser.cpp
+++ b/media/webrtc/signaling/src/sdp/SipccSdpParser.cpp
@@ -9,30 +9,31 @@
 
 #include <utility>
 extern "C" {
 #include "signaling/src/sdp/sipcc/sdp.h"
 }
 
 namespace mozilla {
 
-static const std::string SIPCC_NAME = "SIPCC";
-
 extern "C" {
 
 void sipcc_sdp_parser_results_handler(void* context, uint32_t line,
                                       const char* message) {
   auto* results = static_cast<UniquePtr<InternalResults>*>(context);
   std::string err(message);
   (*results)->AddParseError(line, err);
 }
 
 }  // extern "C"
 
-const std::string& SipccSdpParser::Name() const { return SIPCC_NAME; }
+const std::string& SipccSdpParser::ParserName() {
+  static const std::string SIPCC_NAME = "SIPCC";
+  return SIPCC_NAME;
+}
 
 UniquePtr<SdpParser::Results> SipccSdpParser::Parse(const std::string& aText) {
   UniquePtr<InternalResults> results(new InternalResults(Name()));
   sdp_conf_options_t* sipcc_config = sdp_init_config();
   if (!sipcc_config) {
     return UniquePtr<SdpParser::Results>();
   }
 
@@ -76,12 +77,12 @@ UniquePtr<SdpParser::Results> SipccSdpPa
   if (success) {
     results->SetSdp(UniquePtr<mozilla::Sdp>(std::move(sipccSdp)));
   }
 
   return results;
 }
 
 bool SipccSdpParser::IsNamed(const std::string& aName) {
-  return aName == SIPCC_NAME;
+  return aName == ParserName();
 }
 
 }  // namespace mozilla
--- a/media/webrtc/signaling/src/sdp/SipccSdpParser.h
+++ b/media/webrtc/signaling/src/sdp/SipccSdpParser.h
@@ -12,21 +12,23 @@
 #include "mozilla/UniquePtr.h"
 
 #include "signaling/src/sdp/Sdp.h"
 #include "signaling/src/sdp/SdpParser.h"
 
 namespace mozilla {
 
 class SipccSdpParser final : public SdpParser {
+  static const std::string& ParserName();
+
  public:
   SipccSdpParser() = default;
   virtual ~SipccSdpParser() = default;
 
-  const std::string& Name() const override;
+  const std::string& Name() const override { return ParserName(); }
 
   UniquePtr<SdpParser::Results> Parse(const std::string& aText) override;
 
   static bool IsNamed(const std::string& aName);
 };
 
 }  // namespace mozilla