Bug 1601561 - Move parser names to static functions.;r=dminor
authorNico Grunbaum <na-g@nostrum.com>
Mon, 16 Dec 2019 14:07:13 +0000
changeset 507518 b194872cda4bd211588e244ac908fdf9b66f2d83
parent 507517 d9ffe1b95b07d18481ef7078c8f7e1fad3aa4039
child 507519 e928d60013446484acd63757ac883626b722f85d
push id103494
push userrvandermeulen@mozilla.com
push dateWed, 18 Dec 2019 03:02:06 +0000
treeherderautoland@b194872cda4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1601561
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1601561 - Move parser names to static functions.;r=dminor 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()
     : mStrictSuccess(SdpPref::StrictSuccess()),
       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,
@@ -75,11 +80,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,27 +11,28 @@
 #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 bool mStrictSuccess;
   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()};
@@ -62,12 +63,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