From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Chris Cunningham <chcunningham@chromium.org>
Date: Fri, 1 Jan 2021 05:39:43 +0000
Subject: MediaCapabilities: Use threadsafe static wtf::String

This replaces DEFINE_THREAD_SAFE_STATIC_LOCAL(const String, ...).
StringImpl ref counting (behind that macro) is not currently threadsafe.

Bug: 1160534
Change-Id: I70f4aa796aaefabbee36db4fcdf0fbf0defe4959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606399
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Auto-Submit: Chrome Cunningham <chcunningham@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839863}

diff --git a/third_party/blink/renderer/modules/BUILD.gn b/third_party/blink/renderer/modules/BUILD.gn
index 694ff382d40c3759e3cfe3a852f5b2829d43aed7..ec77ab05748046f4e828ed85cf944d8d25509cc9 100644
--- a/third_party/blink/renderer/modules/BUILD.gn
+++ b/third_party/blink/renderer/modules/BUILD.gn
@@ -21,12 +21,18 @@ config("modules_implementation") {
   defines = [ "BLINK_MODULES_IMPLEMENTATION=1" ]
 }
 
-make_names("module_names") {
+make_names("indexed_db_names") {
   in_files = [ "indexeddb/indexed_db_names.json5" ]
   output_dir = blink_modules_output_dir
   deps = []  # Don't use default deps (otherwise it will be circular).
 }
 
+make_names("media_capabilities_names") {
+  in_files = [ "media_capabilities/media_capabilities_names.json5" ]
+  output_dir = blink_modules_output_dir
+  deps = []  # Don't use default deps (otherwise it will be circular).
+}
+
 component("modules") {
   output_name = "blink_modules"
 
@@ -42,8 +48,9 @@ component("modules") {
     "modules_initializer.h",
   ]
 
-  # Compile sources generated by module_names script.
-  sources += get_target_outputs(":module_names")
+  # Compile sources generated by make_names script.
+  sources += get_target_outputs(":indexed_db_names")
+  sources += get_target_outputs(":media_capabilities_names")
 
   sources += bindings_modules_v8_files
 
@@ -173,8 +180,9 @@ component("modules") {
   }
 
   deps = [
+    ":indexed_db_names",
     ":make_modules_generated",
-    ":module_names",
+    ":media_capabilities_names",
     "//jingle:webrtc_glue",
     "//net:net",
     "//third_party/blink/renderer/bindings/modules:generated",
@@ -256,7 +264,8 @@ source_set("modules_testing") {
 
 group("make_modules_generated") {
   public_deps = [
-    ":module_names",
+    ":indexed_db_names",
+    ":media_capabilities_names",
     "//third_party/blink/renderer/bindings/modules:bindings_modules_generated",
     "//third_party/blink/renderer/bindings/modules/v8:generated",
     "//third_party/blink/renderer/core:core_event_interfaces",
diff --git a/third_party/blink/renderer/modules/media_capabilities/DEPS b/third_party/blink/renderer/modules/media_capabilities/DEPS
index 3b8d2749b4f486c4b0b207d4e20f966b5e573e07..1a5a3e9e3b6a031c4752cd92cf87426cae72f1d2 100644
--- a/third_party/blink/renderer/modules/media_capabilities/DEPS
+++ b/third_party/blink/renderer/modules/media_capabilities/DEPS
@@ -12,6 +12,7 @@ include_rules = [
     "-third_party/blink/renderer/modules",
     "+third_party/blink/renderer/modules/encryptedmedia",
     "+third_party/blink/renderer/modules/media_capabilities",
+    "+third_party/blink/renderer/modules/media_capabilities_names.h",
     "+third_party/blink/renderer/modules/mediarecorder/media_recorder_handler.h",
     "+third_party/blink/renderer/modules/modules_export.h",
 ]
diff --git a/third_party/blink/renderer/modules/media_capabilities/media_capabilities.cc b/third_party/blink/renderer/modules/media_capabilities/media_capabilities.cc
index 9b833e9c6368a3390d17c01f32edffe6f7d65895..ccb4bd082149ec7232cba64a02bfe139a047863c 100644
--- a/third_party/blink/renderer/modules/media_capabilities/media_capabilities.cc
+++ b/third_party/blink/renderer/modules/media_capabilities/media_capabilities.cc
@@ -54,6 +54,7 @@
 #include "third_party/blink/renderer/modules/encryptedmedia/media_key_system_access_initializer_base.h"
 #include "third_party/blink/renderer/modules/encryptedmedia/media_keys_controller.h"
 #include "third_party/blink/renderer/modules/media_capabilities/media_capabilities_identifiability_metrics.h"
+#include "third_party/blink/renderer/modules/media_capabilities_names.h"
 #include "third_party/blink/renderer/modules/mediarecorder/media_recorder_handler.h"
 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
 #include "third_party/blink/renderer/platform/bindings/script_state.h"
@@ -309,9 +310,9 @@ WebAudioConfiguration ToWebAudioConfiguration(
   DCHECK(parsed_content_type.IsValid());
   DCHECK(!parsed_content_type.GetParameters().HasDuplicatedNames());
 
-  DEFINE_THREAD_SAFE_STATIC_LOCAL(const String, codecs, ("codecs"));
   web_configuration.mime_type = parsed_content_type.MimeType().LowerASCII();
-  web_configuration.codec = parsed_content_type.ParameterValueForName(codecs);
+  web_configuration.codec = parsed_content_type.ParameterValueForName(
+      media_capabilities_names::kCodecs);
 
   // |channels| is optional and will be set to a null WebString if not present.
   web_configuration.channels = configuration->hasChannels()
@@ -337,9 +338,9 @@ WebVideoConfiguration ToWebVideoConfiguration(
   DCHECK(parsed_content_type.IsValid());
   DCHECK(!parsed_content_type.GetParameters().HasDuplicatedNames());
 
-  DEFINE_THREAD_SAFE_STATIC_LOCAL(const String, codecs, ("codecs"));
   web_configuration.mime_type = parsed_content_type.MimeType().LowerASCII();
-  web_configuration.codec = parsed_content_type.ParameterValueForName(codecs);
+  web_configuration.codec = parsed_content_type.ParameterValueForName(
+      media_capabilities_names::kCodecs);
 
   DCHECK(configuration->hasWidth());
   web_configuration.width = configuration->width();
@@ -599,9 +600,9 @@ bool ParseContentType(const String& content_type,
     return false;
   }
 
-  DEFINE_THREAD_SAFE_STATIC_LOCAL(const String, codecs, ("codecs"));
   *mime_type = parsed_content_type.MimeType().LowerASCII();
-  *codec = parsed_content_type.ParameterValueForName(codecs);
+  *codec = parsed_content_type.ParameterValueForName(
+      media_capabilities_names::kCodecs);
   return true;
 }
 
diff --git a/third_party/blink/renderer/modules/media_capabilities/media_capabilities_names.json5 b/third_party/blink/renderer/modules/media_capabilities/media_capabilities_names.json5
new file mode 100644
index 0000000000000000000000000000000000000000..01f9a0f705da3fad7708cccbd22c9a8c1789ff0c
--- /dev/null
+++ b/third_party/blink/renderer/modules/media_capabilities/media_capabilities_names.json5
@@ -0,0 +1,9 @@
+{
+  metadata: {
+    namespace: "media_capabilities_names",
+  },
+
+  data: [
+    "codecs",
+  ],
+}
diff --git a/third_party/blink/renderer/modules/modules_initializer.cc b/third_party/blink/renderer/modules/modules_initializer.cc
index e1cfdcbddb11a752d392bb97b1e25e56e8416a77..1b15f6e760c85125dbc05af37ed6eee683718d9a 100644
--- a/third_party/blink/renderer/modules/modules_initializer.cc
+++ b/third_party/blink/renderer/modules/modules_initializer.cc
@@ -63,6 +63,7 @@
 #include "third_party/blink/renderer/modules/launch/web_launch_service_impl.h"
 #include "third_party/blink/renderer/modules/manifest/manifest_manager.h"
 #include "third_party/blink/renderer/modules/media/audio/audio_renderer_sink_cache.h"
+#include "third_party/blink/renderer/modules/media_capabilities_names.h"
 #include "third_party/blink/renderer/modules/media_controls/media_controls_impl.h"
 #include "third_party/blink/renderer/modules/mediasource/media_source_registry_impl.h"
 #include "third_party/blink/renderer/modules/mediastream/user_media_client.h"
@@ -119,6 +120,7 @@ void ModulesInitializer::Initialize() {
   Document::RegisterEventFactory(EventModulesFactory::Create());
   ModuleBindingsInitializer::Init();
   indexed_db_names::Init();
+  media_capabilities_names::Init();
   AXObjectCache::Init(AXObjectCacheImpl::Create);
   DraggedIsolatedFileSystem::Init(
       DraggedIsolatedFileSystemImpl::PrepareForDataObject);
