From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeremy Rose <jeremya@chromium.org>
Date: Mon, 2 Aug 2021 15:56:56 -0700
Subject: only create a console if logging to stderr

This fixes an issue on Windows where, when `--enable-logging=file` is
passed and the app was not run from the console, a console window would
be created for each child process, despite logs being redirected to a
file.

diff --git a/content/app/content_main.cc b/content/app/content_main.cc
index f2b1cdff827eae3726febe590f2f30b5f6d89046..dcce405488dd4c61c218a6b6c356d5932de99fb2 100644
--- a/content/app/content_main.cc
+++ b/content/app/content_main.cc
@@ -337,16 +337,14 @@ NO_STACK_PROTECTOR int RunContentProcess(
 
 #if BUILDFLAG(IS_WIN)
     base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
-    if (command_line->HasSwitch(switches::kHeadless)) {
-      // When running in headless mode we want stdio routed however if
-      // console does not exist we should not create one.
-      base::RouteStdioToConsole(/*create_console_if_not_found*/ false);
-    } else if (command_line->HasSwitch(switches::kEnableLogging)) {
-      // Route stdio to parent console (if any) or create one, do not create a
-      // console in children if handles are being passed.
-      bool create_console = command_line->GetSwitchValueASCII(
-                                switches::kEnableLogging) != "handle";
-      base::RouteStdioToConsole(create_console);
+    // Route stdio to parent console (if any) or create one.
+    bool const log_to_stderr =
+        command_line->HasSwitch(switches::kEnableLogging) &&
+        command_line->GetSwitchValueASCII(switches::kEnableLogging) != "file" &&
+        !command_line->HasSwitch(switches::kLogFile) &&
+        command_line->GetSwitchValueASCII(switches::kEnableLogging) != "handle";
+    if (log_to_stderr) {
+      base::RouteStdioToConsole(true);
     }
 #endif
 
