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

Side by Side Diff: components/ntp_snippets/category_factory.h

Issue 2355393002: New snippets now replace old snippets and do not merge (Closed)
Patch Set: Created 4 years, 3 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_CATEGORY_FACTORY_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_
6 #define COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "components/ntp_snippets/category.h" 13 #include "components/ntp_snippets/category.h"
13 14
14 namespace ntp_snippets { 15 namespace ntp_snippets {
15 16
16 // Creates and orders Category instances. 17 // Creates and orders Category instances.
17 class CategoryFactory { 18 class CategoryFactory {
18 public: 19 public:
(...skipping 17 matching lines...) Expand all
36 37
37 // Compares the given categories according to a strict ordering, returning 38 // Compares the given categories according to a strict ordering, returning
38 // true if and only if |left| is strictly less than |right|. 39 // true if and only if |left| is strictly less than |right|.
39 // This method satisfies the "Compare" contract required by sort algorithms. 40 // This method satisfies the "Compare" contract required by sort algorithms.
40 // The order is determined as follows: All local categories go first, in a 41 // The order is determined as follows: All local categories go first, in a
41 // specific order hard-coded in the |CategoryFactory| constructor. All remote 42 // specific order hard-coded in the |CategoryFactory| constructor. All remote
42 // categories follow in the order in which they were first created through 43 // categories follow in the order in which they were first created through
43 // |FromRemoteCategory|. 44 // |FromRemoteCategory|.
44 bool CompareCategories(const Category& left, const Category& right) const; 45 bool CompareCategories(const Category& left, const Category& right) const;
45 46
47 // Creates a unique ID. The given |within_category_id| must be unique among
48 // all suggestion IDs from this provider for the given |category|. This method
49 // combines it with the |category| to form an ID that is unique
50 // application-wide, because this provider is the only one that provides
51 // suggestions for that category.
52 std::string MakeUniqueID(Category category,
53 const std::string& within_category_id) const;
54
55 // Reverse functions for MakeUniqueID()
56 Category GetCategoryFromUniqueID(const std::string& unique_id);
57 std::string GetWithinCategoryIDFromUniqueID(
58 const std::string& unique_id) const;
59
46 private: 60 private:
47 bool CategoryExists(int id); 61 bool CategoryExists(int id);
48 void AddKnownCategory(KnownCategories known_category); 62 void AddKnownCategory(KnownCategories known_category);
49 Category InternalFromID(int id); 63 Category InternalFromID(int id);
50 64
51 // Stores all known categories in the order which is also returned by 65 // Stores all known categories in the order which is also returned by
52 // |CompareCategories|. 66 // |CompareCategories|.
53 std::vector<Category> ordered_categories_; 67 std::vector<Category> ordered_categories_;
54 68
55 DISALLOW_COPY_AND_ASSIGN(CategoryFactory); 69 DISALLOW_COPY_AND_ASSIGN(CategoryFactory);
56 }; 70 };
57 71
58 } // namespace ntp_snippets 72 } // namespace ntp_snippets
59 73
60 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ 74 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/category_factory.cc » ('j') | components/ntp_snippets/content_suggestions_provider.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698