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

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

Issue 2232783002: Support action button to fetch more content suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippetsbridge
Patch Set: Indent comments 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/content_suggestions_service.h" 5 #include "components/ntp_snippets/content_suggestions_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 providers_.push_back(std::move(provider)); 176 providers_.push_back(std::move(provider));
177 } 177 }
178 178
179 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
180 // Private methods 180 // Private methods
181 181
182 void ContentSuggestionsService::OnNewSuggestions( 182 void ContentSuggestionsService::OnNewSuggestions(
183 ContentSuggestionsProvider* provider, 183 ContentSuggestionsProvider* provider,
184 Category category, 184 Category category,
185 std::vector<ContentSuggestion> new_suggestions) { 185 std::vector<ContentSuggestion> new_suggestions) {
186 if (RegisterCategoryIfRequired(provider, category)) { 186 if (RegisterCategoryIfRequired(provider, category))
187 NotifyCategoryStatusChanged(category); 187 NotifyCategoryStatusChanged(category);
188 } 188
189 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category)))
190 return;
189 191
190 for (const ContentSuggestion& suggestion : 192 for (const ContentSuggestion& suggestion :
191 suggestions_by_category_[category]) { 193 suggestions_by_category_[category]) {
192 id_category_map_.erase(suggestion.id()); 194 id_category_map_.erase(suggestion.id());
193 } 195 }
194 196
195 for (const ContentSuggestion& suggestion : new_suggestions) { 197 for (const ContentSuggestion& suggestion : new_suggestions)
196 id_category_map_.insert(std::make_pair(suggestion.id(), category)); 198 id_category_map_.insert(std::make_pair(suggestion.id(), category));
197 }
198 199
199 suggestions_by_category_[category] = std::move(new_suggestions); 200 suggestions_by_category_[category] = std::move(new_suggestions);
200 201
201 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); 202 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category));
202 } 203 }
203 204
204 void ContentSuggestionsService::OnCategoryStatusChanged( 205 void ContentSuggestionsService::OnCategoryStatusChanged(
205 ContentSuggestionsProvider* provider, 206 ContentSuggestionsProvider* provider,
206 Category category, 207 Category category,
207 CategoryStatus new_status) { 208 CategoryStatus new_status) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return true; 249 return true;
249 } 250 }
250 251
251 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { 252 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
252 FOR_EACH_OBSERVER( 253 FOR_EACH_OBSERVER(
253 Observer, observers_, 254 Observer, observers_,
254 OnCategoryStatusChanged(category, GetCategoryStatus(category))); 255 OnCategoryStatusChanged(category, GetCategoryStatus(category)));
255 } 256 }
256 257
257 } // namespace ntp_snippets 258 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698