bind_to_task_runner.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2015 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. #ifndef COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_
  5. #define COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_
  6. #include <utility>
  7. #include "base/callback.h"
  8. #include "base/location.h"
  9. #include "base/task/bind_post_task.h"
  10. #include "base/threading/sequenced_task_runner_handle.h"
  11. // Helpers for using base::BindPostTask() with the TaskRunner for the current
  12. // sequence, ie. base::SequencedTaskRunnerHandle::Get().
  13. namespace syncer {
  14. template <typename T>
  15. base::OnceCallback<T> BindToCurrentSequence(
  16. base::OnceCallback<T> callback,
  17. const base::Location& location = FROM_HERE) {
  18. return base::BindPostTask(base::SequencedTaskRunnerHandle::Get(),
  19. std::move(callback), location);
  20. }
  21. template <typename T>
  22. base::RepeatingCallback<T> BindToCurrentSequence(
  23. base::RepeatingCallback<T> callback,
  24. const base::Location& location = FROM_HERE) {
  25. return base::BindPostTask(base::SequencedTaskRunnerHandle::Get(),
  26. std::move(callback), location);
  27. }
  28. } // namespace syncer
  29. #endif // COMPONENTS_SYNC_BASE_BIND_TO_TASK_RUNNER_H_