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

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: Document remote categories order 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
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..fc4802ca84d592b7738aa9d107e090ca705401a3 100644
--- a/components/ntp_snippets/content_suggestions_category.h
+++ b/components/ntp_snippets/content_suggestions_category.h
@@ -5,10 +5,51 @@
#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,
Bernhard Bauer 2016/07/28 15:39:27 Stupid question: If the local categories are fixed
Philipp Keck 2016/07/28 16:59:58 It's because they're also hard-coded on the server
Marc Treib 2016/07/29 08:20:35 We don't actually need a gap between them - the fi
Philipp Keck 2016/07/29 08:24:28 Right. There is a second reason why it's helpful f
+ ARTICLES = REMOTE_CATEGORIES_OFFSET + 1,
+};
+
+// A category groups ContentSuggestions which belong together. Use the
+// ContentSuggestionsCategoryFactory to obtain instances.
+class ContentSuggestionsCategory {
+ public:
+ int id() const { return id_; }
+
+ bool IsKnownCategory(KnownSuggestionsCategories known_category) const;
+
+ private:
+ friend class ContentSuggestionsCategoryFactory;
+
+ ContentSuggestionsCategory(int id);
+
+ int id_;
Bernhard Bauer 2016/07/28 15:39:26 Nit: It's quite common to add a comment that copyi
Philipp Keck 2016/07/28 16:59:58 I added it, not sure about the wording and locatio
+};
+
+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

Powered by Google App Engine
This is Rietveld 408576698