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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider.cc

Issue 2520993002: Remove the "exclude archived snippets" from the snippets fetching code. (Closed)
Patch Set: 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
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 bool interactive_request) { 323 bool interactive_request) {
324 // TODO(tschumann): FetchSnippets() and FetchSnippetsFromHost() implement the 324 // TODO(tschumann): FetchSnippets() and FetchSnippetsFromHost() implement the
325 // fetch logic when called by the background fetcher or interactive "reload" 325 // fetch logic when called by the background fetcher or interactive "reload"
326 // requests. Fetch() is right now only called for the fetch-more use case. 326 // requests. Fetch() is right now only called for the fetch-more use case.
327 // The names are confusing and we need to clean them up. 327 // The names are confusing and we need to clean them up.
328 if (!ready()) { 328 if (!ready()) {
329 return; 329 return;
330 } 330 }
331 MarkEmptyCategoriesAsLoading(); 331 MarkEmptyCategoriesAsLoading();
332 332
333 NTPSnippetsFetcher::Params params = 333 NTPSnippetsFetcher::Params params = BuildFetchParams();
334 BuildFetchParams(/*exclude_archived_suggestions=*/true);
335 params.hosts = hosts; 334 params.hosts = hosts;
336 params.interactive_request = interactive_request; 335 params.interactive_request = interactive_request;
337 snippets_fetcher_->FetchSnippets( 336 snippets_fetcher_->FetchSnippets(
338 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, 337 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished,
339 base::Unretained(this))); 338 base::Unretained(this)));
340 } 339 }
341 340
342 void RemoteSuggestionsProvider::Fetch( 341 void RemoteSuggestionsProvider::Fetch(
343 const Category& category, 342 const Category& category,
344 const std::set<std::string>& known_suggestion_ids, 343 const std::set<std::string>& known_suggestion_ids,
345 const FetchDoneCallback& callback) { 344 const FetchDoneCallback& callback) {
346 if (!ready()) { 345 if (!ready()) {
347 CallWithEmptyResults(callback, 346 CallWithEmptyResults(callback,
348 Status(StatusCode::TEMPORARY_ERROR, 347 Status(StatusCode::TEMPORARY_ERROR,
349 "RemoteSuggestionsProvider is not ready!")); 348 "RemoteSuggestionsProvider is not ready!"));
350 return; 349 return;
351 } 350 }
352 NTPSnippetsFetcher::Params params = 351 NTPSnippetsFetcher::Params params = BuildFetchParams();
353 BuildFetchParams(/*exclude_archived_suggestions=*/false);
354 params.excluded_ids.insert(known_suggestion_ids.begin(), 352 params.excluded_ids.insert(known_suggestion_ids.begin(),
355 known_suggestion_ids.end()); 353 known_suggestion_ids.end());
356 params.interactive_request = true; 354 params.interactive_request = true;
357 params.exclusive_category = category; 355 params.exclusive_category = category;
358 356
359 // TODO(tschumann): NTPSnippetsFetcher does not support concurrent requests 357 // TODO(tschumann): NTPSnippetsFetcher does not support concurrent requests
360 // yet. If a background fetch happens while we fetch-more data, the callback 358 // yet. If a background fetch happens while we fetch-more data, the callback
361 // will never get called. 359 // will never get called.
362 snippets_fetcher_->FetchSnippets( 360 snippets_fetcher_->FetchSnippets(
363 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished, 361 params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchMoreFinished,
364 base::Unretained(this), callback)); 362 base::Unretained(this), callback));
365 } 363 }
366 364
367 // Builds default fetcher params. 365 // Builds default fetcher params.
368 NTPSnippetsFetcher::Params RemoteSuggestionsProvider::BuildFetchParams( 366 NTPSnippetsFetcher::Params RemoteSuggestionsProvider::BuildFetchParams() const {
369 bool exclude_archived_suggestions) const {
370 NTPSnippetsFetcher::Params result; 367 NTPSnippetsFetcher::Params result;
371 result.language_code = application_language_code_; 368 result.language_code = application_language_code_;
372 result.count_to_fetch = kMaxSnippetCount; 369 result.count_to_fetch = kMaxSnippetCount;
373 for (const auto& map_entry : category_contents_) { 370 for (const auto& map_entry : category_contents_) {
374 const CategoryContent& content = map_entry.second; 371 const CategoryContent& content = map_entry.second;
375 for (const auto& dismissed_snippet : content.dismissed) { 372 for (const auto& dismissed_snippet : content.dismissed) {
376 result.excluded_ids.insert(dismissed_snippet->id()); 373 result.excluded_ids.insert(dismissed_snippet->id());
377 } 374 }
378 if (exclude_archived_suggestions) {
379 for (const auto& archived_snippet : content.archived) {
380 result.excluded_ids.insert(archived_snippet->id());
381 }
382 }
383 } 375 }
384 return result; 376 return result;
385 } 377 }
386 378
387 void RemoteSuggestionsProvider::MarkEmptyCategoriesAsLoading() { 379 void RemoteSuggestionsProvider::MarkEmptyCategoriesAsLoading() {
388 for (const auto& item : category_contents_) { 380 for (const auto& item : category_contents_) {
389 Category category = item.first; 381 Category category = item.first;
390 const CategoryContent& content = item.second; 382 const CategoryContent& content = item.second;
391 if (content.snippets.empty()) { 383 if (content.snippets.empty()) {
392 UpdateCategoryStatus(category, CategoryStatus::AVAILABLE_LOADING); 384 UpdateCategoryStatus(category, CategoryStatus::AVAILABLE_LOADING);
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = 1328 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) =
1337 default; 1329 default;
1338 1330
1339 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; 1331 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default;
1340 1332
1341 RemoteSuggestionsProvider::CategoryContent& 1333 RemoteSuggestionsProvider::CategoryContent&
1342 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = 1334 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) =
1343 default; 1335 default;
1344 1336
1345 } // namespace ntp_snippets 1337 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698