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 #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)) |
| 26 << "Not a valid ID: " << id | |
| 27 << " Note that local categories must not be removed. This can happen if " | |
| 28 "you switch out of a branch with a new local category."; | |
|
vitaliii
2017/02/08 08:40:35
I have multiple concerns regarding this message:
1
jkrcal
2017/02/08 10:12:05
Done.
| |
| 26 return Category(id); | 29 return Category(id); |
| 27 } | 30 } |
| 28 | 31 |
| 29 // static | 32 // static |
| 30 bool Category::IsValidIDValue(int id) { | 33 bool Category::IsValidIDValue(int id) { |
| 31 return (id >= 0) && | 34 return (id >= 0) && |
| 32 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || | 35 ((id < static_cast<int>(KnownCategories::LOCAL_CATEGORIES_COUNT) || |
| 33 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); | 36 id > static_cast<int>(KnownCategories::REMOTE_CATEGORIES_OFFSET))); |
| 34 } | 37 } |
| 35 | 38 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 53 const Category& right) const { | 56 const Category& right) const { |
| 54 return left.id() < right.id(); | 57 return left.id() < right.id(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 std::ostream& operator<<(std::ostream& os, const Category& obj) { | 60 std::ostream& operator<<(std::ostream& os, const Category& obj) { |
| 58 os << obj.id(); | 61 os << obj.id(); |
| 59 return os; | 62 return os; |
| 60 } | 63 } |
| 61 | 64 |
| 62 } // namespace ntp_snippets | 65 } // namespace ntp_snippets |
| OLD | NEW |