Run font_service in-browser

Instead of running font_service in the utility service, move it back to running
in-browser, as process creation and memory usage overhead seems too high.

Bug: 862553
Change-Id: I42333d07e0e79be55bd5491d9a4ef5d4dd28c874
Reviewed-on: https://chromium-review.googlesource.com/1133002
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Ken Rockot <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Commit-Queue: Dominik Röttsches <[email protected]>
Cr-Commit-Position: refs/heads/master@{#575234}
diff --git a/content/app/strings/content_strings.grd b/content/app/strings/content_strings.grd
index 935715d..e08494f 100644
--- a/content/app/strings/content_strings.grd
+++ b/content/app/strings/content_strings.grd
@@ -792,12 +792,6 @@
         Year
       </message>
 
-      <if expr="is_linux">
-        <message name="IDS_FONT_SERVICE_PROCESS_TITLE" desc="The user-visible process title displayed for the font_service process used by Chrome on Linux.">
-          Linux Font Service
-        </message>
-      </if>
-
       <message name="IDS_FORM_INPUT_WEEK_TEMPLATE" desc="A specific week (1-53) in a specific year shown in a form control">
         Week <ph name="WEEKNUMBER">$2<ex>51</ex></ph>, <ph name="YEAR">$1<ex>2012</ex></ph>
       </message>
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index 2eb15ee..dbe98ed 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -1800,6 +1800,7 @@
 
   if (is_linux) {
     deps += [
+      "//components/services/font:lib",
       "//components/services/font/public/interfaces",
       "//services/service_manager/zygote",
     ]
diff --git a/content/browser/DEPS b/content/browser/DEPS
index a892dea..288e1043 100644
--- a/content/browser/DEPS
+++ b/content/browser/DEPS
@@ -7,6 +7,7 @@
   "+components/download/public/common",
   "+components/download/quarantine/quarantine.h",
   "+components/filename_generation",
+  "+components/services/font",
   "+components/services/filesystem",
   "+components/services/font/ppapi_fontconfig_matching.h",
   "+components/services/leveldb",
diff --git a/content/browser/service_manager/service_manager_context.cc b/content/browser/service_manager/service_manager_context.cc
index ae0aed0..35dba772 100644
--- a/content/browser/service_manager/service_manager_context.cc
+++ b/content/browser/service_manager/service_manager_context.cc
@@ -96,6 +96,7 @@
 #endif
 
 #if defined(OS_LINUX)
+#include "components/services/font/font_service_app.h"
 #include "components/services/font/public/interfaces/constants.mojom.h"
 #endif
 
@@ -609,16 +610,16 @@
       base::BindRepeating(&base::ASCIIToUTF16, "Data Decoder Service");
 
 #if defined(OS_LINUX)
-  out_of_process_services[font_service::mojom::kServiceName] =
-      base::BindRepeating([] {
-        auto title = GetContentClient()->GetLocalizedString(
-            IDS_FONT_SERVICE_PROCESS_TITLE);
-        if (!title.empty())
-          return title;
-
-        // Default to a non-localized string if we have to.
-        return base::ASCIIToUTF16("Linux Font Service");
-      });
+  {
+    service_manager::EmbeddedServiceInfo font_service_info;
+    font_service_info.factory =
+        base::BindRepeating(font_service::FontServiceApp::CreateService);
+    font_service_info.task_runner = base::CreateSequencedTaskRunnerWithTraits(
+        base::TaskTraits({base::MayBlock(), base::WithBaseSyncPrimitives(),
+                          base::TaskPriority::USER_BLOCKING}));
+    packaged_services_connection_->AddEmbeddedService(
+        font_service::mojom::kServiceName, font_service_info);
+  }
 #endif
 
   bool network_service_enabled =
diff --git a/content/utility/BUILD.gn b/content/utility/BUILD.gn
index c47ee99f..610106e 100644
--- a/content/utility/BUILD.gn
+++ b/content/utility/BUILD.gn
@@ -68,10 +68,6 @@
       "//media/mojo/services",
     ]
   }
-
-  if (is_linux) {
-    deps += [ "//components/services/font:lib" ]
-  }
 }
 
 # See comment at the top of //content/BUILD.gn for how this works.
diff --git a/content/utility/DEPS b/content/utility/DEPS
index 1a3894d..51f92f3 100644
--- a/content/utility/DEPS
+++ b/content/utility/DEPS
@@ -1,5 +1,4 @@
 include_rules = [
-  "+components/services/font",
   "+content/child",
   "+content/public/utility",
   "+services/audio",
diff --git a/content/utility/utility_service_factory.cc b/content/utility/utility_service_factory.cc
index 2d0a82de..4d2eb95 100644
--- a/content/utility/utility_service_factory.cc
+++ b/content/utility/utility_service_factory.cc
@@ -45,11 +45,6 @@
 #endif  // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
 #endif
 
-#if defined(OS_LINUX)
-#include "components/services/font/font_service_app.h"  // nogncheck
-#include "components/services/font/public/interfaces/constants.mojom.h"  // nogncheck
-#endif
-
 #if defined(OS_WIN)
 #include "sandbox/win/src/sandbox.h"
 
@@ -175,14 +170,6 @@
     services->insert(
         std::make_pair(content::mojom::kNetworkServiceName, network_info));
   }
-
-#if defined(OS_LINUX)
-  service_manager::EmbeddedServiceInfo font_service_info;
-  font_service_info.factory =
-      base::BindRepeating(&font_service::FontServiceApp::CreateService);
-  services->insert(
-      std::make_pair(font_service::mojom::kServiceName, font_service_info));
-#endif
 }
 
 void UtilityServiceFactory::OnServiceQuit() {