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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2223073002: Add per-section clearing and dismissed suggestions to snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-Debug builds 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 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 d906cbd13fa7bccba9fc12e2c1bf1c0e3e73d9c3..6bda4d84dfd984546aa134f6013d6b02e90960ba 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -274,37 +274,9 @@ std::vector<Category> NTPSnippetsService::GetProvidedCategories() {
return std::vector<Category>({provided_category_});
}
-void NTPSnippetsService::FetchSuggestionImage(
- const std::string& suggestion_id,
- const ImageFetchedCallback& callback) {
- std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id);
- database_->LoadImage(
- snippet_id,
- base::Bind(&NTPSnippetsService::OnSnippetImageFetchedFromDatabase,
- base::Unretained(this), snippet_id, callback));
-}
-
-void NTPSnippetsService::ClearCachedSuggestionsForDebugging() {
- if (!initialized())
- return;
-
- if (snippets_.empty())
- return;
-
- database_->DeleteSnippets(snippets_);
- snippets_.clear();
-
- NotifyNewSuggestions();
-}
-
-std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() const {
- // |suggestions_service_| can be null in tests.
- if (!suggestions_service_)
- return std::set<std::string>();
-
- // TODO(treib): This should just call GetSnippetHostsFromPrefs.
- return GetSuggestionsHostsImpl(
- suggestions_service_->GetSuggestionsDataFromCache());
+CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
+ DCHECK(category.IsKnownCategory(KnownCategories::ARTICLES));
+ return category_status_;
}
void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
@@ -330,7 +302,55 @@ void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
snippets_.erase(it);
}
-void NTPSnippetsService::ClearDismissedSuggestionsForDebugging() {
+void NTPSnippetsService::FetchSuggestionImage(
+ const std::string& suggestion_id,
+ const ImageFetchedCallback& callback) {
+ std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id);
+ database_->LoadImage(
+ snippet_id,
+ base::Bind(&NTPSnippetsService::OnSnippetImageFetchedFromDatabase,
+ base::Unretained(this), snippet_id, callback));
+}
+
+void NTPSnippetsService::ClearCachedSuggestionsForDebugging(Category category) {
+ DCHECK_EQ(category, provided_category_);
+ if (!initialized())
+ return;
+
+ if (snippets_.empty())
+ return;
+
+ database_->DeleteSnippets(snippets_);
+ snippets_.clear();
+
+ NotifyNewSuggestions();
+}
+
+std::vector<ContentSuggestion>
+NTPSnippetsService::GetDismissedSuggestionsForDebugging(Category category) {
+ DCHECK_EQ(category, provided_category_);
+ std::vector<ContentSuggestion> result;
+ for (const std::unique_ptr<NTPSnippet>& snippet : dismissed_snippets_) {
+ if (!snippet->is_complete())
+ continue;
+ ContentSuggestion suggestion(
+ MakeUniqueID(provided_category_, snippet->id()),
+ snippet->best_source().url);
+ suggestion.set_amp_url(snippet->best_source().amp_url);
+ suggestion.set_title(base::UTF8ToUTF16(snippet->title()));
+ suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet()));
+ suggestion.set_publish_date(snippet->publish_date());
+ suggestion.set_publisher_name(
+ base::UTF8ToUTF16(snippet->best_source().publisher_name));
+ suggestion.set_score(snippet->score());
+ result.emplace_back(std::move(suggestion));
+ }
+ return result;
+}
+
+void NTPSnippetsService::ClearDismissedSuggestionsForDebugging(
+ Category category) {
+ DCHECK_EQ(category, provided_category_);
if (!initialized())
return;
@@ -341,9 +361,14 @@ void NTPSnippetsService::ClearDismissedSuggestionsForDebugging() {
dismissed_snippets_.clear();
}
-CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
- DCHECK(category.IsKnownCategory(KnownCategories::ARTICLES));
- return category_status_;
+std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() const {
+ // |suggestions_service_| can be null in tests.
+ if (!suggestions_service_)
+ return std::set<std::string>();
+
+ // TODO(treib): This should just call GetSnippetHostsFromPrefs.
+ return GetSuggestionsHostsImpl(
+ suggestions_service_->GetSuggestionsDataFromCache());
}
// static
@@ -664,8 +689,8 @@ void NTPSnippetsService::EnterStateEnabled(bool fetch_snippets) {
}
void NTPSnippetsService::EnterStateDisabled() {
- ClearCachedSuggestionsForDebugging();
- ClearDismissedSuggestionsForDebugging();
+ ClearCachedSuggestionsForDebugging(provided_category_);
+ ClearDismissedSuggestionsForDebugging(provided_category_);
expiry_timer_.Stop();
suggestions_service_subscription_.reset();
« 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