| 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 | 10 |
| 11 namespace ntp_snippets { | 11 namespace ntp_snippets { |
| 12 | 12 |
| 13 CategoryFactory::CategoryFactory() { | 13 CategoryFactory::CategoryFactory() { |
| 14 // Add all local categories in a fixed order. | 14 // Add all local categories in a fixed order. |
| 15 AddKnownCategory(KnownCategories::DOWNLOADS); | 15 AddKnownCategory(KnownCategories::DOWNLOADS); |
| 16 AddKnownCategory(KnownCategories::RECENT_TABS); | 16 AddKnownCategory(KnownCategories::RECENT_TABS); |
| 17 AddKnownCategory(KnownCategories::FOREIGN_TABS); | 17 AddKnownCategory(KnownCategories::FOREIGN_TABS); |
| 18 AddKnownCategory(KnownCategories::BOOKMARKS); | 18 AddKnownCategory(KnownCategories::BOOKMARKS); |
| 19 AddKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES); | 19 AddKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES); |
| 20 | 20 |
| 21 DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT), | 21 DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT), |
| 22 ordered_categories_.size()); | 22 ordered_categories_.size()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 CategoryFactory::~CategoryFactory() {} | 25 CategoryFactory::~CategoryFactory() = default; |
| 26 | 26 |
| 27 Category CategoryFactory::FromKnownCategory(KnownCategories known_category) { | 27 Category CategoryFactory::FromKnownCategory(KnownCategories known_category) { |
| 28 if (known_category < KnownCategories::LOCAL_CATEGORIES_COUNT) { | 28 if (known_category < KnownCategories::LOCAL_CATEGORIES_COUNT) { |
| 29 // Local categories should have been added already. | 29 // Local categories should have been added already. |
| 30 DCHECK(CategoryExists(static_cast<int>(known_category))); | 30 DCHECK(CategoryExists(static_cast<int>(known_category))); |
| 31 } else { | 31 } else { |
| 32 DCHECK_GT(known_category, KnownCategories::REMOTE_CATEGORIES_OFFSET); | 32 DCHECK_GT(known_category, KnownCategories::REMOTE_CATEGORIES_OFFSET); |
| 33 } | 33 } |
| 34 return InternalFromID(static_cast<int>(known_category)); | 34 return InternalFromID(static_cast<int>(known_category)); |
| 35 } | 35 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 Category(id)); | 74 Category(id)); |
| 75 if (it != ordered_categories_.end()) | 75 if (it != ordered_categories_.end()) |
| 76 return *it; | 76 return *it; |
| 77 | 77 |
| 78 Category category(id); | 78 Category category(id); |
| 79 ordered_categories_.push_back(category); | 79 ordered_categories_.push_back(category); |
| 80 return category; | 80 return category; |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace ntp_snippets | 83 } // namespace ntp_snippets |
| OLD | NEW |