task_info.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_TASK_INFO_H_
  5. #define COMPONENTS_BACKGROUND_TASK_SCHEDULER_TASK_INFO_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "components/background_task_scheduler/task_ids.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace background_task {
  11. // Specifies information regarding periodic tasks.
  12. struct PeriodicInfo {
  13. PeriodicInfo();
  14. ~PeriodicInfo();
  15. int64_t interval_ms;
  16. int64_t flex_ms;
  17. bool expires_after_window_end_time;
  18. };
  19. // Specifies information regarding one-off tasks.
  20. struct OneOffInfo {
  21. OneOffInfo();
  22. ~OneOffInfo();
  23. int64_t window_start_time_ms;
  24. int64_t window_end_time_ms;
  25. bool expires_after_window_end_time;
  26. };
  27. // Specifies information regarding exact tasks.
  28. struct ExactInfo {
  29. ExactInfo();
  30. ~ExactInfo();
  31. int64_t trigger_at_ms;
  32. };
  33. // TaskInfo represents a request to run a specific BackgroundTask given
  34. // the required parameters, such as whether a special type of network is
  35. // available.
  36. struct TaskInfo {
  37. TaskInfo(int task_id, const PeriodicInfo& timing_info);
  38. TaskInfo(int task_id, const OneOffInfo& timing_info);
  39. // TODO(crbug.com/1190755): Either remove this or make sure it's compatible
  40. // with Android S.
  41. // Warning: This functionality might get removed, check with OWNERS before
  42. // using this in new code: //components/background_task_scheduler/OWNERS.
  43. TaskInfo(int task_id, const ExactInfo& timing_info);
  44. TaskInfo(const TaskInfo&) = delete;
  45. TaskInfo& operator=(const TaskInfo&) = delete;
  46. ~TaskInfo();
  47. // A Java counterpart will be generated for this enum.
  48. // GENERATED_JAVA_ENUM_PACKAGE: (
  49. // org.chromium.components.background_task_scheduler)
  50. enum NetworkType {
  51. // This task has no requirements for network connectivity. Default.
  52. NONE = 0,
  53. // This task requires network connectivity.
  54. ANY = 1,
  55. // This task requires network connectivity that is unmetered.
  56. UNMETERED = 2,
  57. };
  58. int task_id;
  59. NetworkType network_type;
  60. bool requires_charging;
  61. bool is_persisted;
  62. bool update_current;
  63. std::string extras;
  64. absl::optional<PeriodicInfo> periodic_info;
  65. absl::optional<OneOffInfo> one_off_info;
  66. absl::optional<ExactInfo> exact_info;
  67. };
  68. } // namespace background_task
  69. #endif // COMPONENTS_BACKGROUND_TASK_SCHEDULER_TASK_INFO_H_