Chromium Code Reviews| 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.h" | 5 #include "components/ntp_snippets/category.h" |
| 6 | 6 |
| 7 namespace ntp_snippets { | 7 namespace ntp_snippets { |
| 8 | 8 |
| 9 Category::Category(int id) : id_(id) {} | 9 Category::Category(int id) : id_(id) {} |
| 10 | 10 |
| 11 bool Category::IsKnownCategory(KnownCategories known_category) const { | 11 bool Category::IsKnownCategory(KnownCategories known_category) const { |
| 12 return id_ == static_cast<int>(known_category); | 12 return id_ == static_cast<int>(known_category); |
| 13 } | 13 } |
| 14 | 14 |
| 15 bool Category::IsAnyKnownCategory() const { | |
| 16 static const int kKnownCategoryIds[] = { | |
| 17 static_cast<int>(KnownCategories::RECENT_TABS), | |
| 18 static_cast<int>(KnownCategories::DOWNLOADS), | |
| 19 static_cast<int>(KnownCategories::BOOKMARKS), | |
| 20 static_cast<int>(KnownCategories::PHYSICAL_WEB_PAGES), | |
| 21 static_cast<int>(KnownCategories::ARTICLES)}; | |
|
jkrcal
2016/09/13 16:08:05
I am just wondering:
Cannot you add to the enum c
Marc Treib
2016/09/13 16:28:50
SERVER_CATEGORIES_MAX would actually have to be KN
jkrcal
2016/09/13 17:22:27
How come? Is it because we can introduce some cate
tschumann
2016/09/14 08:41:35
Joining this discussion as a by-stander. Given tha
Marc Treib
2016/09/14 08:42:20
Say the server adds categories 2 and 3. Later, we
| |
| 22 for (int known_category_id : kKnownCategoryIds) { | |
| 23 if (id_ == known_category_id) | |
| 24 return true; | |
| 25 } | |
| 26 return false; | |
| 27 } | |
| 28 | |
| 15 bool operator==(const Category& left, const Category& right) { | 29 bool operator==(const Category& left, const Category& right) { |
| 16 return left.id() == right.id(); | 30 return left.id() == right.id(); |
| 17 } | 31 } |
| 18 | 32 |
| 19 bool operator!=(const Category& left, const Category& right) { | 33 bool operator!=(const Category& left, const Category& right) { |
| 20 return !(left == right); | 34 return !(left == right); |
| 21 } | 35 } |
| 22 | 36 |
| 23 bool Category::CompareByID::operator()(const Category& left, | 37 bool Category::CompareByID::operator()(const Category& left, |
| 24 const Category& right) const { | 38 const Category& right) const { |
| 25 return left.id() < right.id(); | 39 return left.id() < right.id(); |
| 26 } | 40 } |
| 27 | 41 |
| 28 std::ostream& operator<<(std::ostream& os, const Category& obj) { | 42 std::ostream& operator<<(std::ostream& os, const Category& obj) { |
| 29 os << obj.id(); | 43 os << obj.id(); |
| 30 return os; | 44 return os; |
| 31 } | 45 } |
| 32 | 46 |
| 33 } // namespace ntp_snippets | 47 } // namespace ntp_snippets |
| OLD | NEW |