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

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: Document remote categories order 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. 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,
Bernhard Bauer 2016/07/28 15:39:27 Stupid question: If the local categories are fixed
Philipp Keck 2016/07/28 16:59:58 It's because they're also hard-coded on the server
Marc Treib 2016/07/29 08:20:35 We don't actually need a gap between them - the fi
Philipp Keck 2016/07/29 08:24:28 Right. There is a second reason why it's helpful f
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 int id() const { return id_; }
34
35 bool IsKnownCategory(KnownSuggestionsCategories known_category) const;
36
37 private:
38 friend class ContentSuggestionsCategoryFactory;
39
40 ContentSuggestionsCategory(int id);
41
42 int id_;
Bernhard Bauer 2016/07/28 15:39:26 Nit: It's quite common to add a comment that copyi
Philipp Keck 2016/07/28 16:59:58 I added it, not sure about the wording and locatio
43 };
44
45 bool operator==(const ContentSuggestionsCategory& left,
46 const ContentSuggestionsCategory& right);
47
48 bool operator!=(const ContentSuggestionsCategory& left,
49 const ContentSuggestionsCategory& right);
50
51 std::ostream& operator<<(std::ostream& os,
52 const ContentSuggestionsCategory& obj);
12 53
13 } // namespace ntp_snippets 54 } // namespace ntp_snippets
14 55
15 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_ 56 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698