Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h

Issue 2702223004: [Remote suggestions] Move all decisions to fetch to the scheduler (Closed)
Patch Set: Fixing an embarassing bug :) Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
79 std::unique_ptr<ProviderStatusCallback> callback) override;
80 void RefetchInTheBackground( 85 void RefetchInTheBackground(
81 std::unique_ptr<FetchStatusCallback> callback) override; 86 std::unique_ptr<FetchStatusCallback> callback) override;
82 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging() 87 const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging()
83 const override; 88 const override;
84 89
85 // ContentSuggestionsProvider implementation. 90 // ContentSuggestionsProvider implementation.
86 CategoryStatus GetCategoryStatus(Category category) override; 91 CategoryStatus GetCategoryStatus(Category category) override;
87 CategoryInfo GetCategoryInfo(Category category) override; 92 CategoryInfo GetCategoryInfo(Category category) override;
88 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 93 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
89 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 94 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
(...skipping 22 matching lines...) Expand all
112 bool is_empty() const; 117 bool is_empty() const;
113 118
114 base::TimeDelta interval_persistent_wifi; 119 base::TimeDelta interval_persistent_wifi;
115 base::TimeDelta interval_persistent_fallback; 120 base::TimeDelta interval_persistent_fallback;
116 base::TimeDelta interval_soft_on_usage_event; 121 base::TimeDelta interval_soft_on_usage_event;
117 base::TimeDelta interval_soft_on_ntp_opened; 122 base::TimeDelta interval_soft_on_ntp_opened;
118 }; 123 };
119 124
120 enum class TriggerType; 125 enum class TriggerType;
121 126
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 127 // After the call, updates will be scheduled in the future. Idempotent, can be
127 // run any time later without impacting the current schedule. 128 // run any time later without impacting the current schedule.
128 // If you want to enforce rescheduling, call Unschedule() and then Schedule(). 129 // If you want to enforce rescheduling, call Unschedule() and then Schedule().
129 void StartScheduling(); 130 void StartScheduling();
130 131
131 // After the call, no updates will happen before another call to Schedule(). 132 // After the call, no updates will happen before another call to Schedule().
132 // Idempotent, can be run any time later without impacting the current 133 // Idempotent, can be run any time later without impacting the current
133 // schedule. 134 // schedule.
134 void StopScheduling(); 135 void StopScheduling();
135 136
(...skipping 13 matching lines...) Expand all
149 std::vector<ContentSuggestion> suggestions); 150 std::vector<ContentSuggestion> suggestions);
150 151
151 // Callback after RefetchInTheBackground is completed. 152 // Callback after RefetchInTheBackground is completed.
152 void RefetchInTheBackgroundFinished( 153 void RefetchInTheBackgroundFinished(
153 std::unique_ptr<FetchStatusCallback> callback, 154 std::unique_ptr<FetchStatusCallback> callback,
154 Status fetch_status); 155 Status fetch_status);
155 156
156 // Common function to call after a fetch of any type is finished. 157 // Common function to call after a fetch of any type is finished.
157 void OnFetchCompleted(Status fetch_status); 158 void OnFetchCompleted(Status fetch_status);
158 159
160 // Clears the time of the last fetch so that the provider is ready to make a
161 // soft fetch at any later time (upon a trigger).
162 void ClearLastFetchAttemptTime();
163
159 FetchingSchedule GetDesiredFetchingSchedule() const; 164 FetchingSchedule GetDesiredFetchingSchedule() const;
160 165
161 // Load and store |schedule_|. 166 // Load and store |schedule_|.
162 void LoadLastFetchingSchedule(); 167 void LoadLastFetchingSchedule();
163 void StoreFetchingSchedule(); 168 void StoreFetchingSchedule();
164 169
165 // Applies the persistent schedule given by |schedule_|. 170 // Applies the persistent schedule given by |schedule_|.
166 void ApplyPersistentFetchingSchedule(); 171 void ApplyPersistentFetchingSchedule();
167 172
168 // Gets enabled trigger types from the variation parameter. 173 // Gets enabled trigger types from the variation parameter.
(...skipping 12 matching lines...) Expand all
181 FetchingSchedule schedule_; 186 FetchingSchedule schedule_;
182 bool background_fetch_in_progress_; 187 bool background_fetch_in_progress_;
183 188
184 // Used to adapt the schedule based on usage activity of the user. Not owned. 189 // Used to adapt the schedule based on usage activity of the user. Not owned.
185 const UserClassifier* user_classifier_; 190 const UserClassifier* user_classifier_;
186 191
187 PrefService* pref_service_; 192 PrefService* pref_service_;
188 std::unique_ptr<base::Clock> clock_; 193 std::unique_ptr<base::Clock> clock_;
189 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; 194 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_;
190 195
196 base::Time background_fetches_allowed_after_;
197
191 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); 198 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider);
192 }; 199 };
193 200
194 } // namespace ntp_snippets 201 } // namespace ntp_snippets
195 202
196 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_ 203 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698