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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2225753003: Revert of Add per-section clearing and dismissed suggestions to snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 6bda4d84dfd984546aa134f6013d6b02e90960ba..d906cbd13fa7bccba9fc12e2c1bf1c0e3e73d9c3 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -274,34 +274,6 @@
return std::vector<Category>({provided_category_});
}
-CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
- DCHECK(category.IsKnownCategory(KnownCategories::ARTICLES));
- return category_status_;
-}
-
-void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
- if (!ready())
- return;
-
- std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id);
-
- auto it =
- std::find_if(snippets_.begin(), snippets_.end(),
- [&snippet_id](const std::unique_ptr<NTPSnippet>& snippet) {
- return snippet->id() == snippet_id;
- });
- if (it == snippets_.end())
- return;
-
- (*it)->set_dismissed(true);
-
- database_->SaveSnippet(**it);
- database_->DeleteImage((*it)->id());
-
- dismissed_snippets_.push_back(std::move(*it));
- snippets_.erase(it);
-}
-
void NTPSnippetsService::FetchSuggestionImage(
const std::string& suggestion_id,
const ImageFetchedCallback& callback) {
@@ -312,8 +284,7 @@
base::Unretained(this), snippet_id, callback));
}
-void NTPSnippetsService::ClearCachedSuggestionsForDebugging(Category category) {
- DCHECK_EQ(category, provided_category_);
+void NTPSnippetsService::ClearCachedSuggestionsForDebugging() {
if (!initialized())
return;
@@ -324,41 +295,6 @@
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;
-
- if (dismissed_snippets_.empty())
- return;
-
- database_->DeleteSnippets(dismissed_snippets_);
- dismissed_snippets_.clear();
}
std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() const {
@@ -369,6 +305,45 @@
// TODO(treib): This should just call GetSnippetHostsFromPrefs.
return GetSuggestionsHostsImpl(
suggestions_service_->GetSuggestionsDataFromCache());
+}
+
+void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
+ if (!ready())
+ return;
+
+ std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id);
+
+ auto it =
+ std::find_if(snippets_.begin(), snippets_.end(),
+ [&snippet_id](const std::unique_ptr<NTPSnippet>& snippet) {
+ return snippet->id() == snippet_id;
+ });
+ if (it == snippets_.end())
+ return;
+
+ (*it)->set_dismissed(true);
+
+ database_->SaveSnippet(**it);
+ database_->DeleteImage((*it)->id());
+
+ dismissed_snippets_.push_back(std::move(*it));
+ snippets_.erase(it);
+}
+
+void NTPSnippetsService::ClearDismissedSuggestionsForDebugging() {
+ if (!initialized())
+ return;
+
+ if (dismissed_snippets_.empty())
+ return;
+
+ database_->DeleteSnippets(dismissed_snippets_);
+ dismissed_snippets_.clear();
+}
+
+CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
+ DCHECK(category.IsKnownCategory(KnownCategories::ARTICLES));
+ return category_status_;
}
// static
@@ -689,8 +664,8 @@
}
void NTPSnippetsService::EnterStateDisabled() {
- ClearCachedSuggestionsForDebugging(provided_category_);
- ClearDismissedSuggestionsForDebugging(provided_category_);
+ ClearCachedSuggestionsForDebugging();
+ ClearDismissedSuggestionsForDebugging();
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