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

Unified Diff: components/ntp_snippets/content_suggestions_category.h

Issue 2187233002: Add ContentSuggestionsCategoryFactory; Store categories as ints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 months 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
« no previous file with comments | « components/ntp_snippets/BUILD.gn ('k') | components/ntp_snippets/content_suggestions_category.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/content_suggestions_category.h
diff --git a/components/ntp_snippets/content_suggestions_category.h b/components/ntp_snippets/content_suggestions_category.h
index 70bb23d06fedc97de38433c46551ea6fc347af2c..460dd7eae23ef31c9b8bc89a36ae7dce23280fd0 100644
--- a/components/ntp_snippets/content_suggestions_category.h
+++ b/components/ntp_snippets/content_suggestions_category.h
@@ -5,10 +5,58 @@
#ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
#define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
+#include <ostream>
+
namespace ntp_snippets {
-// A category groups ContentSuggestions which belong together.
-enum class ContentSuggestionsCategory { ARTICLES, OFFLINE_PAGES, COUNT };
+class ContentSuggestionsCategoryFactory;
+
+// These are the categories that the client knows about.
+// The values before LOCAL_CATEGORIES_COUNT are the categories that are provided
+// locally on the device. Those values need to be listed in the
+// ContentSuggestionsCategoryFactory constructor!
+// Categories provided by the server (IDs strictly larger than
+// REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need to be
+// recognized by the client implementation.
+enum class KnownSuggestionsCategories {
+ OFFLINE_PAGES,
+ LOCAL_CATEGORIES_COUNT,
+
+ REMOTE_CATEGORIES_OFFSET = 10000,
+ ARTICLES = REMOTE_CATEGORIES_OFFSET + 1,
+};
+
+// A category groups ContentSuggestions which belong together. Use the
+// ContentSuggestionsCategoryFactory to obtain instances.
+class ContentSuggestionsCategory {
+ public:
+ // Returns a non-negative identifier that is unique for the category and can
+ // be converted back to a ContentSuggestionsCategory instance using
+ // |ContentSuggestionsCategoryFactory::FromIDValue(id)|.
+ // Note that these IDs are not necessarily stable across multiple runs of
+ // the application, so they should not be persisted.
+ int id() const { return id_; }
+
+ bool IsKnownCategory(KnownSuggestionsCategories known_category) const;
+
+ private:
+ friend class ContentSuggestionsCategoryFactory;
+
+ ContentSuggestionsCategory(int id);
+
+ int id_;
+
+ // Allow copy and assignment.
+};
+
+bool operator==(const ContentSuggestionsCategory& left,
+ const ContentSuggestionsCategory& right);
+
+bool operator!=(const ContentSuggestionsCategory& left,
+ const ContentSuggestionsCategory& right);
+
+std::ostream& operator<<(std::ostream& os,
+ const ContentSuggestionsCategory& obj);
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/BUILD.gn ('k') | components/ntp_snippets/content_suggestions_category.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698