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

Side by Side Diff: components/ntp_snippets/section_rankers/default_constant_section_ranker.cc

Issue 2568033005: [NTP::SectionOrder] Replace CategoryFactory with a category ranker. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/ntp_snippets/section_rankers/default_constant_section_ranke r.h"
6
7 #include "base/stl_util.h"
8
9 namespace ntp_snippets {
10
11 DefaultConstantSectionRanker::DefaultConstantSectionRanker() {
12 // Add all local categories in a fixed order.
13 AppendKnownCategory(KnownCategories::DOWNLOADS);
14 AppendKnownCategory(KnownCategories::RECENT_TABS);
15 AppendKnownCategory(KnownCategories::FOREIGN_TABS);
16 AppendKnownCategory(KnownCategories::BOOKMARKS);
17 AppendKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES);
18
19 DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT),
20 ordered_categories_.size());
21 }
22
23 DefaultConstantSectionRanker::~DefaultConstantSectionRanker() = default;
24
25 bool DefaultConstantSectionRanker::Compare(Category left,
26 Category right) const {
27 for (Category category : ordered_categories_) {
28 if (category == left) {
29 return true;
30 }
31 if (category == right) {
32 return false;
33 }
34 }
35 return left.id() < right.id();
36 }
37
38 void DefaultConstantSectionRanker::ClearHistory(base::Time begin,
39 base::Time end) {
40 // Ignored.
41 }
42
43 void DefaultConstantSectionRanker::AppendCategoryIfNecessary(
44 Category category) {
45 if (!base::ContainsValue(ordered_categories_, category)) {
46 ordered_categories_.push_back(category);
47 }
48 }
49
50 void DefaultConstantSectionRanker::OnSuggestionOpened(Category category) {
51 // Ignored. The order is constant.
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////
55 // Private methods
56
57 void DefaultConstantSectionRanker::AppendKnownCategory(
58 KnownCategories known_category) {
59 Category category = Category::FromKnownCategory(known_category);
60 DCHECK(!base::ContainsValue(ordered_categories_, category));
61 ordered_categories_.push_back(category);
62 }
63
64 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698