Compiling headless_shell_switches.cc once should be enough

In Windows (multi dll) builds, headless_shell_switches.cc was
compiled twice and with some timings and linkers, that cause
a duplicate symbol link error. In other cases one set of symbols
was discarded as unused before the link errors.

This setup was probably triggered by several build target
(headless_renderer, headless_shell_browser_lib,
headless_shell_child_lib and more) being compiled as if they
were inside headless.dll in component builds. That prevented
them from actually accessing the switches inside headless.dll.

The fix is to only compile headless.dll ("component headless")
with HEADLESS_IMPLEMENTATION, which controls HEADLESS_EXPORT,
and to not have a duplicate copy of the switches in
headless_shell_browser_lib.

Bug: 919231
Change-Id: Id0d5cade84b47b9053474a26a1b14723c576d346
Reviewed-on: https://chromium-review.googlesource.com/c/1440141
Commit-Queue: Daniel Bratell <bratell@opera.com>
Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628335}
diff --git a/headless/BUILD.gn b/headless/BUILD.gn
index 7450e8c..01b8e67 100644
--- a/headless/BUILD.gn
+++ b/headless/BUILD.gn
@@ -18,12 +18,9 @@
 import("//tools/grit/repack.gni")
 import("//tools/v8_context_snapshot/v8_context_snapshot.gni")
 
-config("headless_implementation") {
+# For code inside the build component "headless".
+config("inside_headless_component") {
   defines = [ "HEADLESS_IMPLEMENTATION" ]
-
-  if (headless_use_embedded_resources) {
-    defines += [ "HEADLESS_USE_EMBEDDED_RESOURCES" ]
-  }
 }
 
 group("headless_lib") {
@@ -226,7 +223,7 @@
       "//third_party/fontconfig",
     ]
 
-    configs += [ ":headless_implementation" ]
+    configs += [ ":inside_headless_component" ]
   }
 }
 
@@ -476,6 +473,7 @@
   }
 
   if (headless_use_embedded_resources) {
+    defines = [ "HEADLESS_USE_EMBEDDED_RESOURCES" ]
     deps += [ ":embed_resources" ]
     sources += [
       "$root_gen_dir/headless/embedded_resource_pak.cc",
@@ -493,7 +491,7 @@
     deps += [ ":headless_fontconfig_utils" ]
   }
 
-  configs += [ ":headless_implementation" ]
+  configs += [ ":inside_headless_component" ]
 }
 
 # Headless renderer is a convenience library for non component builds that
@@ -527,8 +525,6 @@
     if (enable_basic_printing) {
       deps += [ "//components/printing/renderer" ]
     }
-
-    configs += [ ":headless_implementation" ]
   }
 } else {
   # For component builds all dependencies are already included in the headless
@@ -777,8 +773,6 @@
     sources = [
       "app/headless_shell.cc",
       "app/headless_shell.h",
-      "app/headless_shell_switches.cc",
-      "app/headless_shell_switches.h",
       "app/headless_shell_win.cc",
       "lib/browser/headless_content_browser_client.cc",
       "lib/browser/headless_content_browser_client.h",
@@ -811,8 +805,6 @@
         "//third_party/blink/public:blink_headers",
       ]
     }
-
-    configs += [ ":headless_implementation" ]
   }
 
   # Headless library with child specific dependencies (e.g., renderer). This
@@ -847,8 +839,6 @@
         "//third_party/blink/public:blink_headers",
       ]
     }
-
-    configs += [ ":headless_implementation" ]
   }
 }