Chromium Code Reviews| Index: components/ntp_snippets/category_rankers/constant_category_ranker.cc |
| diff --git a/components/ntp_snippets/category_rankers/constant_category_ranker.cc b/components/ntp_snippets/category_rankers/constant_category_ranker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3995bd00404c4b1b1ba06eb7b18c85e83230589a |
| --- /dev/null |
| +++ b/components/ntp_snippets/category_rankers/constant_category_ranker.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/ntp_snippets/category_rankers/constant_category_ranker.h" |
| + |
| +#include "base/stl_util.h" |
| + |
| +namespace ntp_snippets { |
| + |
| +ConstantCategoryRanker::ConstantCategoryRanker() { |
| + // Add all local categories in a fixed order. |
| + AppendKnownCategory(KnownCategories::DOWNLOADS); |
| + AppendKnownCategory(KnownCategories::RECENT_TABS); |
| + AppendKnownCategory(KnownCategories::FOREIGN_TABS); |
| + AppendKnownCategory(KnownCategories::BOOKMARKS); |
| + AppendKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES); |
| + |
| + DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT), |
| + ordered_categories_.size()); |
| +} |
| + |
| +ConstantCategoryRanker::~ConstantCategoryRanker() = default; |
| + |
| +bool ConstantCategoryRanker::Compare(Category left, Category right) const { |
| + for (Category category : ordered_categories_) { |
| + if (category == left) { |
| + return true; |
| + } |
| + if (category == right) { |
| + return false; |
| + } |
| + } |
| + return left.id() < right.id(); |
|
tschumann
2016/12/15 11:50:26
that's a bit confusing. What are the cases where l
vitaliii
2016/12/15 15:30:13
When remote categories are sent in an order not so
tschumann
2016/12/15 18:23:13
I totally agree that it's good to get this consoli
vitaliii
2016/12/16 08:15:43
Acknowledged.
|
| +} |
| + |
| +void ConstantCategoryRanker::ClearHistory(base::Time begin, base::Time end) { |
| + // Ignored. |
| +} |
| + |
| +void ConstantCategoryRanker::AppendCategoryIfNecessary(Category category) { |
| + if (!base::ContainsValue(ordered_categories_, category)) { |
| + ordered_categories_.push_back(category); |
| + } |
| +} |
| + |
| +void ConstantCategoryRanker::OnSuggestionOpened(Category category) { |
| + // Ignored. The order is constant. |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
|
tschumann
2016/12/15 11:50:26
i'd drop this section comment. Ideally we don't ge
Marc Treib
2016/12/15 12:22:56
No, it's not particularly common. I don't write th
tschumann
2016/12/15 13:05:20
Then let's leave them out.
vitaliii
2016/12/15 15:30:13
Done.
|
| +// Private methods |
| + |
| +void ConstantCategoryRanker::AppendKnownCategory( |
| + KnownCategories known_category) { |
| + Category category = Category::FromKnownCategory(known_category); |
| + DCHECK(!base::ContainsValue(ordered_categories_, category)); |
| + ordered_categories_.push_back(category); |
| +} |
| + |
| +} // namespace ntp_snippets |