Chromium Code Reviews| 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..f49af2938a5736060f0b55cc75e98e16d3f74ccb 100644 |
| --- a/components/ntp_snippets/content_suggestions_category.h |
| +++ b/components/ntp_snippets/content_suggestions_category.h |
| @@ -5,10 +5,69 @@ |
| #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. Categories provided by the server 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, |
|
Marc Treib
2016/07/28 11:41:45
Should REMOTE_CATEGORIES_OFFSET itself be a valid
Philipp Keck
2016/07/28 13:50:53
No it shouldn't and the factory enforces that. I d
|
| + 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_; }; |
|
Marc Treib
2016/07/28 11:41:45
nit: extra semicolon at the end
Philipp Keck
2016/07/28 13:50:54
Done.
|
| + |
| + private: |
| + friend class ContentSuggestionsCategoryFactory; |
| + ContentSuggestionsCategory(int id); |
|
Marc Treib
2016/07/28 11:41:45
empty line before
Philipp Keck
2016/07/28 13:50:54
Done.
|
| + |
| + int id_; |
| +}; |
| + |
| +inline bool operator==(const ContentSuggestionsCategory& left, |
|
Marc Treib
2016/07/28 11:41:45
All these shouldn't be inline.
Philipp Keck
2016/07/28 13:50:54
Done.
|
| + const ContentSuggestionsCategory& right) { |
| + return left.id() == right.id(); |
| +} |
| + |
| +inline bool operator!=(const ContentSuggestionsCategory& left, |
| + const ContentSuggestionsCategory& right) { |
| + return left.id() != right.id(); |
|
Marc Treib
2016/07/28 11:41:45
It's a common practice to define != in terms of ==
Philipp Keck
2016/07/28 13:50:54
Done.
|
| +} |
| + |
| +inline bool operator==(const KnownSuggestionsCategories& left, |
|
Marc Treib
2016/07/28 11:41:45
Hmm, not quite sure about these... maybe an explic
tschumann
2016/07/28 12:50:14
Yeah, this also seems a bit overkill to me. Ideall
Philipp Keck
2016/07/28 13:50:53
Done.
Philipp Keck
2016/07/28 13:50:54
See below.
|
| + const ContentSuggestionsCategory& right) { |
| + return static_cast<int>(left) == right.id(); |
| +} |
| + |
| +inline bool operator==(const ContentSuggestionsCategory& left, |
| + const KnownSuggestionsCategories& right) { |
| + return right == left; |
| +} |
| + |
| +inline bool operator!=(const KnownSuggestionsCategories& left, |
| + const ContentSuggestionsCategory& right) { |
| + return static_cast<int>(left) != right.id(); |
| +} |
| + |
| +inline bool operator!=(const ContentSuggestionsCategory& left, |
| + const KnownSuggestionsCategories& right) { |
| + return right != left; |
| +} |
| + |
| +std::ostream& operator<<(std::ostream& os, |
|
Marc Treib
2016/07/28 11:41:45
What's this needed for - output in tests?
tschumann
2016/07/28 12:50:14
not sure about chrome, but in google3 you'd have a
Marc Treib
2016/07/28 12:54:02
Chrome's LOG, DCHECK etc macros make use of operat
Philipp Keck
2016/07/28 13:50:54
It's used in DCHECK_EQ, but it also comes in handy
tschumann
2016/07/28 15:03:45
ok, so this means no operator== comparing KnownSug
Philipp Keck
2016/07/28 15:15:25
Yes, I removed the operator== comparing KnownSugge
|
| + const ContentSuggestionsCategory& obj); |
| } // namespace ntp_snippets |