| 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 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace ntp_snippets { | 9 namespace ntp_snippets { |
| 10 | 10 |
| 11 // static | 11 // static |
| 12 Category Category::FromKnownCategory(KnownCategories known_category) { | 12 Category Category::FromKnownCategory(KnownCategories known_category) { |
| 13 return FromIDValue(static_cast<int>(known_category)); | 13 return FromIDValue(static_cast<int>(known_category)); |
| 14 } | 14 } |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 Category Category::FromRemoteCategory(int remote_category) { | 17 Category Category::FromRemoteCategory(int remote_category) { |
| 18 DCHECK_GT(remote_category, 0); | 18 DCHECK_GT(remote_category, 0); |
| 19 return Category(static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET) + | 19 return Category(static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET) + |
| 20 remote_category); | 20 remote_category); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 Category Category::FromIDValue(int id) { | 24 Category Category::FromIDValue(int id) { |
| 25 DCHECK(IsValidIDValue(id)) << "Not a valid ID: " << id; | 25 DCHECK(IsValidIDValue(id)) << id << " is not a valid category ID. This may " |
| 26 "have been caused by removal of a local " |
| 27 "KnownCategory."; |
| 26 return Category(id); | 28 return Category(id); |
| 27 } | 29 } |
| 28 | 30 |
| 29 // static | 31 // static |
| 30 bool Category::IsValidIDValue(int id) { | 32 bool Category::IsValidIDValue(int id) { |
| 31 return (id >= 0) && | 33 return (id >= 0) && |
| 32 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || | 34 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || |
| 33 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); | 35 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); |
| 34 } | 36 } |
| 35 | 37 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 const Category& right) const { | 55 const Category& right) const { |
| 54 return left.id() < right.id(); | 56 return left.id() < right.id(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 std::ostream& operator<<(std::ostream& os, const Category& obj) { | 59 std::ostream& operator<<(std::ostream& os, const Category& obj) { |
| 58 os << obj.id(); | 60 os << obj.id(); |
| 59 return os; | 61 return os; |
| 60 } | 62 } |
| 61 | 63 |
| 62 } // namespace ntp_snippets | 64 } // namespace ntp_snippets |
| OLD | NEW |