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

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

Issue 2774663002: [Remote suggestions] Refactor the scheduler (Closed)
Patch Set: Marc's nits #2 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h
diff --git a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h b/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h
similarity index 52%
rename from components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
rename to components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h
index 780fe8651ed70560930c09ea09ab29d934efc88c..a8baaf05af2ae032d04fa97c0a631eba480b3437 100644
--- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.h
+++ b/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_
-#define COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_
+#ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_
+#define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_
#include <memory>
#include <set>
@@ -12,10 +12,10 @@
#include <vector>
#include "base/macros.h"
+#include "base/time/clock.h"
#include "base/time/time.h"
#include "components/ntp_snippets/content_suggestions_provider.h"
#include "components/ntp_snippets/remote/persistent_scheduler.h"
-#include "components/ntp_snippets/remote/remote_suggestions_provider.h"
#include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
#include "components/ntp_snippets/remote/request_throttler.h"
#include "components/web_resource/eula_accepted_notifier.h"
@@ -33,85 +33,33 @@ struct Status;
class EulaState;
class UserClassifier;
-// A wrapper around RemoteSuggestionsProvider that introduces periodic fetching.
-//
-// The class initiates fetches on its own in these situations:
-// - initial fetch when the provider is constructed and we have no suggestions;
-// - regular fetches according to its schedule.
-// TODO(jkrcal): After soft fetch on Chrome startup is introduced, remove
-// the initial fetch completely.
-//
-// The class also needs to understand when last fetch trials and successful
-// fetches happen and thus it intercepts following interactive fetch requests:
-// - Fetch() - after "More" button of a remote section is pressed in the UI;
-// TODO(jkrcal): Clarify what Fetch() should do for this provider and maybe stop
-// intercepting it.
-// TODO(jkrcal): Intercept also ReloadSuggestions() call (after the user swipes
-// away everything incl. all empty sections and presses "More"); Not done in the
-// first shot because it implements a public interface function without any
-// callback.
-// This class is final because it does things in its constructor which make it
-// unsafe to derive from it.
-// TODO(jkrcal): Introduce two-phase initialization and make the class not
-// final? (see the same comment for RemoteSuggestionsProvider)
-// TODO(jkrcal): Change the interface to ContentSuggestionsProvider. We do not
-// need any special functionality, all special should be exposed in the
-// Scheduler interface. crbug.com/695447
-class SchedulingRemoteSuggestionsProvider final
- : public RemoteSuggestionsProvider,
- public RemoteSuggestionsScheduler {
+// A client of RemoteSuggestionsProvider that introduces periodic fetching.
+class RemoteSuggestionsSchedulerImpl : public RemoteSuggestionsScheduler {
public:
- SchedulingRemoteSuggestionsProvider(
- Observer* observer,
- std::unique_ptr<RemoteSuggestionsProvider> provider,
- PersistentScheduler* persistent_scheduler,
- const UserClassifier* user_classifier,
- PrefService* profile_prefs,
- PrefService* local_state_prefs,
- std::unique_ptr<base::Clock> clock);
+ RemoteSuggestionsSchedulerImpl(PersistentScheduler* persistent_scheduler,
+ const UserClassifier* user_classifier,
+ PrefService* profile_prefs,
+ PrefService* local_state_prefs,
+ std::unique_ptr<base::Clock> clock);
- ~SchedulingRemoteSuggestionsProvider() override;
+ ~RemoteSuggestionsSchedulerImpl();
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// RemoteSuggestionsScheduler implementation.
+ void SetProvider(RemoteSuggestionsProvider* provider) override;
void OnProviderActivated() override;
void OnProviderDeactivated() override;
void OnSuggestionsCleared() override;
void OnHistoryCleared() override;
void RescheduleFetching() override;
+ bool AcquireQuotaForInteractiveFetch() override;
+ void OnInteractiveFetchFinished(Status fetch_status) override;
void OnPersistentSchedulerWakeUp() override;
void OnBrowserForegrounded() override;
void OnBrowserColdStart() override;
void OnNTPOpened() override;
- // RemoteSuggestionsProvider implementation.
- void RefetchInTheBackground(
- std::unique_ptr<FetchStatusCallback> callback) override;
- const RemoteSuggestionsFetcher* suggestions_fetcher_for_debugging()
- const override;
-
- // ContentSuggestionsProvider implementation.
- CategoryStatus GetCategoryStatus(Category category) override;
- CategoryInfo GetCategoryInfo(Category category) override;
- void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
- void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
- const ImageFetchedCallback& callback) override;
- void Fetch(const Category& category,
- const std::set<std::string>& known_suggestion_ids,
- const FetchDoneCallback& callback) override;
- void ReloadSuggestions() override;
- void ClearHistory(
- base::Time begin,
- base::Time end,
- const base::Callback<bool(const GURL& url)>& filter) override;
- void ClearCachedSuggestions(Category category) override;
- void OnSignInStateChanged() override;
- void GetDismissedSuggestionsForDebugging(
- Category category,
- const DismissedSuggestionsCallback& callback) override;
- void ClearDismissedSuggestionsForDebugging(Category category) override;
-
private:
// Abstract description of the fetching schedule.
struct FetchingSchedule {
@@ -141,6 +89,9 @@ class SchedulingRemoteSuggestionsProvider final
// Trigger a background refetch for the given |trigger| if enabled.
void RefetchInTheBackgroundIfEnabled(TriggerType trigger);
+ // Trigger the background refetch.
+ void RefetchInTheBackground();
+
// Checks whether it is time to perform a soft background fetch, according to
// |schedule|.
bool ShouldRefetchInTheBackgroundNow(TriggerType trigger);
@@ -151,15 +102,8 @@ class SchedulingRemoteSuggestionsProvider final
// Returns true if quota is available for another request.
bool AcquireQuota(bool interactive_request);
- // Callback after Fetch is completed.
- void FetchFinished(const FetchDoneCallback& callback,
- Status fetch_status,
- std::vector<ContentSuggestion> suggestions);
-
// Callback after RefetchInTheBackground is completed.
- void RefetchInTheBackgroundFinished(
- std::unique_ptr<FetchStatusCallback> callback,
- Status fetch_status);
+ void RefetchInTheBackgroundFinished(Status fetch_status);
// Common function to call after a fetch of any type is finished.
void OnFetchCompleted(Status fetch_status);
@@ -183,13 +127,13 @@ class SchedulingRemoteSuggestionsProvider final
// Gets trigger types enabled by default.
std::set<TriggerType> GetDefaultEnabledTriggerTypes();
- // Interface for doing all the actual work (apart from scheduling).
- std::unique_ptr<RemoteSuggestionsProvider> provider_;
-
// Interface for scheduling hard fetches, OS dependent. Not owned, may be
// null.
PersistentScheduler* persistent_scheduler_;
+ // Interface for doing all the actual work (apart from scheduling). Not owned.
+ RemoteSuggestionsProvider* provider_;
+
FetchingSchedule schedule_;
bool background_fetch_in_progress_;
@@ -206,13 +150,13 @@ class SchedulingRemoteSuggestionsProvider final
PrefService* profile_prefs_;
std::unique_ptr<base::Clock> clock_;
- std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_;
+ std::set<TriggerType> enabled_triggers_;
base::Time background_fetches_allowed_after_;
- DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider);
+ DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsSchedulerImpl);
};
} // namespace ntp_snippets
-#endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_
+#endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_SCHEDULER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698