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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 1922463002: [NTP Snippets] Limit the number of snippets to 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 8 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/ntp_snippets_service.cc
diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc
index 84a13b1ee2ec79684674ca54dc23e4600c078963..d1d349b34c667dcdbfedcd6be2055760ed65a082 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -33,6 +33,8 @@ namespace ntp_snippets {
namespace {
+const int kMaxSnippetCount = 10;
+
const int kFetchingIntervalWifiChargingSeconds = 30 * 60;
const int kFetchingIntervalWifiSeconds = 2 * 60 * 60;
const int kFetchingIntervalFallbackSeconds = 24 * 60 * 60;
@@ -235,11 +237,11 @@ void NTPSnippetsService::FetchSnippetsFromHosts(
const std::set<std::string>& hosts) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDontRestrict)) {
- snippets_fetcher_->FetchSnippets(std::set<std::string>());
+ snippets_fetcher_->FetchSnippets(std::set<std::string>(), kMaxSnippetCount);
return;
}
if (!hosts.empty()) {
- snippets_fetcher_->FetchSnippets(hosts);
+ snippets_fetcher_->FetchSnippets(hosts, kMaxSnippetCount);
} else {
last_fetch_status_ = kStatusMessageEmptyHosts;
LoadingSnippetsFinished();
@@ -310,6 +312,11 @@ void NTPSnippetsService::RemoveObserver(NTPSnippetsServiceObserver* observer) {
observers_.RemoveObserver(observer);
}
+// static
+int NTPSnippetsService::GetMaxSnippetCountForTesting() {
+ return kMaxSnippetCount;
+}
+
void NTPSnippetsService::OnSuggestionsChanged(
const SuggestionsProfile& suggestions) {
std::set<std::string> hosts = GetSuggestionsHostsImpl(suggestions);
@@ -414,6 +421,11 @@ bool NTPSnippetsService::LoadFromListValue(const base::ListValue& list) {
std::make_move_iterator(new_snippets.begin()),
std::make_move_iterator(new_snippets.end()));
+ // If there are more snippets now than we want to show, drop the extra ones
+ // from the end of the list.
+ if (snippets_.size() > kMaxSnippetCount)
+ snippets_.resize(kMaxSnippetCount);
+
return true;
}
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service.h ('k') | components/ntp_snippets/ntp_snippets_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698