| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ | |
| 6 #define COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "components/ntp_snippets/category.h" | |
| 14 | |
| 15 namespace ntp_snippets { | |
| 16 | |
| 17 // Creates and orders Category instances. | |
| 18 class CategoryFactory { | |
| 19 public: | |
| 20 CategoryFactory(); | |
| 21 ~CategoryFactory(); | |
| 22 | |
| 23 // Creates a category from a KnownCategory value. The passed |known_category| | |
| 24 // must not be one of the special values (LOCAL_CATEGORIES_COUNT or | |
| 25 // REMOTE_CATEGORIES_OFFSET). | |
| 26 Category FromKnownCategory(KnownCategories known_category); | |
| 27 | |
| 28 // Creates a category from a category identifier delivered by the server. | |
| 29 // |remote_category| must be positive. | |
| 30 // Note that remote categories are ordered in the order in which they were | |
| 31 // first created by calling this method. | |
| 32 Category FromRemoteCategory(int remote_category); | |
| 33 | |
| 34 // Creates a category from an ID as returned by |Category::id()|. | |
| 35 // |id| must be a non-negative value. | |
| 36 Category FromIDValue(int id); | |
| 37 | |
| 38 // Compares the given categories according to a strict ordering, returning | |
| 39 // true if and only if |left| is strictly less than |right|. | |
| 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 | |
| 42 // specific order hard-coded in the |CategoryFactory| constructor. All remote | |
| 43 // categories follow in the order in which they were first created through | |
| 44 // |FromRemoteCategory|. | |
| 45 bool CompareCategories(const Category& left, const Category& right) const; | |
| 46 | |
| 47 private: | |
| 48 bool CategoryExists(int id); | |
| 49 void AddKnownCategory(KnownCategories known_category); | |
| 50 Category InternalFromID(int id); | |
| 51 | |
| 52 // Stores all known categories in the order which is also returned by | |
| 53 // |CompareCategories|. | |
| 54 std::vector<Category> ordered_categories_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(CategoryFactory); | |
| 57 }; | |
| 58 | |
| 59 } // namespace ntp_snippets | |
| 60 | |
| 61 #endif // COMPONENTS_NTP_SNIPPETS_CATEGORY_FACTORY_H_ | |
| OLD | NEW |