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

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

Issue 2377663002: [NTP Snippets] Introduce ContentSuggestion::ID (Closed)
Patch Set: rebase Created 4 years, 2 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 <string>
10 #include <vector> 10 #include <vector>
(...skipping 26 matching lines...) Expand all
37 37
38 // Compares the given categories according to a strict ordering, returning 38 // Compares the given categories according to a strict ordering, returning
39 // true if and only if |left| is strictly less than |right|. 39 // true if and only if |left| is strictly less than |right|.
40 // This method satisfies the "Compare" contract required by sort algorithms. 40 // This method satisfies the "Compare" contract required by sort algorithms.
41 // 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
42 // specific order hard-coded in the |CategoryFactory| constructor. All remote 42 // specific order hard-coded in the |CategoryFactory| constructor. All remote
43 // 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
44 // |FromRemoteCategory|. 44 // |FromRemoteCategory|.
45 bool CompareCategories(const Category& left, const Category& right) const; 45 bool CompareCategories(const Category& left, const Category& right) const;
46 46
47 // TODO(treib): Remove the following 3 functions from here once we move to a
48 // more structured identification than the unique_id string and thus once we
49 // eliminate these functions. See crbug.com/649048.
50
51 // Creates a unique ID. The given |within_category_id| must be unique among
52 // all suggestion IDs from this provider for the given |category|. This method
53 // combines it with the |category| to form an ID that is unique
54 // application-wide, because this provider is the only one that provides
55 // suggestions for that category.
56 std::string MakeUniqueID(Category category,
57 const std::string& within_category_id) const;
58
59 // Reverse functions for MakeUniqueID()
60 Category GetCategoryFromUniqueID(const std::string& unique_id);
61 std::string GetWithinCategoryIDFromUniqueID(
62 const std::string& unique_id) const;
63
64 private: 47 private:
65 bool CategoryExists(int id); 48 bool CategoryExists(int id);
66 void AddKnownCategory(KnownCategories known_category); 49 void AddKnownCategory(KnownCategories known_category);
67 Category InternalFromID(int id); 50 Category InternalFromID(int id);
68 51
69 // Stores all known categories in the order which is also returned by 52 // Stores all known categories in the order which is also returned by
70 // |CompareCategories|. 53 // |CompareCategories|.
71 std::vector<Category> ordered_categories_; 54 std::vector<Category> ordered_categories_;
72 55
73 DISALLOW_COPY_AND_ASSIGN(CategoryFactory); 56 DISALLOW_COPY_AND_ASSIGN(CategoryFactory);
74 }; 57 };
75 58
76 } // namespace ntp_snippets 59 } // namespace ntp_snippets
77 60
78 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ 61 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc ('k') | components/ntp_snippets/category_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698