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

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

Issue 2368583002: [NTP Snippets] Cleanups from clang-tidy (Closed)
Patch Set: Created 4 years, 3 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 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 12 matching lines...) Expand all
23 PrefService* pref_service) 23 PrefService* pref_service)
24 : state_(state), 24 : state_(state),
25 history_service_observer_(this), 25 history_service_observer_(this),
26 ntp_snippets_service_(nullptr), 26 ntp_snippets_service_(nullptr),
27 user_classifier_(pref_service) { 27 user_classifier_(pref_service) {
28 // Can be null in tests. 28 // Can be null in tests.
29 if (history_service) 29 if (history_service)
30 history_service_observer_.Add(history_service); 30 history_service_observer_.Add(history_service);
31 } 31 }
32 32
33 ContentSuggestionsService::~ContentSuggestionsService() {} 33 ContentSuggestionsService::~ContentSuggestionsService() = default;
34 34
35 void ContentSuggestionsService::Shutdown() { 35 void ContentSuggestionsService::Shutdown() {
36 ntp_snippets_service_ = nullptr; 36 ntp_snippets_service_ = nullptr;
37 id_category_map_.clear(); 37 id_category_map_.clear();
38 suggestions_by_category_.clear(); 38 suggestions_by_category_.clear();
39 providers_by_category_.clear(); 39 providers_by_category_.clear();
40 categories_.clear(); 40 categories_.clear();
41 providers_.clear(); 41 providers_.clear();
42 state_ = State::DISABLED; 42 state_ = State::DISABLED;
43 FOR_EACH_OBSERVER(Observer, observers_, ContentSuggestionsServiceShutdown()); 43 FOR_EACH_OBSERVER(Observer, observers_, ContentSuggestionsServiceShutdown());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 DCHECK(state_ == State::ENABLED); 186 DCHECK(state_ == State::ENABLED);
187 providers_.push_back(std::move(provider)); 187 providers_.push_back(std::move(provider));
188 } 188 }
189 189
190 //////////////////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////////////////
191 // Private methods 191 // Private methods
192 192
193 void ContentSuggestionsService::OnNewSuggestions( 193 void ContentSuggestionsService::OnNewSuggestions(
194 ContentSuggestionsProvider* provider, 194 ContentSuggestionsProvider* provider,
195 Category category, 195 Category category,
196 std::vector<ContentSuggestion> new_suggestions) { 196 std::vector<ContentSuggestion> suggestions) {
Marc Treib 2016/09/23 16:42:44 To match the declaration in the header
197 if (RegisterCategoryIfRequired(provider, category)) 197 if (RegisterCategoryIfRequired(provider, category))
198 NotifyCategoryStatusChanged(category); 198 NotifyCategoryStatusChanged(category);
199 199
200 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) 200 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category)))
201 return; 201 return;
202 202
203 for (const ContentSuggestion& suggestion : 203 for (const ContentSuggestion& suggestion :
204 suggestions_by_category_[category]) { 204 suggestions_by_category_[category]) {
205 id_category_map_.erase(suggestion.id()); 205 id_category_map_.erase(suggestion.id());
206 } 206 }
207 207
208 for (const ContentSuggestion& suggestion : new_suggestions) 208 for (const ContentSuggestion& suggestion : suggestions)
209 id_category_map_.insert(std::make_pair(suggestion.id(), category)); 209 id_category_map_.insert(std::make_pair(suggestion.id(), category));
210 210
211 suggestions_by_category_[category] = std::move(new_suggestions); 211 suggestions_by_category_[category] = std::move(suggestions);
212 212
213 // The positioning of the bookmarks category depends on whether it's empty. 213 // The positioning of the bookmarks category depends on whether it's empty.
214 // TODO(treib): Remove this temporary hack, crbug.com/640568. 214 // TODO(treib): Remove this temporary hack, crbug.com/640568.
215 if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) 215 if (category.IsKnownCategory(KnownCategories::BOOKMARKS))
216 SortCategories(); 216 SortCategories();
217 217
218 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); 218 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category));
219 } 219 }
220 220
221 void ContentSuggestionsService::OnCategoryStatusChanged( 221 void ContentSuggestionsService::OnCategoryStatusChanged(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) 358 if (left.IsKnownCategory(KnownCategories::BOOKMARKS))
359 return false; 359 return false;
360 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) 360 if (right.IsKnownCategory(KnownCategories::BOOKMARKS))
361 return true; 361 return true;
362 } 362 }
363 return category_factory_.CompareCategories(left, right); 363 return category_factory_.CompareCategories(left, right);
364 }); 364 });
365 } 365 }
366 366
367 } // namespace ntp_snippets 367 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698