extension_file_task_runner.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "extensions/browser/extension_file_task_runner.h"
  5. #include "base/task/lazy_thread_pool_task_runner.h"
  6. #include "base/task/sequenced_task_runner.h"
  7. #include "base/task/task_traits.h"
  8. #include "base/task/thread_pool.h"
  9. namespace extensions {
  10. namespace {
  11. // Note: All tasks posted to a single task runner have the same priority. This
  12. // is unfortunate, since some file-related tasks are high priority (like serving
  13. // a file from the extension protocols or loading an extension in response to a
  14. // user action), and others are low priority (like garbage collection). Split
  15. // the difference and use USER_VISIBLE, which is the default priority and what a
  16. // task posted to a named thread (like the FILE thread) would receive.
  17. base::LazyThreadPoolSequencedTaskRunner g_task_runner =
  18. LAZY_THREAD_POOL_SEQUENCED_TASK_RUNNER_INITIALIZER(
  19. base::TaskTraits(base::MayBlock(),
  20. base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
  21. base::TaskPriority::USER_VISIBLE));
  22. } // namespace
  23. scoped_refptr<base::SequencedTaskRunner> GetExtensionFileTaskRunner() {
  24. return g_task_runner.Get();
  25. }
  26. scoped_refptr<base::SequencedTaskRunner> GetOneShotFileTaskRunner(
  27. base::TaskPriority priority) {
  28. return base::ThreadPool::CreateSequencedTaskRunner(
  29. {base::MayBlock(), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN,
  30. priority});
  31. }
  32. } // namespace extensions