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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 struct CompareByID; | 58 struct CompareByID; |
61 | 59 |
62 // Returns a non-negative identifier that is unique for the category and can | 60 // Returns a non-negative identifier that is unique for the category and can |
63 // be converted back to a Category instance using | 61 // be converted back to a Category instance using |
64 // |CategoryFactory::FromIDValue(id)|. | 62 // |CategoryFactory::FromIDValue(id)|. |
65 int id() const { return id_; } | 63 int id() const { return id_; } |
66 | 64 |
67 // Returns whether this category matches the given |known_category|. | 65 // Returns whether this category matches the given |known_category|. |
68 bool IsKnownCategory(KnownCategories known_category) const; | 66 bool IsKnownCategory(KnownCategories known_category) const; |
69 | 67 |
68 // Creates a category from a KnownCategory value. The passed |known_category| | |
69 // must not be one of the special values (LOCAL_CATEGORIES_COUNT or | |
70 // REMOTE_CATEGORIES_OFFSET). | |
71 static Category FromKnownCategory(KnownCategories known_category); | |
72 | |
73 // Creates a category from a category identifier delivered by the server. | |
74 // |remote_category| must be positive. | |
75 static Category FromRemoteCategory(int remote_category); | |
76 | |
77 // Creates a category from an ID as returned by |Category::id()|. | |
Marc Treib
2016/12/13 12:22:42
nit: "Category::" isn't required
vitaliii
2016/12/14 08:59:38
Done.
| |
78 // |id| must be a non-negative value. | |
79 static Category FromIDValue(int id); | |
Marc Treib
2016/12/13 12:22:42
nit: Move all the static "create" methods to the t
vitaliii
2016/12/14 08:59:38
Done.
| |
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 |