constant_category_ranker.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef COMPONENTS_NTP_SNIPPETS_CATEGORY_RANKERS_CONSTANT_CATEGORY_RANKER_H_
  5. #define COMPONENTS_NTP_SNIPPETS_CATEGORY_RANKERS_CONSTANT_CATEGORY_RANKER_H_
  6. #include <vector>
  7. #include "base/time/time.h"
  8. #include "components/ntp_snippets/category.h"
  9. #include "components/ntp_snippets/category_rankers/category_ranker.h"
  10. namespace ntp_snippets {
  11. // Simple implementation of a CategoryRanker that never changes the order. For
  12. // KnownCategories, the order is hardcoded. Remote categories must be added
  13. // using |AppendCategoryIfNecessary|. They are sorted after all known
  14. // categories. Among themselves their order is the same as the order they were
  15. // added in.
  16. class ConstantCategoryRanker : public CategoryRanker {
  17. public:
  18. ConstantCategoryRanker();
  19. ConstantCategoryRanker(const ConstantCategoryRanker&) = delete;
  20. ConstantCategoryRanker& operator=(const ConstantCategoryRanker&) = delete;
  21. ~ConstantCategoryRanker() override;
  22. // CategoryRanker implementation.
  23. bool Compare(Category left, Category right) const override;
  24. void ClearHistory(base::Time begin, base::Time end) override;
  25. void AppendCategoryIfNecessary(Category category) override;
  26. void InsertCategoryBeforeIfNecessary(Category category_to_insert,
  27. Category anchor) override;
  28. void InsertCategoryAfterIfNecessary(Category category_to_insert,
  29. Category anchor) override;
  30. std::vector<CategoryRanker::DebugDataItem> GetDebugData() override;
  31. void OnSuggestionOpened(Category category) override;
  32. void OnCategoryDismissed(Category category) override;
  33. static std::vector<KnownCategories> GetKnownCategoriesDefaultOrder();
  34. private:
  35. void AppendKnownCategory(KnownCategories known_category);
  36. std::vector<Category> ordered_categories_;
  37. };
  38. } // namespace ntp_snippets
  39. #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_RANKERS_CONSTANT_CATEGORY_RANKER_H_