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

Side by Side 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: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
7 7
8 #include <ostream>
9
8 namespace ntp_snippets { 10 namespace ntp_snippets {
9 11
10 // A category groups ContentSuggestions which belong together. 12 class ContentSuggestionsCategoryFactory;
11 enum class ContentSuggestionsCategory { ARTICLES, OFFLINE_PAGES, COUNT }; 13
14 // These are the categories that the client knows about.
15 // The values before LOCAL_CATEGORIES_COUNT are the categories that are provided
16 // locally on the device. Categories provided by the server only need to be
17 // hard-coded here if they need to be recognized by the client implementation.
18 enum class KnownSuggestionsCategories {
19 OFFLINE_PAGES,
20 LOCAL_CATEGORIES_COUNT,
21
22 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
23 ARTICLES = REMOTE_CATEGORIES_OFFSET + 1,
24 };
25
26 // A category groups ContentSuggestions which belong together. Use the
27 // ContentSuggestionsCategoryFactory to obtain instances.
28 class ContentSuggestionsCategory {
29 public:
30 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.
31
32 private:
33 friend class ContentSuggestionsCategoryFactory;
34 ContentSuggestionsCategory(int id);
Marc Treib 2016/07/28 11:41:45 empty line before
Philipp Keck 2016/07/28 13:50:54 Done.
35
36 int id_;
37 };
38
39 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.
40 const ContentSuggestionsCategory& right) {
41 return left.id() == right.id();
42 }
43
44 inline bool operator!=(const ContentSuggestionsCategory& left,
45 const ContentSuggestionsCategory& right) {
46 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.
47 }
48
49 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.
50 const ContentSuggestionsCategory& right) {
51 return static_cast<int>(left) == right.id();
52 }
53
54 inline bool operator==(const ContentSuggestionsCategory& left,
55 const KnownSuggestionsCategories& right) {
56 return right == left;
57 }
58
59 inline bool operator!=(const KnownSuggestionsCategories& left,
60 const ContentSuggestionsCategory& right) {
61 return static_cast<int>(left) != right.id();
62 }
63
64 inline bool operator!=(const ContentSuggestionsCategory& left,
65 const KnownSuggestionsCategories& right) {
66 return right != left;
67 }
68
69 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
70 const ContentSuggestionsCategory& obj);
12 71
13 } // namespace ntp_snippets 72 } // namespace ntp_snippets
14 73
15 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ 74 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698