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