OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ | |
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "components/ntp_snippets/content_suggestions_category.h" | |
13 | |
14 namespace ntp_snippets { | |
15 | |
16 // Creates and orders instances of ContentSuggestionsCategory. | |
17 class ContentSuggestionsCategoryFactory { | |
18 public: | |
19 ContentSuggestionsCategoryFactory(); | |
20 ~ContentSuggestionsCategoryFactory(); | |
21 | |
22 // Creates a category from a KnownSuggestionsCategory value. The passed | |
23 // |known_category| must not be one of the special values | |
24 // (LOCAL_CATEGORIES_COUNT or REMOTE_CATEGORIES_OFFSET). | |
25 ContentSuggestionsCategory FromKnownCategory( | |
26 KnownSuggestionsCategories known_category); | |
27 | |
28 // Creates a category from a category ID delivered by the server. |remote_id| | |
29 // must be positive. The resulting category will be | |
30 // |REMOTE_CATEGORIES_OFFSET + remote_id|. It may, but does not have to match | |
tschumann
2016/07/28 15:36:10
IMO, the factory should not document this detail (
Philipp Keck
2016/07/28 16:59:58
Yeah, this might be the wrong place to document th
tschumann
2016/07/28 17:05:16
Thanks. Arguable the enum constant values should a
| |
31 // a KnownSuggestionsCategory. | |
32 ContentSuggestionsCategory FromRemoteCategory(int remote_id); | |
33 | |
34 // Creates a category from an ID as returned by | |
35 // |ContentSuggestionsCategory::id()|. |id| must be a non-negative value. | |
36 ContentSuggestionsCategory FromIDValue(int id); | |
37 | |
38 // Compares the given categories according to a strict ordering, returning | |
39 // true if and only if |left| is strictly less than |right|. | |
40 // This method satisfies the "Compare" contract required by sort algorithms. | |
41 bool CompareCategories(const ContentSuggestionsCategory& left, | |
42 const ContentSuggestionsCategory& right) const; | |
43 | |
44 private: | |
45 bool CategoryExists(int id); | |
46 void AddKnownCategory(KnownSuggestionsCategories known_category); | |
47 ContentSuggestionsCategory InternalFromID(int id); | |
48 | |
49 // Stores all known categories in the order which is also returned by | |
50 // |CompareCategories|. | |
51 std::vector<ContentSuggestionsCategory> categories_; | |
tschumann
2016/07/28 15:36:10
should we rename this to ordered_categories_? Just
Philipp Keck
2016/07/28 16:59:58
Done.
| |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsCategoryFactory); | |
54 }; | |
55 | |
56 } // namespace ntp_snippets | |
57 | |
58 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ | |
OLD | NEW |