Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_fetcher.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| index c0018e7d816ad650ff06f25bdf664b5b64034e2e..37a61cc01bf6d742039cbbea70a420949e4f51b7 100644 |
| --- a/components/ntp_snippets/ntp_snippets_fetcher.cc |
| +++ b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| @@ -70,6 +70,8 @@ const char kPersonalizationBothString[] = "both"; // the default value |
| const char kHostRestrictionOnString[] = "on"; // the default value |
| const char kHostRestrictionOffString[] = "off"; |
| +const int kMaxExcludedIds = 100; |
| + |
| std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { |
| switch (result) { |
| case NTPSnippetsFetcher::FetchResult::SUCCESS: |
| @@ -216,6 +218,7 @@ void NTPSnippetsFetcher::SetCallback( |
| void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
| const std::set<std::string>& hosts, |
| const std::string& language_code, |
| + const std::set<std::string>& excluded_ids, |
| int count, |
| bool interactive_request) { |
| if (!request_throttler_.DemandQuotaForRequest(interactive_request)) |
| @@ -223,6 +226,7 @@ void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
| hosts_ = hosts; |
| fetch_start_time_ = tick_clock_->NowTicks(); |
| + excluded_ids_ = excluded_ids; |
| if (UsesHostRestrictions() && hosts_.empty()) { |
| FetchFinished(OptionalSnippets(), FetchResult::EMPTY_HOSTS, |
| @@ -317,12 +321,22 @@ std::string NTPSnippetsFetcher::RequestParams::BuildRequest() { |
| if (!user_locale.empty()) { |
| request->SetString("uiLanguage", user_locale); |
| } |
| + |
| auto regular_hosts = base::MakeUnique<base::ListValue>(); |
| for (const auto& host : host_restricts) { |
| regular_hosts->AppendString(host); |
| } |
| request->Set("regularlyVisitedHostNames", std::move(regular_hosts)); |
| + auto excluded = base::MakeUnique<base::ListValue>(); |
| + int exclusion_count = 0; |
| + for (const auto& id : excluded_ids) { |
| + if (exclusion_count++ >= kMaxExcludedIds) |
|
Marc Treib
2016/08/25 11:41:44
ListValue has a GetSize, no need for a separate co
sfiera
2016/08/25 11:58:07
Done.
|
| + break; |
| + excluded->AppendString(id); |
| + } |
| + request->Set("excludedSuggestionIds", std::move(excluded)); |
| + |
| // TODO(sfiera): support authentication and personalization |
| // TODO(sfiera): support count_to_fetch |
| break; |
| @@ -392,6 +406,7 @@ void NTPSnippetsFetcher::FetchSnippetsNonAuthenticated() { |
| params.fetch_api = fetch_api_; |
| params.host_restricts = |
| UsesHostRestrictions() ? hosts_ : std::set<std::string>(); |
| + params.excluded_ids = excluded_ids_; |
| params.count_to_fetch = count_to_fetch_; |
| FetchSnippetsImpl(url, std::string(), params.BuildRequest()); |
| } |
| @@ -407,6 +422,7 @@ void NTPSnippetsFetcher::FetchSnippetsAuthenticated( |
| params.user_locale = locale_; |
| params.host_restricts = |
| UsesHostRestrictions() ? hosts_ : std::set<std::string>(); |
| + params.excluded_ids = excluded_ids_; |
| params.count_to_fetch = count_to_fetch_; |
| // TODO(jkrcal, treib): Add unit-tests for authenticated fetches. |
| FetchSnippetsImpl(fetch_url_, |