OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/time/time.h" | |
10 | 9 |
11 namespace ntp_snippets { | 10 namespace ntp_snippets { |
12 | 11 |
13 // Class to take care of scheduling of periodic updates of snippets. There are | 12 // Interface for informing the scheduler of fetches of remote suggestions about |
Marc Treib
2016/12/19 12:59:23
nit: "scheduler of fetches of remote suggestions"
jkrcal
2016/12/20 16:39:46
Done.
| |
14 // two types of scheduled updates: | 13 // relevant external events. |
15 // - "hard" ones that should outlive current running instance of Chrome. These | |
16 // should get triggered according to their schedule even if Chrome is not | |
17 // running at the given moment. This is OS-dependent, may be unavilable on | |
18 // some platforms. | |
19 // - "soft" ones that get triggered only if Chrome stays running until the | |
20 // scheduled point. | |
21 class RemoteSuggestionsScheduler { | 14 class RemoteSuggestionsScheduler { |
22 public: | 15 public: |
23 // Interface to perform the scheduled update. | 16 // Fetch content suggestions. |
24 class Updater { | 17 virtual void OnFetchDue() = 0; |
tschumann
2016/12/19 11:07:19
This sounds a bit odd on this interface. The sched
jkrcal
2016/12/20 16:39:46
Done. Great suggestions, thanks!
| |
25 virtual void HardUpdate(); | |
26 virtual void SoftUpdate(); | |
27 }; | |
28 | 18 |
29 // The passed in |updater| is called when an update is due according to the | 19 // Force rescheduling of fetching. |
30 // schedule. Note that hard fetches get access to the |updater| via the keyed | 20 virtual void RescheduleFetching() = 0; |
31 // ContentSuggestionService because the concrete instance passed to | |
32 // RemoteSuggestionsScheduler when the hard fetch was scheduled may not exist | |
33 // any more when the hard update is due. | |
34 explicit RemoteSuggestionsScheduler(Updater* updater); | |
35 | |
36 // Schedules both "soft" and "hard" fetches. First removes existing schedule | |
37 // before scheduling new updates. | |
38 void Schedule(); | |
39 | |
40 // Removes any existing schedule. | |
41 void Unschedule(); | |
42 | |
43 // Schedule periodic fetching of snippets, with different periods depending on | |
44 // network state. Once per period, the concrete implementation should call | |
45 // RemoteSuggestionsUpdater::HardUpdate where RemoteSuggestionsUpdater is | |
46 // obtained from ContentSuggestionsService. | |
47 // Any of the periods can be zero to indicate that the corresponding task | |
48 // should not be scheduled. | |
49 virtual bool Schedule(base::TimeDelta period_wifi, | |
50 base::TimeDelta period_fallback) = 0; | |
51 | |
52 // Cancel any scheduled tasks. | |
53 virtual bool Unschedule() = 0; | |
54 | |
55 private: | |
56 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsHardScheduler); | |
57 }; | 21 }; |
Marc Treib
2016/12/19 12:59:23
DISALLOW_COPY_AND_ASSIGN?
jkrcal
2016/12/20 16:39:46
Is it needed? Are these default constructors creat
| |
58 | 22 |
59 } // namespace ntp_snippets | 23 } // namespace ntp_snippets |
60 | 24 |
61 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_HARD_SCHEDULER_H_ | 25 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_H_ |
OLD | NEW |