| 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 #include "components/ntp_snippets/category_factory.h" | 5 #include "components/ntp_snippets/category_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 | 12 |
| 13 namespace ntp_snippets { | 13 namespace ntp_snippets { |
| 14 | 14 |
| 15 CategoryFactory::CategoryFactory() { | 15 CategoryFactory::CategoryFactory() { |
| 16 // Add all local categories in a fixed order. | 16 // Add all local categories in a fixed order. |
| 17 AddKnownCategory(KnownCategories::DOWNLOADS); | 17 AddKnownCategory(KnownCategories::DOWNLOADS); |
| 18 AddKnownCategory(KnownCategories::RECENT_TABS); | 18 AddKnownCategory(KnownCategories::RECENT_TABS); |
| 19 AddKnownCategory(KnownCategories::FOREIGN_TABS); | 19 AddKnownCategory(KnownCategories::FOREIGN_TABS); |
| 20 AddKnownCategory(KnownCategories::BOOKMARKS); | 20 AddKnownCategory(KnownCategories::BOOKMARKS); |
| 21 AddKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES); | 21 AddKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES); |
| 22 | 22 |
| 23 DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT), | 23 DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT), |
| 24 ordered_categories_.size()); | 24 ordered_categories_.size()); |
| 25 |
| 26 // Known remote categories come after. Other remote categories will be ordered |
| 27 // after these depending on when providers notify us about a related change. |
| 28 AddKnownCategory(KnownCategories::ARTICLES); |
| 25 } | 29 } |
| 26 | 30 |
| 27 CategoryFactory::~CategoryFactory() = default; | 31 CategoryFactory::~CategoryFactory() = default; |
| 28 | 32 |
| 29 Category CategoryFactory::FromKnownCategory(KnownCategories known_category) { | 33 Category CategoryFactory::FromKnownCategory(KnownCategories known_category) { |
| 30 if (known_category < KnownCategories::LOCAL_CATEGORIES_COUNT) { | 34 if (known_category < KnownCategories::LOCAL_CATEGORIES_COUNT) { |
| 31 // Local categories should have been added already. | 35 // Local categories should have been added already. |
| 32 DCHECK(CategoryExists(static_cast<int>(known_category))); | 36 DCHECK(CategoryExists(static_cast<int>(known_category))); |
| 33 } else { | 37 } else { |
| 34 DCHECK_GT(known_category, KnownCategories::REMOTE_CATEGORIES_OFFSET); | 38 DCHECK_GT(known_category, KnownCategories::REMOTE_CATEGORIES_OFFSET); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 Category(id)); | 80 Category(id)); |
| 77 if (it != ordered_categories_.end()) | 81 if (it != ordered_categories_.end()) |
| 78 return *it; | 82 return *it; |
| 79 | 83 |
| 80 Category category(id); | 84 Category category(id); |
| 81 ordered_categories_.push_back(category); | 85 ordered_categories_.push_back(category); |
| 82 return category; | 86 return category; |
| 83 } | 87 } |
| 84 | 88 |
| 85 } // namespace ntp_snippets | 89 } // namespace ntp_snippets |
| OLD | NEW |