| 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;
|
| }
|
|
|
|
|