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

Unified Diff: components/ntp_snippets/content_suggestions_category_factory.h

Issue 2187233002: Add ContentSuggestionsCategoryFactory; Store categories as ints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marc's new comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698