[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/extensions/browser/extension_file_task_runner.cc b/extensions/browser/extension_file_task_runner.cc
new file mode 100644
index 0000000..95d51646
--- /dev/null
+++ b/extensions/browser/extension_file_task_runner.cc
@@ -0,0 +1,33 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/extension_file_task_runner.h"
+
+#include "base/sequenced_task_runner.h"
+#include "base/task_scheduler/lazy_task_runner.h"
+#include "base/task_scheduler/task_traits.h"
+
+namespace extensions {
+
+namespace {
+
+// Note: All tasks posted to a single task runner have the same priority. This
+// is unfortunate, since some file-related tasks are high priority (like serving
+// a file from the extension protocols or loading an extension in response to a
+// user action), and others are low priority (like garbage collection). Split
+// the difference and use USER_VISIBLE, which is the default priority and what a
+// task posted to a named thread (like the FILE thread) would receive.
+base::LazySequencedTaskRunner g_task_runner =
+    LAZY_SEQUENCED_TASK_RUNNER_INITIALIZER(
+        base::TaskTraits(base::MayBlock(),
+                         base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
+                         base::TaskPriority::USER_VISIBLE));
+
+}  // namespace
+
+scoped_refptr<base::SequencedTaskRunner> GetExtensionFileTaskRunner() {
+  return g_task_runner.Get();
+}
+
+}  // namespace extensions