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_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. Those values need to be listed in the |
| 17 // ContentSuggestionsCategoryFactory constructor! |
| 18 // Categories provided by the server (IDs strictly larger than |
| 19 // REMOTE_CATEGORIES_OFFSET) only need to be hard-coded here if they need to be |
| 20 // recognized by the client implementation. |
| 21 enum class KnownSuggestionsCategories { |
| 22 OFFLINE_PAGES, |
| 23 LOCAL_CATEGORIES_COUNT, |
| 24 |
| 25 REMOTE_CATEGORIES_OFFSET = 10000, |
| 26 ARTICLES = REMOTE_CATEGORIES_OFFSET + 1, |
| 27 }; |
| 28 |
| 29 // A category groups ContentSuggestions which belong together. Use the |
| 30 // ContentSuggestionsCategoryFactory to obtain instances. |
| 31 class ContentSuggestionsCategory { |
| 32 public: |
| 33 // Returns a non-negative identifier that is unique for the category and can |
| 34 // be converted back to a ContentSuggestionsCategory instance using |
| 35 // |ContentSuggestionsCategoryFactory::FromIDValue(id)|. |
| 36 // Note that these IDs are not necessarily stable across multiple runs of |
| 37 // the application, so they should not be persisted. |
| 38 int id() const { return id_; } |
| 39 |
| 40 bool IsKnownCategory(KnownSuggestionsCategories known_category) const; |
| 41 |
| 42 private: |
| 43 friend class ContentSuggestionsCategoryFactory; |
| 44 |
| 45 ContentSuggestionsCategory(int id); |
| 46 |
| 47 int id_; |
| 48 |
| 49 // Allow copy and assignment. |
| 50 }; |
| 51 |
| 52 bool operator==(const ContentSuggestionsCategory& left, |
| 53 const ContentSuggestionsCategory& right); |
| 54 |
| 55 bool operator!=(const ContentSuggestionsCategory& left, |
| 56 const ContentSuggestionsCategory& right); |
| 57 |
| 58 std::ostream& operator<<(std::ostream& os, |
| 59 const ContentSuggestionsCategory& obj); |
12 | 60 |
13 } // namespace ntp_snippets | 61 } // namespace ntp_snippets |
14 | 62 |
15 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ | 63 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ |
OLD | NEW |