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

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

Issue 2557363002: [NTP Snippets] Refactor background scheduling for remote suggestions (Closed)
Patch Set: Tim's comments and splitting RemoteSuggestionsProvider and RemoteSuggestionsProviderImpl Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER_H_
7
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/macros.h"
14 #include "base/time/time.h"
15 #include "components/ntp_snippets/content_suggestions_provider.h"
16 #include "components/ntp_snippets/remote/persistent_scheduler.h"
17 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
18 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
19
20 class PrefRegistrySimple;
21 class PrefService;
22
23 namespace ntp_snippets {
24
25 struct Status;
26 class UserClassifier;
27
28 // A wrapper around RemoteSuggestionsProvider that introduces periodic fetching.
29 //
30 // The class initiates fetches on its own in these situations:
31 // - initial fetch when the provider is constructed and we have no suggestions;
32 // - regular fetches according to its schedule (when notified via
tschumann 2016/12/19 11:07:19 i'd drop the part in parenthesis. It's an implemen
jkrcal 2016/12/20 16:39:47 Done.
33 // PersistentScheduler::Listener::OnFetchDue).
34 // TODO(jkrcal): After soft fetch on Chrome startup is introduced, remove
35 // the initial fetch completely.
36 //
37 // The class also needs to understand when last fetch trials and successful
38 // fetches happen and thus it intercepts following interactive fetch requests:
39 // - Fetch() - after "More" button of a remote section is pressed in the UI;
40 // TODO(jkrcal): Clarify what Fetch() should do for this provider and maybe stop
41 // intercepting it.
42 // TODO(jkrcal): Intercept also ReloadSuggestions() call (after the user swipes
43 // away everything incl. all empty sections and presses "More"); Not done in the
44 // first shot because it implements a public interface function without any
45 // callback.
46 // This class is final because it does things in its constructor which make it
47 // unsafe to derive from it.
48 // TODO(jkrcal): Introduce two-phase initialization and make the class not
49 // final? (see the same comment for RemoteSuggestionsProvider)
50 class SchedulingRemoteSuggestionsProvider final
51 : public ContentSuggestionsProvider,
52 public RemoteSuggestionsScheduler {
53 public:
54 // The passed in |updater| is called when an update is due according to the
Marc Treib 2016/12/19 12:59:24 There's no |updater|
jkrcal 2016/12/20 16:39:47 Done.
55 // schedule. Note that hard fetches get access to the |updater| via the keyed
56 // ContentSuggestionService because the concrete instance passed to
57 // RemoteSuggestionsScheduler when the hard fetch was scheduled may not exist
58 // any more when the hard update is due.
59 SchedulingRemoteSuggestionsProvider(
60 Observer* observer,
61 CategoryFactory* category_factory,
62 std::unique_ptr<RemoteSuggestionsProvider> provider,
63 PersistentScheduler* persistent_scheduler,
64 const UserClassifier* user_classifier,
65 PrefService* pref_service);
66
67 ~SchedulingRemoteSuggestionsProvider() override;
68
69 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
70
71 // RemoteSuggestionsScheduler implementation
tschumann 2016/12/19 11:07:19 nit: Comments should end with a period.
jkrcal 2016/12/20 16:39:47 Done.
72 void RescheduleFetching() override;
73 void OnFetchDue() override;
74
75 // ContentSuggestionsProvider implementation.
76 CategoryStatus GetCategoryStatus(Category category) override;
77 CategoryInfo GetCategoryInfo(Category category) override;
78 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
79 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
80 const ImageFetchedCallback& callback) override;
81 void Fetch(const Category& category,
82 const std::set<std::string>& known_suggestion_ids,
83 const FetchDoneCallback& callback) override;
84 void ReloadSuggestions() override;
85 void ClearHistory(
86 base::Time begin,
87 base::Time end,
88 const base::Callback<bool(const GURL& url)>& filter) override;
89 void ClearCachedSuggestions(Category category) override;
90 void OnSignInStateChanged() override;
91 void GetDismissedSuggestionsForDebugging(
92 Category category,
93 const DismissedSuggestionsCallback& callback) override;
94 void ClearDismissedSuggestionsForDebugging(Category category) override;
95
96 private:
97 // Abstract description of the fetching schedule.
98 struct FetchingSchedule;
99
100 void OnProviderStatusChanged(
Marc Treib 2016/12/19 12:59:24 Comment?
jkrcal 2016/12/20 16:39:47 Done.
101 RemoteSuggestionsProvider::ProviderStatus status);
102
103 // One of the following two functions must be called on startup of Chrome for
104 // the scheduler to work correctly.
105 // After the call, updates will be scheduled in the future. Idempotent, can be
106 // run any time later without impacting the current schedule.
107 // If you want to enforce rescheduling, call Unschedule() and then Schedule().
108 void StartScheduling();
109
110 // After the call, no updates will happen before another call to Schedule().
111 // Idempotent, can be run any time later without impacting the current
112 // schedule.
113 void StopScheduling();
114
115 // Callback after Fetch is completed.
116 void FetchFinished(const FetchDoneCallback& callback,
117 Status status_code,
118 std::vector<ContentSuggestion> suggestions);
119
120 FetchingSchedule GetDesiredFetchingSchedule();
Marc Treib 2016/12/19 12:59:24 Can this be const?
121 FetchingSchedule GetLastFetchingSchedule() const;
122 void StoreLastFetchingSchedule(const FetchingSchedule& schedule);
123
124 // Common function to call after each fetch.
Marc Treib 2016/12/19 12:59:24 misaligned
jkrcal 2016/12/20 16:39:47 Done.
125 void OnFetchCompleted(Status status);
126
127 // Applies the provided |schedule|.
128 void ApplyFetchingSchedule(const FetchingSchedule& schedule);
129
130 // Interface for doing the actual updates, when they are due. Not owned.
Marc Treib 2016/12/19 12:59:24 If it's a unique_ptr, it's owned by definition.
jkrcal 2016/12/20 16:39:47 Done (outdated comment).
131 std::unique_ptr<RemoteSuggestionsProvider> provider_;
132
133 // Interface for scheduling hard fetches, OS dependent. Not owned, may be
134 // null.
135 PersistentScheduler* persistent_scheduler_;
136
137 // Used to adapt the schedule based on usage activity of the user. Not owned.
138 const UserClassifier* user_classifier_;
139
140 PrefService* pref_service_;
141
142 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider);
143 };
144
145 } // namespace ntp_snippets
146
147 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698