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_IMPL_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 void OnHistoryCleared() override; | 54 void OnHistoryCleared() override; |
55 void RescheduleFetching() override; | 55 void RescheduleFetching() override; |
56 bool AcquireQuotaForInteractiveFetch() override; | 56 bool AcquireQuotaForInteractiveFetch() override; |
57 void OnInteractiveFetchFinished(Status fetch_status) override; | 57 void OnInteractiveFetchFinished(Status fetch_status) override; |
58 void OnPersistentSchedulerWakeUp() override; | 58 void OnPersistentSchedulerWakeUp() override; |
59 void OnBrowserForegrounded() override; | 59 void OnBrowserForegrounded() override; |
60 void OnBrowserColdStart() override; | 60 void OnBrowserColdStart() override; |
61 void OnNTPOpened() override; | 61 void OnNTPOpened() override; |
62 | 62 |
63 private: | 63 private: |
64 // Abstract description of the fetching schedule. | 64 // Abstract description of the fetching schedule. See the enum |
| 65 // FetchingInterval for more documentation. |
65 struct FetchingSchedule { | 66 struct FetchingSchedule { |
66 static FetchingSchedule Empty(); | 67 static FetchingSchedule Empty(); |
67 bool operator==(const FetchingSchedule& other) const; | 68 bool operator==(const FetchingSchedule& other) const; |
68 bool operator!=(const FetchingSchedule& other) const; | 69 bool operator!=(const FetchingSchedule& other) const; |
69 bool is_empty() const; | 70 bool is_empty() const; |
70 | 71 |
71 base::TimeDelta interval_persistent_wifi; | 72 base::TimeDelta interval_persistent_wifi; |
72 base::TimeDelta interval_persistent_fallback; | 73 base::TimeDelta interval_persistent_fallback; |
73 base::TimeDelta interval_soft_on_usage_event; | 74 base::TimeDelta interval_soft_wifi; |
74 base::TimeDelta interval_soft_on_ntp_opened; | 75 base::TimeDelta interval_soft_fallback; |
75 }; | 76 }; |
76 | 77 |
77 enum class TriggerType; | 78 enum class TriggerType; |
78 | 79 |
79 // After the call, updates will be scheduled in the future. Idempotent, can be | 80 // After the call, updates will be scheduled in the future. Idempotent, can be |
80 // run any time later without impacting the current schedule. | 81 // run any time later without impacting the current schedule. |
81 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). | 82 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). |
82 void StartScheduling(); | 83 void StartScheduling(); |
83 | 84 |
84 // After the call, no updates will happen before another call to Schedule(). | 85 // After the call, no updates will happen before another call to Schedule(). |
85 // Idempotent, can be run any time later without impacting the current | 86 // Idempotent, can be run any time later without impacting the current |
86 // schedule. | 87 // schedule. |
87 void StopScheduling(); | 88 void StopScheduling(); |
88 | 89 |
89 // Trigger a background refetch for the given |trigger| if enabled. | 90 // Trigger a background refetch for the given |trigger| if enabled and if the |
90 void RefetchInTheBackgroundIfEnabled(TriggerType trigger); | 91 // timing is appropriate for another fetch. |
91 | 92 void RefetchInTheBackgroundIfAppropriate(TriggerType trigger); |
92 // Trigger the background refetch. | |
93 void RefetchInTheBackground(); | |
94 | 93 |
95 // Checks whether it is time to perform a soft background fetch, according to | 94 // Checks whether it is time to perform a soft background fetch, according to |
96 // |schedule|. | 95 // |schedule|. |
97 bool ShouldRefetchInTheBackgroundNow(TriggerType trigger); | 96 bool ShouldRefetchInTheBackgroundNow(); |
98 | 97 |
99 // Returns whether background fetching (for the given |trigger|) is disabled. | 98 // Returns whether background fetching (for the given |trigger|) is disabled. |
100 bool BackgroundFetchesDisabled(TriggerType trigger) const; | 99 bool BackgroundFetchesDisabled(TriggerType trigger) const; |
101 | 100 |
102 // Returns true if quota is available for another request. | 101 // Returns true if quota is available for another request. |
103 bool AcquireQuota(bool interactive_request); | 102 bool AcquireQuota(bool interactive_request); |
104 | 103 |
105 // Callback after RefetchInTheBackground is completed. | 104 // Callback after RefetchInTheBackground is completed. |
106 void RefetchInTheBackgroundFinished(Status fetch_status); | 105 void RefetchInTheBackgroundFinished(Status fetch_status); |
107 | 106 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 std::set<TriggerType> enabled_triggers_; | 152 std::set<TriggerType> enabled_triggers_; |
154 | 153 |
155 base::Time background_fetches_allowed_after_; | 154 base::Time background_fetches_allowed_after_; |
156 | 155 |
157 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsSchedulerImpl); | 156 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsSchedulerImpl); |
158 }; | 157 }; |
159 | 158 |
160 } // namespace ntp_snippets | 159 } // namespace ntp_snippets |
161 | 160 |
162 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_ | 161 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_ |
OLD | NEW |