Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "components/ntp_snippets/remote/request_throttler.h" |
| 21 #include "components/web_resource/eula_accepted_notifier.h" | |
| 21 | 22 |
| 22 class PrefRegistrySimple; | 23 class PrefRegistrySimple; |
| 23 class PrefService; | 24 class PrefService; |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class Clock; | 27 class Clock; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace ntp_snippets { | 30 namespace ntp_snippets { |
| 30 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 50 // callback. | 51 // callback. |
| 51 // This class is final because it does things in its constructor which make it | 52 // This class is final because it does things in its constructor which make it |
| 52 // unsafe to derive from it. | 53 // unsafe to derive from it. |
| 53 // TODO(jkrcal): Introduce two-phase initialization and make the class not | 54 // TODO(jkrcal): Introduce two-phase initialization and make the class not |
| 54 // final? (see the same comment for RemoteSuggestionsProvider) | 55 // final? (see the same comment for RemoteSuggestionsProvider) |
| 55 // TODO(jkrcal): Change the interface to ContentSuggestionsProvider. We do not | 56 // TODO(jkrcal): Change the interface to ContentSuggestionsProvider. We do not |
| 56 // need any special functionality, all special should be exposed in the | 57 // need any special functionality, all special should be exposed in the |
| 57 // Scheduler interface. crbug.com/695447 | 58 // Scheduler interface. crbug.com/695447 |
| 58 class SchedulingRemoteSuggestionsProvider final | 59 class SchedulingRemoteSuggestionsProvider final |
| 59 : public RemoteSuggestionsProvider, | 60 : public RemoteSuggestionsProvider, |
| 60 public RemoteSuggestionsScheduler { | 61 public RemoteSuggestionsScheduler, |
| 62 public web_resource::EulaAcceptedNotifier::Observer { | |
|
tschumann
2017/03/21 20:13:15
as you know, I'm trying to avoid multiple inherita
jkrcal
2017/03/22 09:36:04
Done. WDYT?
tschumann
2017/03/22 09:47:01
Thanks! The cyclic dependency is still a bit of a
jkrcal
2017/03/22 16:48:01
Acknowledged.
| |
| 61 public: | 63 public: |
| 62 SchedulingRemoteSuggestionsProvider( | 64 SchedulingRemoteSuggestionsProvider( |
| 63 Observer* observer, | 65 ContentSuggestionsProvider::Observer* observer, |
| 64 std::unique_ptr<RemoteSuggestionsProvider> provider, | 66 std::unique_ptr<RemoteSuggestionsProvider> provider, |
| 65 PersistentScheduler* persistent_scheduler, | 67 PersistentScheduler* persistent_scheduler, |
| 66 const UserClassifier* user_classifier, | 68 const UserClassifier* user_classifier, |
| 67 PrefService* pref_service, | 69 PrefService* profile_prefs, |
| 70 PrefService* local_state_prefs, | |
| 68 std::unique_ptr<base::Clock> clock); | 71 std::unique_ptr<base::Clock> clock); |
| 69 | 72 |
| 70 ~SchedulingRemoteSuggestionsProvider() override; | 73 ~SchedulingRemoteSuggestionsProvider() override; |
| 71 | 74 |
| 72 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 75 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 73 | 76 |
| 74 // RemoteSuggestionsScheduler implementation. | 77 // RemoteSuggestionsScheduler implementation. |
| 75 void OnProviderActivated() override; | 78 void OnProviderActivated() override; |
| 76 void OnProviderDeactivated() override; | 79 void OnProviderDeactivated() override; |
| 77 void OnSuggestionsCleared() override; | 80 void OnSuggestionsCleared() override; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 102 base::Time begin, | 105 base::Time begin, |
| 103 base::Time end, | 106 base::Time end, |
| 104 const base::Callback<bool(const GURL& url)>& filter) override; | 107 const base::Callback<bool(const GURL& url)>& filter) override; |
| 105 void ClearCachedSuggestions(Category category) override; | 108 void ClearCachedSuggestions(Category category) override; |
| 106 void OnSignInStateChanged() override; | 109 void OnSignInStateChanged() override; |
| 107 void GetDismissedSuggestionsForDebugging( | 110 void GetDismissedSuggestionsForDebugging( |
| 108 Category category, | 111 Category category, |
| 109 const DismissedSuggestionsCallback& callback) override; | 112 const DismissedSuggestionsCallback& callback) override; |
| 110 void ClearDismissedSuggestionsForDebugging(Category category) override; | 113 void ClearDismissedSuggestionsForDebugging(Category category) override; |
| 111 | 114 |
| 115 // EulaAcceptedNotifier::Observer implementation. | |
| 116 void OnEulaAccepted() override; | |
| 117 | |
| 112 private: | 118 private: |
| 113 // Abstract description of the fetching schedule. | 119 // Abstract description of the fetching schedule. |
| 114 struct FetchingSchedule { | 120 struct FetchingSchedule { |
| 115 static FetchingSchedule Empty(); | 121 static FetchingSchedule Empty(); |
| 116 bool operator==(const FetchingSchedule& other) const; | 122 bool operator==(const FetchingSchedule& other) const; |
| 117 bool operator!=(const FetchingSchedule& other) const; | 123 bool operator!=(const FetchingSchedule& other) const; |
| 118 bool is_empty() const; | 124 bool is_empty() const; |
| 119 | 125 |
| 120 base::TimeDelta interval_persistent_wifi; | 126 base::TimeDelta interval_persistent_wifi; |
| 121 base::TimeDelta interval_persistent_fallback; | 127 base::TimeDelta interval_persistent_fallback; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 bool background_fetch_in_progress_; | 197 bool background_fetch_in_progress_; |
| 192 | 198 |
| 193 // Used to adapt the schedule based on usage activity of the user. Not owned. | 199 // Used to adapt the schedule based on usage activity of the user. Not owned. |
| 194 const UserClassifier* user_classifier_; | 200 const UserClassifier* user_classifier_; |
| 195 | 201 |
| 196 // Request throttlers for limiting requests for different classes of users. | 202 // Request throttlers for limiting requests for different classes of users. |
| 197 RequestThrottler request_throttler_rare_ntp_user_; | 203 RequestThrottler request_throttler_rare_ntp_user_; |
| 198 RequestThrottler request_throttler_active_ntp_user_; | 204 RequestThrottler request_throttler_active_ntp_user_; |
| 199 RequestThrottler request_throttler_active_suggestions_consumer_; | 205 RequestThrottler request_throttler_active_suggestions_consumer_; |
| 200 | 206 |
| 201 PrefService* pref_service_; | 207 // We should not fetch in background before EULA gets accepted. |
| 208 std::unique_ptr<web_resource::EulaAcceptedNotifier> eula_notifier_; | |
| 209 | |
| 210 PrefService* profile_prefs_; | |
| 202 std::unique_ptr<base::Clock> clock_; | 211 std::unique_ptr<base::Clock> clock_; |
| 203 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; | 212 std::set<SchedulingRemoteSuggestionsProvider::TriggerType> enabled_triggers_; |
| 204 | 213 |
| 205 base::Time background_fetches_allowed_after_; | 214 base::Time background_fetches_allowed_after_; |
| 206 | 215 |
| 207 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); | 216 DISALLOW_COPY_AND_ASSIGN(SchedulingRemoteSuggestionsProvider); |
| 208 }; | 217 }; |
| 209 | 218 |
| 210 } // namespace ntp_snippets | 219 } // namespace ntp_snippets |
| 211 | 220 |
| 212 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_ | 221 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_SCHEDULING_REMOTE_SUGGESTIONS_PROVIDER _H_ |
| OLD | NEW |