| 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)) << id << " is not a valid category ID. This may " | 25 DCHECK(IsValidIDValue(id)) << id |
| 26 "have been caused by removal of a local " | 26 << " is not a valid category ID. This may have " |
| 27 "KnownCategory."; | 27 "been caused by removal of a local " |
| 28 "KnownCategory."; |
| 28 return Category(id); | 29 return Category(id); |
| 29 } | 30 } |
| 30 | 31 |
| 31 // static | 32 // static |
| 32 bool Category::IsValidIDValue(int id) { | 33 bool Category::IsValidIDValue(int id) { |
| 33 return (id >= 0) && | 34 return (id >= 0) && |
| 34 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || | 35 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || |
| 35 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); | 36 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); |
| 36 } | 37 } |
| 37 | 38 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 const Category& right) const { | 56 const Category& right) const { |
| 56 return left.id() < right.id(); | 57 return left.id() < right.id(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 std::ostream& operator<<(std::ostream& os, const Category& obj) { | 60 std::ostream& operator<<(std::ostream& os, const Category& obj) { |
| 60 os << obj.id(); | 61 os << obj.id(); |
| 61 return os; | 62 return os; |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace ntp_snippets | 65 } // namespace ntp_snippets |
| OLD | NEW |