[Task Migration][Extensions] Add and use a devoted file task runner

With the new task scheduling system, there are no guarantees that
different operations will not collide - each caller has to ensure that
no conflicting tasks will be scheduled and executed synchronously. This
means that for file tasks, we need to have a common task runner for any
tasks that may touch the same files.

Introduce a common SequencedTaskRunner for the extension system, and use
it in the UserScriptLoader.  Additionally, use it in ExtensionService,
in lieu of the prior ExtensionService-owned task runner that's used for
file tasks in installation.  Finally, also make the GetFileTaskRunner()
method in ExtensionService non-virtual, since it's not needed on any of
the interfaces.

Bug: 689520
Bug: 750122
Change-Id: I9d0b993689821e7aca9b2553283609cce796a162
Reviewed-on: https://chromium-review.googlesource.com/593854
Reviewed-by: Istiaque Ahmed <[email protected]>
Commit-Queue: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#491209}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 51d3227..95ca0f3 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -74,6 +74,7 @@
 #include "content/public/browser/storage_partition.h"
 #include "extensions/browser/app_sorting.h"
 #include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_file_task_runner.h"
 #include "extensions/browser/extension_host.h"
 #include "extensions/browser/extension_registry.h"
 #include "extensions/browser/extension_system.h"
@@ -329,13 +330,6 @@
       install_directory_(install_directory),
       extensions_enabled_(extensions_enabled),
       ready_(ready),
-      // We should be able to interrupt any part of extension install process
-      // during shutdown. SKIP_ON_SHUTDOWN ensures that not extension install
-      // task will be stopped while it is running but that tasks that have not
-      // started running will be skipped on shutdown.
-      file_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
-          {base::MayBlock(), base::TaskPriority::BACKGROUND,
-           base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})),
       shared_module_service_(new extensions::SharedModuleService(profile_)),
       renderer_helper_(
           extensions::RendererStartupHelperFactory::GetForBrowserContext(
@@ -1208,10 +1202,6 @@
   return ready_->is_signaled();
 }
 
-base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
-  return file_task_runner_.get();
-}
-
 void ExtensionService::CheckManagementPolicy() {
   std::vector<std::string> to_unload;
   std::map<std::string, Extension::DisableReason> to_disable;
@@ -2518,6 +2508,12 @@
   }
 }
 
+base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() {
+  // TODO(devlin): Update callers to use GetExtensionFileTaskRunner()
+  // directly.
+  return extensions::GetExtensionFileTaskRunner().get();
+}
+
 // Used only by test code.
 void ExtensionService::UnloadAllExtensionsInternal() {
   profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();