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

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

Issue 2406573002: 📰 Persist category dismissals (Closed)
Patch Set: ready for review Created 4 years, 2 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/remote/ntp_snippets_service.h" 5 #include "components/ntp_snippets/remote/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 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 state_ = State::ERROR_OCCURRED; 954 state_ = State::ERROR_OCCURRED;
955 EnterStateError(); 955 EnterStateError();
956 break; 956 break;
957 } 957 }
958 958
959 // Schedule or un-schedule background fetching after each state change. 959 // Schedule or un-schedule background fetching after each state change.
960 RescheduleFetching(false); 960 RescheduleFetching(false);
961 } 961 }
962 962
963 void NTPSnippetsService::NotifyNewSuggestions() { 963 void NTPSnippetsService::NotifyNewSuggestions() {
964 ContentSuggestionsProvider::Observer::SuggestionBatch receivedSuggestions;
965
964 for (const auto& item : categories_) { 966 for (const auto& item : categories_) {
965 Category category = item.first; 967 Category category = item.first;
966 const CategoryContent& content = item.second; 968 const CategoryContent& content = item.second;
967 969
968 std::vector<ContentSuggestion> result; 970 std::vector<ContentSuggestion> result;
969 for (const std::unique_ptr<NTPSnippet>& snippet : content.snippets) { 971 for (const std::unique_ptr<NTPSnippet>& snippet : content.snippets) {
970 // TODO(sfiera): if a snippet is not going to be displayed, move it 972 // TODO(sfiera): if a snippet is not going to be displayed, move it
971 // directly to content.dismissed on fetch. Otherwise, we might prune 973 // directly to content.dismissed on fetch. Otherwise, we might prune
972 // other snippets to get down to kMaxSnippetCount, only to hide one of the 974 // other snippets to get down to kMaxSnippetCount, only to hide one of the
973 // incomplete ones we kept. 975 // incomplete ones we kept.
974 if (!snippet->is_complete()) 976 if (!snippet->is_complete())
975 continue; 977 continue;
976 ContentSuggestion suggestion(category, snippet->id(), 978 ContentSuggestion suggestion(category, snippet->id(),
977 snippet->best_source().url); 979 snippet->best_source().url);
978 suggestion.set_amp_url(snippet->best_source().amp_url); 980 suggestion.set_amp_url(snippet->best_source().amp_url);
979 suggestion.set_title(base::UTF8ToUTF16(snippet->title())); 981 suggestion.set_title(base::UTF8ToUTF16(snippet->title()));
980 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet())); 982 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet()));
981 suggestion.set_publish_date(snippet->publish_date()); 983 suggestion.set_publish_date(snippet->publish_date());
982 suggestion.set_publisher_name( 984 suggestion.set_publisher_name(
983 base::UTF8ToUTF16(snippet->best_source().publisher_name)); 985 base::UTF8ToUTF16(snippet->best_source().publisher_name));
984 suggestion.set_score(snippet->score()); 986 suggestion.set_score(snippet->score());
985 result.emplace_back(std::move(suggestion)); 987 result.emplace_back(std::move(suggestion));
986 } 988 }
987 989
988 DVLOG(1) << "NotifyNewSuggestions(): " << result.size() 990 receivedSuggestions[category] = std::move(result);
989 << " items in category " << category;
990 observer()->OnNewSuggestions(this, category, std::move(result));
991 } 991 }
992
993 observer()->OnNewSuggestionBatch(this, std::move(receivedSuggestions));
992 } 994 }
993 995
994 void NTPSnippetsService::UpdateCategoryStatus(Category category, 996 void NTPSnippetsService::UpdateCategoryStatus(Category category,
995 CategoryStatus status) { 997 CategoryStatus status) {
996 DCHECK(base::ContainsKey(categories_, category)); 998 DCHECK(base::ContainsKey(categories_, category));
997 CategoryContent& content = categories_[category]; 999 CategoryContent& content = categories_[category];
998 if (status == content.status) 1000 if (status == content.status)
999 return; 1001 return;
1000 1002
1001 DVLOG(1) << "UpdateCategoryStatus(): " << category.id() << ": " 1003 DVLOG(1) << "UpdateCategoryStatus(): " << category.id() << ": "
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 } 1103 }
1102 1104
1103 NTPSnippetsService::CategoryContent::CategoryContent() = default; 1105 NTPSnippetsService::CategoryContent::CategoryContent() = default;
1104 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = 1106 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) =
1105 default; 1107 default;
1106 NTPSnippetsService::CategoryContent::~CategoryContent() = default; 1108 NTPSnippetsService::CategoryContent::~CategoryContent() = default;
1107 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: 1109 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent::
1108 operator=(CategoryContent&&) = default; 1110 operator=(CategoryContent&&) = default;
1109 1111
1110 } // namespace ntp_snippets 1112 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698