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_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 static FetchingSchedule Empty(); | 109 static FetchingSchedule Empty(); |
110 bool operator==(const FetchingSchedule& other) const; | 110 bool operator==(const FetchingSchedule& other) const; |
111 bool operator!=(const FetchingSchedule& other) const; | 111 bool operator!=(const FetchingSchedule& other) const; |
112 bool is_empty() const; | 112 bool is_empty() const; |
113 | 113 |
114 base::TimeDelta interval_persistent_wifi; | 114 base::TimeDelta interval_persistent_wifi; |
115 base::TimeDelta interval_persistent_fallback; | 115 base::TimeDelta interval_persistent_fallback; |
116 base::TimeDelta interval_soft_on_usage_event; | 116 base::TimeDelta interval_soft_on_usage_event; |
117 }; | 117 }; |
118 | 118 |
| 119 enum class TriggerType; |
| 120 |
119 // Callback that is notified whenever the status of |provider_| changes. | 121 // Callback that is notified whenever the status of |provider_| changes. |
120 void OnProviderStatusChanged( | 122 void OnProviderStatusChanged( |
121 RemoteSuggestionsProvider::ProviderStatus status); | 123 RemoteSuggestionsProvider::ProviderStatus status); |
122 | 124 |
123 // After the call, updates will be scheduled in the future. Idempotent, can be | 125 // After the call, updates will be scheduled in the future. Idempotent, can be |
124 // run any time later without impacting the current schedule. | 126 // run any time later without impacting the current schedule. |
125 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). | 127 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). |
126 void StartScheduling(); | 128 void StartScheduling(); |
127 | 129 |
128 // After the call, no updates will happen before another call to Schedule(). | 130 // After the call, no updates will happen before another call to Schedule(). |
129 // Idempotent, can be run any time later without impacting the current | 131 // Idempotent, can be run any time later without impacting the current |
130 // schedule. | 132 // schedule. |
131 void StopScheduling(); | 133 void StopScheduling(); |
132 | 134 |
| 135 // Trigger a background refetch for the given |trigger| if enabled. |
| 136 void RefetchInTheBackgroundIfEnabled(TriggerType trigger); |
| 137 |
133 // Checks whether it is time to perform a soft background fetch, according to | 138 // Checks whether it is time to perform a soft background fetch, according to |
134 // |schedule|. | 139 // |schedule|. |
135 bool ShouldRefetchInTheBackgroundNow(); | 140 bool ShouldRefetchInTheBackgroundNow(); |
136 | 141 |
| 142 // Returns whether background fetching (for the given |trigger|) is disabled. |
| 143 bool BackgroundFetchesDisabled(TriggerType trigger) const; |
| 144 |
137 // Callback after Fetch is completed. | 145 // Callback after Fetch is completed. |
138 void FetchFinished(const FetchDoneCallback& callback, | 146 void FetchFinished(const FetchDoneCallback& callback, |
139 Status fetch_status, | 147 Status fetch_status, |
140 std::vector<ContentSuggestion> suggestions); | 148 std::vector<ContentSuggestion> suggestions); |
141 | 149 |
142 // Callback after RefetchInTheBackground is completed. | 150 // Callback after RefetchInTheBackground is completed. |
143 void RefetchInTheBackgroundFinished( | 151 void RefetchInTheBackgroundFinished( |
144 std::unique_ptr<FetchStatusCallback> callback, | 152 std::unique_ptr<FetchStatusCallback> callback, |
145 Status fetch_status); | 153 Status fetch_status); |
146 | 154 |
147 // Common function to call after a fetch of any type is finished. | 155 // Common function to call after a fetch of any type is finished. |
148 void OnFetchCompleted(Status fetch_status); | 156 void OnFetchCompleted(Status fetch_status); |
149 | 157 |
150 FetchingSchedule GetDesiredFetchingSchedule() const; | 158 FetchingSchedule GetDesiredFetchingSchedule() const; |
151 | 159 |
152 // Load and store |schedule_|. | 160 // Load and store |schedule_|. |
153 void LoadLastFetchingSchedule(); | 161 void LoadLastFetchingSchedule(); |
154 void StoreFetchingSchedule(); | 162 void StoreFetchingSchedule(); |
155 bool BackgroundFetchesDisabled() const; | |
156 | 163 |
157 // Applies the persistent schedule given by |schedule_|. | 164 // Applies the persistent schedule given by |schedule_|. |
158 void ApplyPersistentFetchingSchedule(); | 165 void ApplyPersistentFetchingSchedule(); |
159 | 166 |
| 167 // Gets enabled trigger types from the variation parameter. |
| 168 std::set<TriggerType> GetEnabledTriggerTypes(); |
| 169 |
| 170 // Gets trigger types enabled by default. |
| 171 std::set<TriggerType> GetDefaultEnabledTriggerTypes(); |
| 172 |
160 // Interface for doing all the actual work (apart from scheduling). | 173 // Interface for doing all the actual work (apart from scheduling). |
161 std::unique_ptr<RemoteSuggestionsProvider> provider_; | 174 std::unique_ptr<RemoteSuggestionsProvider> provider_; |
162 | 175 |
163 // Interface for scheduling hard fetches, OS dependent. Not owned, may be | 176 // Interface for scheduling hard fetches, OS dependent. Not owned, may be |
164 // null. | 177 // null. |
165 PersistentScheduler* persistent_scheduler_; | 178 PersistentScheduler* persistent_scheduler_; |
166 | 179 |
167 FetchingSchedule schedule_; | 180 FetchingSchedule schedule_; |
168 bool background_fetch_in_progress_; | 181 bool background_fetch_in_progress_; |
169 | 182 |
170 // Used to adapt the schedule based on usage activity of the user. Not owned. | 183 // Used to adapt the schedule based on usage activity of the user. Not owned. |
171 const UserClassifier* user_classifier_; | 184 const UserClassifier* user_classifier_; |
172 | 185 |
173 PrefService* pref_service_; | 186 PrefService* pref_service_; |
174 std::unique_ptr<base::Clock> clock_; | 187 std::unique_ptr<base::Clock> clock_; |
| 188 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; |
175 | 189 |
176 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); | 190 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); |
177 }; | 191 }; |
178 | 192 |
179 } // namespace ntp_snippets | 193 } // namespace ntp_snippets |
180 | 194 |
181 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER
_H_ | 195 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER
_H_ |
OLD | NEW |