OLD | NEW |
---|---|
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 Loading... | |
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 // 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 // minimize usage of these functions. See crbug.com/649048. | |
Marc Treib
2016/09/22 11:27:06
s/minimize usage of/eliminate/ :)
jkrcal
2016/09/22 12:50:05
Done.
| |
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 | |
46 private: | 64 private: |
47 bool CategoryExists(int id); | 65 bool CategoryExists(int id); |
48 void AddKnownCategory(KnownCategories known_category); | 66 void AddKnownCategory(KnownCategories known_category); |
49 Category InternalFromID(int id); | 67 Category InternalFromID(int id); |
50 | 68 |
51 // Stores all known categories in the order which is also returned by | 69 // Stores all known categories in the order which is also returned by |
52 // |CompareCategories|. | 70 // |CompareCategories|. |
53 std::vector<Category> ordered_categories_; | 71 std::vector<Category> ordered_categories_; |
54 | 72 |
55 DISALLOW_COPY_AND_ASSIGN(CategoryFactory); | 73 DISALLOW_COPY_AND_ASSIGN(CategoryFactory); |
56 }; | 74 }; |
57 | 75 |
58 } // namespace ntp_snippets | 76 } // namespace ntp_snippets |
59 | 77 |
60 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ | 78 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ |
OLD | NEW |