background_task_scheduler.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2020 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_BACKGROUND_TASK_SCHEDULER_BACKGROUND_TASK_SCHEDULER_H_
  5. #define COMPONENTS_BACKGROUND_TASK_SCHEDULER_BACKGROUND_TASK_SCHEDULER_H_
  6. #include "base/callback.h"
  7. #include "components/background_task_scheduler/task_info.h"
  8. #include "components/keyed_service/core/keyed_service.h"
  9. namespace background_task {
  10. // A BackgroundTaskScheduler is used to schedule jobs that run in the
  11. // background. It is backed by system APIs which have different implementations
  12. // on different android versions. For more information, please refer
  13. // BackgroundTaskScheduler.java.
  14. class BackgroundTaskScheduler : public KeyedService {
  15. public:
  16. BackgroundTaskScheduler(const BackgroundTaskScheduler&) = delete;
  17. BackgroundTaskScheduler& operator=(const BackgroundTaskScheduler&) = delete;
  18. // Schedules a background task with various scheduling related params
  19. // contained in |task_info|.
  20. virtual bool Schedule(const TaskInfo& task_info) = 0;
  21. // Cancels the task specified by the |task_id}.
  22. virtual void Cancel(int task_id) = 0;
  23. protected:
  24. BackgroundTaskScheduler() = default;
  25. ~BackgroundTaskScheduler() override = default;
  26. };
  27. } // namespace background_task
  28. #endif // COMPONENTS_BACKGROUND_TASK_SCHEDULER_BACKGROUND_TASK_SCHEDULER_H_