| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // TODO(jkrcal): Clarify what Fetch() should do for this provider and maybe stop | 44 // TODO(jkrcal): Clarify what Fetch() should do for this provider and maybe stop |
| 45 // intercepting it. | 45 // intercepting it. |
| 46 // TODO(jkrcal): Intercept also ReloadSuggestions() call (after the user swipes | 46 // TODO(jkrcal): Intercept also ReloadSuggestions() call (after the user swipes |
| 47 // away everything incl. all empty sections and presses "More"); Not done in the | 47 // away everything incl. all empty sections and presses "More"); Not done in the |
| 48 // first shot because it implements a public interface function without any | 48 // first shot because it implements a public interface function without any |
| 49 // callback. | 49 // callback. |
| 50 // This class is final because it does things in its constructor which make it | 50 // This class is final because it does things in its constructor which make it |
| 51 // unsafe to derive from it. | 51 // unsafe to derive from it. |
| 52 // TODO(jkrcal): Introduce two-phase initialization and make the class not | 52 // TODO(jkrcal): Introduce two-phase initialization and make the class not |
| 53 // final? (see the same comment for RemoteSuggestionsProvider) | 53 // final? (see the same comment for RemoteSuggestionsProvider) |
| 54 // TODO(jkrcal): Change the interface to ContentSuggestionsProvider. We do not |
| 55 // need any special functionality, all special should be exposed in the |
| 56 // Scheduler interface. crbug.com/695447 |
| 54 class SchedulingRemoteSuggestionsProvider final | 57 class SchedulingRemoteSuggestionsProvider final |
| 55 : public RemoteSuggestionsProvider, | 58 : public RemoteSuggestionsProvider, |
| 56 public RemoteSuggestionsScheduler { | 59 public RemoteSuggestionsScheduler { |
| 57 public: | 60 public: |
| 58 SchedulingRemoteSuggestionsProvider( | 61 SchedulingRemoteSuggestionsProvider( |
| 59 Observer* observer, | 62 Observer* observer, |
| 60 std::unique_ptr<RemoteSuggestionsProvider> provider, | 63 std::unique_ptr<RemoteSuggestionsProvider> provider, |
| 61 PersistentScheduler* persistent_scheduler, | 64 PersistentScheduler* persistent_scheduler, |
| 62 const UserClassifier* user_classifier, | 65 const UserClassifier* user_classifier, |
| 63 PrefService* pref_service, | 66 PrefService* pref_service, |
| 64 std::unique_ptr<base::Clock> clock); | 67 std::unique_ptr<base::Clock> clock); |
| 65 | 68 |
| 66 ~SchedulingRemoteSuggestionsProvider() override; | 69 ~SchedulingRemoteSuggestionsProvider() override; |
| 67 | 70 |
| 68 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 71 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 69 | 72 |
| 70 // RemoteSuggestionsScheduler implementation. | 73 // RemoteSuggestionsScheduler implementation. |
| 74 void OnProviderActivated() override; |
| 75 void OnProviderDeactivated() override; |
| 76 void OnSuggestionsCleared() override; |
| 77 void OnHistoryCleared() override; |
| 71 void RescheduleFetching() override; | 78 void RescheduleFetching() override; |
| 72 void OnPersistentSchedulerWakeUp() override; | 79 void OnPersistentSchedulerWakeUp() override; |
| 73 void OnBrowserForegrounded() override; | 80 void OnBrowserForegrounded() override; |
| 74 void OnBrowserColdStart() override; | 81 void OnBrowserColdStart() override; |
| 75 void OnNTPOpened() override; | 82 void OnNTPOpened() override; |
| 76 | 83 |
| 77 // RemoteSuggestionsProvider implementation. | 84 // RemoteSuggestionsProvider implementation. |
| 78 void SetProviderStatusCallback( | 85 void SetRemoteSuggestionsScheduler( |
| 79 std::unique_ptr<ProviderStatusCallback> callback) override; | 86 RemoteSuggestionsScheduler* scheduler) override; |
| 80 void RefetchInTheBackground( | 87 void RefetchInTheBackground( |
| 81 std::unique_ptr<FetchStatusCallback> callback) override; | 88 std::unique_ptr<FetchStatusCallback> callback) override; |
| 82 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() | 89 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() |
| 83 const override; | 90 const override; |
| 84 | 91 |
| 85 // ContentSuggestionsProvider implementation. | 92 // ContentSuggestionsProvider implementation. |
| 86 CategoryStatus GetCategoryStatus(Category category) override; | 93 CategoryStatus GetCategoryStatus(Category category) override; |
| 87 CategoryInfo GetCategoryInfo(Category category) override; | 94 CategoryInfo GetCategoryInfo(Category category) override; |
| 88 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; | 95 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; |
| 89 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, | 96 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 bool is_empty() const; | 119 bool is_empty() const; |
| 113 | 120 |
| 114 base::TimeDelta interval_persistent_wifi; | 121 base::TimeDelta interval_persistent_wifi; |
| 115 base::TimeDelta interval_persistent_fallback; | 122 base::TimeDelta interval_persistent_fallback; |
| 116 base::TimeDelta interval_soft_on_usage_event; | 123 base::TimeDelta interval_soft_on_usage_event; |
| 117 base::TimeDelta interval_soft_on_ntp_opened; | 124 base::TimeDelta interval_soft_on_ntp_opened; |
| 118 }; | 125 }; |
| 119 | 126 |
| 120 enum class TriggerType; | 127 enum class TriggerType; |
| 121 | 128 |
| 122 // Callback that is notified whenever the status of |provider_| changes. | |
| 123 void OnProviderStatusChanged( | |
| 124 RemoteSuggestionsProvider::ProviderStatus status); | |
| 125 | |
| 126 // After the call, updates will be scheduled in the future. Idempotent, can be | 129 // After the call, updates will be scheduled in the future. Idempotent, can be |
| 127 // run any time later without impacting the current schedule. | 130 // run any time later without impacting the current schedule. |
| 128 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). | 131 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). |
| 129 void StartScheduling(); | 132 void StartScheduling(); |
| 130 | 133 |
| 131 // After the call, no updates will happen before another call to Schedule(). | 134 // After the call, no updates will happen before another call to Schedule(). |
| 132 // Idempotent, can be run any time later without impacting the current | 135 // Idempotent, can be run any time later without impacting the current |
| 133 // schedule. | 136 // schedule. |
| 134 void StopScheduling(); | 137 void StopScheduling(); |
| 135 | 138 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 149 std::vector<ContentSuggestion> suggestions); | 152 std::vector<ContentSuggestion> suggestions); |
| 150 | 153 |
| 151 // Callback after RefetchInTheBackground is completed. | 154 // Callback after RefetchInTheBackground is completed. |
| 152 void RefetchInTheBackgroundFinished( | 155 void RefetchInTheBackgroundFinished( |
| 153 std::unique_ptr<FetchStatusCallback> callback, | 156 std::unique_ptr<FetchStatusCallback> callback, |
| 154 Status fetch_status); | 157 Status fetch_status); |
| 155 | 158 |
| 156 // Common function to call after a fetch of any type is finished. | 159 // Common function to call after a fetch of any type is finished. |
| 157 void OnFetchCompleted(Status fetch_status); | 160 void OnFetchCompleted(Status fetch_status); |
| 158 | 161 |
| 162 // Clears the time of the last fetch so that the provider is ready to make a |
| 163 // soft fetch at any later time (upon a trigger). |
| 164 void ClearLastFetchAttemptTime(); |
| 165 |
| 159 FetchingSchedule GetDesiredFetchingSchedule() const; | 166 FetchingSchedule GetDesiredFetchingSchedule() const; |
| 160 | 167 |
| 161 // Load and store |schedule_|. | 168 // Load and store |schedule_|. |
| 162 void LoadLastFetchingSchedule(); | 169 void LoadLastFetchingSchedule(); |
| 163 void StoreFetchingSchedule(); | 170 void StoreFetchingSchedule(); |
| 164 | 171 |
| 165 // Applies the persistent schedule given by |schedule_|. | 172 // Applies the persistent schedule given by |schedule_|. |
| 166 void ApplyPersistentFetchingSchedule(); | 173 void ApplyPersistentFetchingSchedule(); |
| 167 | 174 |
| 168 // Gets enabled trigger types from the variation parameter. | 175 // Gets enabled trigger types from the variation parameter. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 181 FetchingSchedule schedule_; | 188 FetchingSchedule schedule_; |
| 182 bool background_fetch_in_progress_; | 189 bool background_fetch_in_progress_; |
| 183 | 190 |
| 184 // Used to adapt the schedule based on usage activity of the user. Not owned. | 191 // Used to adapt the schedule based on usage activity of the user. Not owned. |
| 185 const UserClassifier* user_classifier_; | 192 const UserClassifier* user_classifier_; |
| 186 | 193 |
| 187 PrefService* pref_service_; | 194 PrefService* pref_service_; |
| 188 std::unique_ptr<base::Clock> clock_; | 195 std::unique_ptr<base::Clock> clock_; |
| 189 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; | 196 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; |
| 190 | 197 |
| 198 base::Time background_fetches_allowed_after_; |
| 199 |
| 191 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); | 200 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); |
| 192 }; | 201 }; |
| 193 | 202 |
| 194 } // namespace ntp_snippets | 203 } // namespace ntp_snippets |
| 195 | 204 |
| 196 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER
_H_ | 205 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER
_H_ |
| OLD | NEW |