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

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

Issue 2714863004: [Remote suggestions] Move the throttler into the Scheduler (Closed)
Patch Set: 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>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/ntp_snippets/content_suggestions_provider.h" 16 #include "components/ntp_snippets/content_suggestions_provider.h"
17 #include "components/ntp_snippets/remote/persistent_scheduler.h" 17 #include "components/ntp_snippets/remote/persistent_scheduler.h"
18 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 18 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
19 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" 19 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
20 #include "components/ntp_snippets/remote/request_throttler.h"
20 21
21 class PrefRegistrySimple; 22 class PrefRegistrySimple;
22 class PrefService; 23 class PrefService;
23 24
24 namespace base { 25 namespace base {
25 class Clock; 26 class Clock;
26 } 27 }
27 28
28 namespace ntp_snippets { 29 namespace ntp_snippets {
29 30
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Trigger a background refetch for the given |trigger| if enabled. 140 // Trigger a background refetch for the given |trigger| if enabled.
140 void RefetchInTheBackgroundIfEnabled(TriggerType trigger); 141 void RefetchInTheBackgroundIfEnabled(TriggerType trigger);
141 142
142 // Checks whether it is time to perform a soft background fetch, according to 143 // Checks whether it is time to perform a soft background fetch, according to
143 // |schedule|. 144 // |schedule|.
144 bool ShouldRefetchInTheBackgroundNow(TriggerType trigger); 145 bool ShouldRefetchInTheBackgroundNow(TriggerType trigger);
145 146
146 // Returns whether background fetching (for the given |trigger|) is disabled. 147 // Returns whether background fetching (for the given |trigger|) is disabled.
147 bool BackgroundFetchesDisabled(TriggerType trigger) const; 148 bool BackgroundFetchesDisabled(TriggerType trigger) const;
148 149
150 // Returns true if quota is available for another request.
151 bool DemandQuotaForRequest(bool interactive_request);
tschumann 2017/02/24 10:18:08 nit: would AcquireQuota() be a better name? We hav
jkrcal 2017/02/27 10:26:23 Done.
152
149 // Callback after Fetch is completed. 153 // Callback after Fetch is completed.
150 void FetchFinished(const FetchDoneCallback& callback, 154 void FetchFinished(const FetchDoneCallback& callback,
151 Status fetch_status, 155 Status fetch_status,
152 std::vector<ContentSuggestion> suggestions); 156 std::vector<ContentSuggestion> suggestions);
153 157
154 // Callback after RefetchInTheBackground is completed. 158 // Callback after RefetchInTheBackground is completed.
155 void RefetchInTheBackgroundFinished( 159 void RefetchInTheBackgroundFinished(
156 std::unique_ptr<FetchStatusCallback> callback, 160 std::unique_ptr<FetchStatusCallback> callback,
Marc Treib 2017/02/24 15:50:35 Unrelated to this CL, but: Why are we passing arou
jkrcal 2017/02/27 10:26:23 This is a known issue. Added a TODO with a bug lin
157 Status fetch_status); 161 Status fetch_status);
158 162
159 // Common function to call after a fetch of any type is finished. 163 // Common function to call after a fetch of any type is finished.
160 void OnFetchCompleted(Status fetch_status); 164 void OnFetchCompleted(Status fetch_status);
161 165
162 // Clears the time of the last fetch so that the provider is ready to make a 166 // 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). 167 // soft fetch at any later time (upon a trigger).
164 void ClearLastFetchAttemptTime(); 168 void ClearLastFetchAttemptTime();
165 169
166 FetchingSchedule GetDesiredFetchingSchedule() const; 170 FetchingSchedule GetDesiredFetchingSchedule() const;
(...skipping 17 matching lines...) Expand all
184 // Interface for scheduling hard fetches, OS dependent. Not owned, may be 188 // Interface for scheduling hard fetches, OS dependent. Not owned, may be
185 // null. 189 // null.
186 PersistentScheduler* persistent_scheduler_; 190 PersistentScheduler* persistent_scheduler_;
187 191
188 FetchingSchedule schedule_; 192 FetchingSchedule schedule_;
189 bool background_fetch_in_progress_; 193 bool background_fetch_in_progress_;
190 194
191 // Used to adapt the schedule based on usage activity of the user. Not owned. 195 // Used to adapt the schedule based on usage activity of the user. Not owned.
192 const UserClassifier* user_classifier_; 196 const UserClassifier* user_classifier_;
193 197
198 // Request throttlers for limiting requests for different classes of users.
199 RequestThrottler request_throttler_rare_ntp_user_;
200 RequestThrottler request_throttler_active_ntp_user_;
201 RequestThrottler request_throttler_active_suggestions_consumer_;
202
194 PrefService* pref_service_; 203 PrefService* pref_service_;
195 std::unique_ptr<base::Clock> clock_; 204 std::unique_ptr<base::Clock> clock_;
196 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; 205 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_;
197 206
198 base::Time background_fetches_allowed_after_; 207 base::Time background_fetches_allowed_after_;
199 208
200 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); 209 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider);
201 }; 210 };
202 211
203 } // namespace ntp_snippets 212 } // namespace ntp_snippets
204 213
205 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_ 214 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698