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

Unified Diff: components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h

Issue 2611523004: [Background fetching] Background fetching when opening an NTP. (Closed)
Patch Set: Rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
diff --git a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
index 71dd4f8c487c1db86a7047cb25e4d82576a603d7..787071848afd6f131c6fd20f64d6fa788025bd51 100644
--- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
+++ b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
@@ -8,6 +8,7 @@
#include <memory>
#include <set>
#include <string>
+#include <utility>
#include <vector>
#include "base/macros.h"
@@ -20,6 +21,10 @@
class PrefRegistrySimple;
class PrefService;
+namespace base {
+class Clock;
+}
+
namespace ntp_snippets {
struct Status;
@@ -55,7 +60,8 @@ class SchedulingRemoteSuggestionsProvider final
std::unique_ptr<RemoteSuggestionsProvider> provider,
PersistentScheduler* persistent_scheduler,
const UserClassifier* user_classifier,
- PrefService* pref_service);
+ PrefService* pref_service,
+ std::unique_ptr<base::Clock> clock);
~SchedulingRemoteSuggestionsProvider() override;
@@ -98,7 +104,16 @@ class SchedulingRemoteSuggestionsProvider final
private:
// Abstract description of the fetching schedule.
- struct FetchingSchedule;
+ struct FetchingSchedule {
+ static FetchingSchedule Empty();
+ bool operator==(const FetchingSchedule& other) const;
+ bool operator!=(const FetchingSchedule& other) const;
+ bool is_empty() const;
+
+ base::TimeDelta interval_persistent_wifi;
+ base::TimeDelta interval_persistent_fallback;
+ base::TimeDelta interval_soft_on_usage_event;
+ };
// Callback that is notified whenever the status of |provider_| changes.
void OnProviderStatusChanged(
@@ -114,20 +129,32 @@ class SchedulingRemoteSuggestionsProvider final
// schedule.
void StopScheduling();
+ // Checks whether it is time to perform a soft background fetch, according to
+ // |schedule|.
+ bool ShouldRefetchInTheBackgroundNow();
+
// Callback after Fetch is completed.
void FetchFinished(const FetchDoneCallback& callback,
- Status status_code,
+ Status fetch_status,
std::vector<ContentSuggestion> suggestions);
+ // Callback after RefetchInTheBackground is completed.
+ void RefetchInTheBackgroundFinished(
+ std::unique_ptr<FetchStatusCallback> callback,
+ Status fetch_status);
+
+ // Common function to call after a fetch of any type is finished.
+ void OnFetchCompleted(Status fetch_status);
+
FetchingSchedule GetDesiredFetchingSchedule() const;
- FetchingSchedule GetLastFetchingSchedule() const;
- void StoreLastFetchingSchedule(const FetchingSchedule& schedule);
- // Common function to call after each fetch.
- void OnFetchCompleted(Status status);
+ // Load and store |schedule_|.
+ void LoadLastFetchingSchedule();
+ void StoreFetchingSchedule();
+ bool BackgroundFetchesDisabled() const;
- // Applies the provided |schedule|.
- void ApplyFetchingSchedule(const FetchingSchedule& schedule);
+ // Applies the persistent schedule given by |schedule_|.
+ void ApplyPersistentFetchingSchedule();
// Interface for doing all the actual work (apart from scheduling).
std::unique_ptr<RemoteSuggestionsProvider> provider_;
@@ -136,10 +163,14 @@ class SchedulingRemoteSuggestionsProvider final
// null.
PersistentScheduler* persistent_scheduler_;
+ FetchingSchedule schedule_;
+ bool background_fetch_in_progress_;
+
// Used to adapt the schedule based on usage activity of the user. Not owned.
const UserClassifier* user_classifier_;
PrefService* pref_service_;
+ std::unique_ptr<base::Clock> clock_;
DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider);
};
« no previous file with comments | « components/ntp_snippets/pref_names.cc ('k') | components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698