OLD | NEW |
---|---|
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_CATEGORY_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ |
7 | 7 |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 namespace ntp_snippets { | 10 namespace ntp_snippets { |
11 | 11 |
12 class CategoryFactory; | |
13 | |
14 // These are the categories that the client knows about. | 12 // These are the categories that the client knows about. |
15 // The values before LOCAL_CATEGORIES_COUNT are the categories that are provided | 13 // The values before LOCAL_CATEGORIES_COUNT are the categories that are provided |
16 // locally on the device. Categories provided by the server (IDs strictly larger | 14 // locally on the device. Categories provided by the server (IDs strictly larger |
17 // than REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need | 15 // than REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need |
18 // to be recognized by the client implementation. | 16 // to be recognized by the client implementation. |
19 // NOTE: These are persisted, so don't reorder or remove values, and insert new | 17 // NOTE: These are persisted, so don't reorder or remove values, and insert new |
20 // values only in the appropriate places marked below. | 18 // values only in the appropriate places marked below. |
21 // On Android builds, a Java counterpart will be generated for this enum. | 19 // On Android builds, a Java counterpart will be generated for this enum. |
22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets | 20 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets |
23 enum class KnownCategories { | 21 enum class KnownCategories { |
(...skipping 24 matching lines...) Expand all Loading... | |
48 // INSERT NEW REMOTE CATEGORIES HERE! | 46 // INSERT NEW REMOTE CATEGORIES HERE! |
49 | 47 |
50 // Tracks the last known remote category | 48 // Tracks the last known remote category |
51 LAST_KNOWN_REMOTE_CATEGORY = ARTICLES, | 49 LAST_KNOWN_REMOTE_CATEGORY = ARTICLES, |
52 }; | 50 }; |
53 | 51 |
54 // A category groups ContentSuggestions which belong together. Use the | 52 // A category groups ContentSuggestions which belong together. Use the |
55 // CategoryFactory to obtain instances. | 53 // CategoryFactory to obtain instances. |
56 class Category { | 54 class Category { |
57 public: | 55 public: |
56 // Creates a category from a KnownCategory value. The passed |known_category| | |
57 // must not be one of the special values (LOCAL_CATEGORIES_COUNT or | |
58 // REMOTE_CATEGORIES_OFFSET). | |
59 static Category FromKnownCategory(KnownCategories known_category); | |
60 | |
61 // Creates a category from a category identifier delivered by the server. | |
62 // |remote_category| must be positive. | |
63 static Category FromRemoteCategory(int remote_category); | |
64 | |
65 // Creates a category from an ID as returned by |id()|. |id| must be a | |
66 // non-negative value. | |
67 static Category FromIDValue(int id); | |
68 | |
58 // An arbitrary but consistent ordering. Can be used to look up categories in | 69 // An arbitrary but consistent ordering. Can be used to look up categories in |
59 // a std::map, but should not be used to order categories for other purposes. | 70 // a std::map, but should not be used to order categories for other purposes. |
60 struct CompareByID; | 71 struct CompareByID; |
Marc Treib
2016/12/14 10:24:31
nitty nit: This should probably stay on top (types
vitaliii
2016/12/15 15:30:12
Done.
| |
61 | 72 |
62 // Returns a non-negative identifier that is unique for the category and can | 73 // Returns a non-negative identifier that is unique for the category and can |
63 // be converted back to a Category instance using | 74 // be converted back to a Category instance using |
64 // |CategoryFactory::FromIDValue(id)|. | 75 // |CategoryFactory::FromIDValue(id)|. |
65 int id() const { return id_; } | 76 int id() const { return id_; } |
66 | 77 |
67 // Returns whether this category matches the given |known_category|. | 78 // Returns whether this category matches the given |known_category|. |
68 bool IsKnownCategory(KnownCategories known_category) const; | 79 bool IsKnownCategory(KnownCategories known_category) const; |
69 | 80 |
70 private: | 81 private: |
71 friend class CategoryFactory; | |
72 | |
73 explicit Category(int id); | 82 explicit Category(int id); |
74 | 83 |
75 int id_; | 84 int id_; |
76 | 85 |
77 // Allow copy and assignment. | 86 // Allow copy and assignment. |
78 }; | 87 }; |
79 | 88 |
80 bool operator==(const Category& left, const Category& right); | 89 bool operator==(const Category& left, const Category& right); |
81 | 90 |
82 bool operator!=(const Category& left, const Category& right); | 91 bool operator!=(const Category& left, const Category& right); |
83 | 92 |
84 struct Category::CompareByID { | 93 struct Category::CompareByID { |
85 bool operator()(const Category& left, const Category& right) const; | 94 bool operator()(const Category& left, const Category& right) const; |
86 }; | 95 }; |
87 | 96 |
88 std::ostream& operator<<(std::ostream& os, const Category& obj); | 97 std::ostream& operator<<(std::ostream& os, const Category& obj); |
89 | 98 |
90 } // namespace ntp_snippets | 99 } // namespace ntp_snippets |
91 | 100 |
92 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ | 101 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ |
OLD | NEW |