Index: components/ntp_snippets/content_suggestions_category_factory.h |
diff --git a/components/ntp_snippets/content_suggestions_category_factory.h b/components/ntp_snippets/content_suggestions_category_factory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d734d52a27433f71f03dfe427ef19095fc0af8cf |
--- /dev/null |
+++ b/components/ntp_snippets/content_suggestions_category_factory.h |
@@ -0,0 +1,58 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ |
+#define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ |
+ |
+#include <map> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "components/ntp_snippets/content_suggestions_category.h" |
+ |
+namespace ntp_snippets { |
+ |
+// Creates and orders instances of ContentSuggestionsCategory. |
+class ContentSuggestionsCategoryFactory { |
+ public: |
+ ContentSuggestionsCategoryFactory(); |
+ ~ContentSuggestionsCategoryFactory(); |
+ |
+ // Creates a category from a KnownSuggestionsCategory value. The passed |
+ // |known_category| must not be one of the special values |
+ // (LOCAL_CATEGORIES_COUNT or REMOTE_CATEGORIES_OFFSET). |
+ ContentSuggestionsCategory FromKnownCategory( |
+ KnownSuggestionsCategories known_category); |
+ |
+ // Creates a category from a category ID delivered by the server. |remote_id| |
+ // must be positive. The resulting category will be |
+ // |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
|
+ // a KnownSuggestionsCategory. |
+ ContentSuggestionsCategory FromRemoteCategory(int remote_id); |
+ |
+ // Creates a category from an ID as returned by |
+ // |ContentSuggestionsCategory::id()|. |id| must be a non-negative value. |
+ ContentSuggestionsCategory FromIDValue(int id); |
+ |
+ // Compares the given categories according to a strict ordering, returning |
+ // true if and only if |left| is strictly less than |right|. |
+ // This method satisfies the "Compare" contract required by sort algorithms. |
+ bool CompareCategories(const ContentSuggestionsCategory& left, |
+ const ContentSuggestionsCategory& right) const; |
+ |
+ private: |
+ bool CategoryExists(int id); |
+ void AddKnownCategory(KnownSuggestionsCategories known_category); |
+ ContentSuggestionsCategory InternalFromID(int id); |
+ |
+ // Stores all known categories in the order which is also returned by |
+ // |CompareCategories|. |
+ 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.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsCategoryFactory); |
+}; |
+ |
+} // namespace ntp_snippets |
+ |
+#endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_CATEGORY_FACTORY_H_ |