| Index: components/ntp_snippets/section_rankers/default_constant_section_ranker.cc
|
| diff --git a/components/ntp_snippets/section_rankers/default_constant_section_ranker.cc b/components/ntp_snippets/section_rankers/default_constant_section_ranker.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..30ba8cc26e71ffda94281192c7f0c61b1517d42a
|
| --- /dev/null
|
| +++ b/components/ntp_snippets/section_rankers/default_constant_section_ranker.cc
|
| @@ -0,0 +1,64 @@
|
| +// 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/section_rankers/default_constant_section_ranker.h"
|
| +
|
| +#include "base/stl_util.h"
|
| +
|
| +namespace ntp_snippets {
|
| +
|
| +DefaultConstantSectionRanker::DefaultConstantSectionRanker() {
|
| + // 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());
|
| +}
|
| +
|
| +DefaultConstantSectionRanker::~DefaultConstantSectionRanker() = default;
|
| +
|
| +bool DefaultConstantSectionRanker::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();
|
| +}
|
| +
|
| +void DefaultConstantSectionRanker::ClearHistory(base::Time begin,
|
| + base::Time end) {
|
| + // Ignored.
|
| +}
|
| +
|
| +void DefaultConstantSectionRanker::AppendCategoryIfNecessary(
|
| + Category category) {
|
| + if (!base::ContainsValue(ordered_categories_, category)) {
|
| + ordered_categories_.push_back(category);
|
| + }
|
| +}
|
| +
|
| +void DefaultConstantSectionRanker::OnSuggestionOpened(Category category) {
|
| + // Ignored. The order is constant.
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// Private methods
|
| +
|
| +void DefaultConstantSectionRanker::AppendKnownCategory(
|
| + KnownCategories known_category) {
|
| + Category category = Category::FromKnownCategory(known_category);
|
| + DCHECK(!base::ContainsValue(ordered_categories_, category));
|
| + ordered_categories_.push_back(category);
|
| +}
|
| +
|
| +} // namespace ntp_snippets
|
|
|