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; | 12 class CategoryFactory; |
13 | 13 |
14 // These are the categories that the client knows about. | 14 // These are the categories that the client knows about. |
15 // The values before LOCAL_CATEGORIES_COUNT are the categories that are provided | 15 // 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 | 16 // 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 | 17 // than REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need |
18 // to be recognized by the client implementation. | 18 // to be recognized by the client implementation. |
| 19 // NOTE: These are persisted, so don't reorder or remove values, and insert new |
| 20 // values only in the appropriate places marked below. |
19 // On Android builds, a Java counterpart will be generated for this enum. | 21 // On Android builds, a Java counterpart will be generated for this enum. |
20 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets | 22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets |
21 enum class KnownCategories { | 23 enum class KnownCategories { |
22 // Pages recently downloaded during normal navigation. | 24 // Pages recently downloaded during normal navigation. |
23 RECENT_TABS, | 25 RECENT_TABS, |
24 | 26 |
25 // Pages downloaded by the user for offline consumption. | 27 // Pages downloaded by the user for offline consumption. |
26 DOWNLOADS, | 28 DOWNLOADS, |
27 | 29 |
28 // Recently used bookmarks. | 30 // Recently used bookmarks. |
29 BOOKMARKS, | 31 BOOKMARKS, |
30 | 32 |
31 // Physical Web page available in the vicinity. | 33 // Physical Web page available in the vicinity. |
32 PHYSICAL_WEB_PAGES, | 34 PHYSICAL_WEB_PAGES, |
33 | 35 |
34 // Pages recently browsed to on other devices. | 36 // Pages recently browsed to on other devices. |
35 FOREIGN_TABS, | 37 FOREIGN_TABS, |
| 38 // INSERT NEW LOCAL CATEGORIES HERE! |
36 | 39 |
37 // Follows the last local category. | 40 // Follows the last local category. |
38 LOCAL_CATEGORIES_COUNT, | 41 LOCAL_CATEGORIES_COUNT, |
39 | 42 |
40 // Remote categories come after this. | 43 // Remote categories come after this. |
41 REMOTE_CATEGORIES_OFFSET = 10000, | 44 REMOTE_CATEGORIES_OFFSET = 10000, |
42 | 45 |
43 // Articles for you. | 46 // Articles for you. |
44 ARTICLES, | 47 ARTICLES, |
| 48 // INSERT NEW REMOTE CATEGORIES HERE! |
45 }; | 49 }; |
46 | 50 |
47 // A category groups ContentSuggestions which belong together. Use the | 51 // A category groups ContentSuggestions which belong together. Use the |
48 // CategoryFactory to obtain instances. | 52 // CategoryFactory to obtain instances. |
49 class Category { | 53 class Category { |
50 public: | 54 public: |
51 // An arbitrary but consistent ordering. Can be used to look up categories in | 55 // An arbitrary but consistent ordering. Can be used to look up categories in |
52 // a std::map, but should not be used to order categories for other purposes. | 56 // a std::map, but should not be used to order categories for other purposes. |
53 struct CompareByID; | 57 struct CompareByID; |
54 | 58 |
55 // Returns a non-negative identifier that is unique for the category and can | 59 // Returns a non-negative identifier that is unique for the category and can |
56 // be converted back to a Category instance using | 60 // be converted back to a Category instance using |
57 // |CategoryFactory::FromIDValue(id)|. | 61 // |CategoryFactory::FromIDValue(id)|. |
58 // Note that these IDs are not necessarily stable across multiple runs of | |
59 // the application, so they should not be persisted. | |
60 int id() const { return id_; } | 62 int id() const { return id_; } |
61 | 63 |
62 // Returns whether this category matches the given |known_category|. | 64 // Returns whether this category matches the given |known_category|. |
63 bool IsKnownCategory(KnownCategories known_category) const; | 65 bool IsKnownCategory(KnownCategories known_category) const; |
64 | 66 |
65 private: | 67 private: |
66 friend class CategoryFactory; | 68 friend class CategoryFactory; |
67 | 69 |
68 explicit Category(int id); | 70 explicit Category(int id); |
69 | 71 |
70 int id_; | 72 int id_; |
71 | 73 |
72 // Allow copy and assignment. | 74 // Allow copy and assignment. |
73 }; | 75 }; |
74 | 76 |
75 bool operator==(const Category& left, const Category& right); | 77 bool operator==(const Category& left, const Category& right); |
76 | 78 |
77 bool operator!=(const Category& left, const Category& right); | 79 bool operator!=(const Category& left, const Category& right); |
78 | 80 |
79 struct Category::CompareByID { | 81 struct Category::CompareByID { |
80 bool operator()(const Category& left, const Category& right) const; | 82 bool operator()(const Category& left, const Category& right) const; |
81 }; | 83 }; |
82 | 84 |
83 std::ostream& operator<<(std::ostream& os, const Category& obj); | 85 std::ostream& operator<<(std::ostream& os, const Category& obj); |
84 | 86 |
85 } // namespace ntp_snippets | 87 } // namespace ntp_snippets |
86 | 88 |
87 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ | 89 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_H_ |
OLD | NEW |