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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2260783002: Make GetDismissedSuggestionsForDebugging asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace function pointer, use multiple if-continue Created 4 years, 4 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 unified diff | Download patch
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/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 if (snippets_.empty()) 331 if (snippets_.empty())
332 return; 332 return;
333 333
334 database_->DeleteSnippets(snippets_); 334 database_->DeleteSnippets(snippets_);
335 snippets_.clear(); 335 snippets_.clear();
336 336
337 NotifyNewSuggestions(); 337 NotifyNewSuggestions();
338 } 338 }
339 339
340 std::vector<ContentSuggestion> 340 void NTPSnippetsService::GetDismissedSuggestionsForDebugging(
341 NTPSnippetsService::GetDismissedSuggestionsForDebugging(Category category) { 341 Category category,
342 const DismissedSuggestionsCallback& callback) {
342 DCHECK_EQ(category, provided_category_); 343 DCHECK_EQ(category, provided_category_);
343 std::vector<ContentSuggestion> result; 344 std::vector<ContentSuggestion> result;
344 for (const std::unique_ptr<NTPSnippet>& snippet : dismissed_snippets_) { 345 for (const std::unique_ptr<NTPSnippet>& snippet : dismissed_snippets_) {
345 if (!snippet->is_complete()) 346 if (!snippet->is_complete())
346 continue; 347 continue;
347 ContentSuggestion suggestion( 348 ContentSuggestion suggestion(
348 MakeUniqueID(provided_category_, snippet->id()), 349 MakeUniqueID(provided_category_, snippet->id()),
349 snippet->best_source().url); 350 snippet->best_source().url);
350 suggestion.set_amp_url(snippet->best_source().amp_url); 351 suggestion.set_amp_url(snippet->best_source().amp_url);
351 suggestion.set_title(base::UTF8ToUTF16(snippet->title())); 352 suggestion.set_title(base::UTF8ToUTF16(snippet->title()));
352 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet())); 353 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet()));
353 suggestion.set_publish_date(snippet->publish_date()); 354 suggestion.set_publish_date(snippet->publish_date());
354 suggestion.set_publisher_name( 355 suggestion.set_publisher_name(
355 base::UTF8ToUTF16(snippet->best_source().publisher_name)); 356 base::UTF8ToUTF16(snippet->best_source().publisher_name));
356 suggestion.set_score(snippet->score()); 357 suggestion.set_score(snippet->score());
357 result.emplace_back(std::move(suggestion)); 358 result.emplace_back(std::move(suggestion));
358 } 359 }
359 return result; 360 callback.Run(std::move(result));
360 } 361 }
361 362
362 void NTPSnippetsService::ClearDismissedSuggestionsForDebugging( 363 void NTPSnippetsService::ClearDismissedSuggestionsForDebugging(
363 Category category) { 364 Category category) {
364 DCHECK_EQ(category, provided_category_); 365 DCHECK_EQ(category, provided_category_);
365 if (!initialized()) 366 if (!initialized())
366 return; 367 return;
367 368
368 if (dismissed_snippets_.empty()) 369 if (dismissed_snippets_.empty())
369 return; 370 return;
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 void NTPSnippetsService::UpdateCategoryStatus(CategoryStatus status) { 840 void NTPSnippetsService::UpdateCategoryStatus(CategoryStatus status) {
840 if (status == category_status_) 841 if (status == category_status_)
841 return; 842 return;
842 843
843 category_status_ = status; 844 category_status_ = status;
844 observer()->OnCategoryStatusChanged(this, provided_category_, 845 observer()->OnCategoryStatusChanged(this, provided_category_,
845 category_status_); 846 category_status_);
846 } 847 }
847 848
848 } // namespace ntp_snippets 849 } // namespace ntp_snippets
OLDNEW
« 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