persistent_scheduler.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2016 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_NTP_SNIPPETS_REMOTE_PERSISTENT_SCHEDULER_H_
  5. #define COMPONENTS_NTP_SNIPPETS_REMOTE_PERSISTENT_SCHEDULER_H_
  6. #include "base/time/time.h"
  7. namespace ntp_snippets {
  8. // Interface to schedule persistent periodic fetches for remote suggestions, OS-
  9. // dependent. These persistent fetches must get triggered according to their
  10. // schedule independent of whether Chrome is running at that moment.
  11. //
  12. // Once per period, the concrete implementation should call
  13. // RemoteSuggestionsScheduler::OnPersistentSchedulerWakeUp() where the scheduler
  14. // object is obtained from ContentSuggestionsService.
  15. class PersistentScheduler {
  16. public:
  17. PersistentScheduler(const PersistentScheduler&) = delete;
  18. PersistentScheduler& operator=(const PersistentScheduler&) = delete;
  19. // Schedule periodic fetching of remote suggestions, with different periods
  20. // depending on network state. Any of the periods can be zero to indicate that
  21. // the corresponding task should not be scheduled. Returns whether the
  22. // scheduling was successful.
  23. virtual bool Schedule(base::TimeDelta period_wifi,
  24. base::TimeDelta period_fallback) = 0;
  25. // Cancel any scheduled tasks. Equivalent to Schedule(0, 0). Returns whether
  26. // the scheduling was successful.
  27. virtual bool Unschedule() = 0;
  28. // TODO(jkrcal): Get this information exposed in the platform-independent
  29. // net::NetworkChangeNotifier and remove this function.
  30. virtual bool IsOnUnmeteredConnection() = 0;
  31. protected:
  32. PersistentScheduler() = default;
  33. };
  34. } // namespace ntp_snippets
  35. #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_PERSISTENT_SCHEDULER_H_