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

Unified Diff: components/ntp_snippets/category_rankers/constant_category_ranker.h

Issue 2568033005: [NTP::SectionOrder] Replace CategoryFactory with a category ranker. (Closed)
Patch Set: rebase. 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/category_rankers/constant_category_ranker.h
diff --git a/components/ntp_snippets/category_rankers/constant_category_ranker.h b/components/ntp_snippets/category_rankers/constant_category_ranker.h
new file mode 100644
index 0000000000000000000000000000000000000000..c01f0b969dbba70acc56c7f763106fcfe9c7fac6
--- /dev/null
+++ b/components/ntp_snippets/category_rankers/constant_category_ranker.h
@@ -0,0 +1,42 @@
+// 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.
+
+#ifndef COMPONENTS_NTP_SNIPPETS_SECTION_RANKERS_CONSTANT_SECTION_RANKER_H_
+#define COMPONENTS_NTP_SNIPPETS_SECTION_RANKERS_CONSTANT_SECTION_RANKER_H_
+
+#include <vector>
+
+#include "base/time/time.h"
+#include "components/ntp_snippets/category.h"
+#include "components/ntp_snippets/category_rankers/category_ranker.h"
+
+namespace ntp_snippets {
+
+// Simple implementation of a CategoryRanker that never changes the order. For
+// KnownCategories, the order is hardcoded. Remote categories must be added
+// using |AppendCategoryIfNecessary|. They are sorted after all known
+// categories. Among themselves their order is the same as the order they were
+// added in.
+class ConstantCategoryRanker : public CategoryRanker {
+ public:
+ ConstantCategoryRanker();
+ ~ConstantCategoryRanker() override;
+
+ // CategoryRanker implementation.
+ bool Compare(Category left, Category right) const override;
+ void ClearHistory(base::Time begin, base::Time end) override;
+ void AppendCategoryIfNecessary(Category category) override;
+ void OnSuggestionOpened(Category category) override;
+
+ private:
+ void AppendKnownCategory(KnownCategories known_category);
+
+ std::vector<Category> ordered_categories_;
+
+ DISALLOW_COPY_AND_ASSIGN(ConstantCategoryRanker);
+};
+
+} // namespace ntp_snippets
+
+#endif // COMPONENTS_NTP_SNIPPETS_SECTION_RANKERS_CONSTANT_SECTION_RANKER_H_

Powered by Google App Engine
This is Rietveld 408576698