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/content_suggestions_provider.h" | 5 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | |
| 7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 8 | 9 |
| 9 namespace ntp_snippets { | 10 namespace ntp_snippets { |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 const char kCombinedIDFormat[] = "%d:%s"; | 14 const char kCombinedIDFormat[] = "%d|%s"; |
| 15 const char kSeparator[] = "|"; | |
|
Marc Treib
2016/07/19 12:31:11
Can you make this an actual char, rather than a st
Philipp Keck
2016/07/19 13:02:37
Done.
| |
| 14 | 16 |
| 15 } // namespace | 17 } // namespace |
| 16 | 18 |
| 17 ContentSuggestionsProvider::ContentSuggestionsProvider( | 19 ContentSuggestionsProvider::ContentSuggestionsProvider( |
| 18 const std::vector<ContentSuggestionsCategory>& provided_categories) | 20 const std::vector<ContentSuggestionsCategory>& provided_categories) |
| 19 : provided_categories_(provided_categories) {} | 21 : provided_categories_(provided_categories) {} |
| 20 | 22 |
| 21 ContentSuggestionsProvider::~ContentSuggestionsProvider() {} | 23 ContentSuggestionsProvider::~ContentSuggestionsProvider() {} |
| 22 | 24 |
| 23 std::string ContentSuggestionsProvider::MakeUniqueID( | 25 std::string ContentSuggestionsProvider::MakeUniqueID( |
| 24 ContentSuggestionsCategory category, | 26 ContentSuggestionsCategory category, |
| 25 const std::string& within_category_id) { | 27 const std::string& within_category_id) { |
| 26 return base::StringPrintf(kCombinedIDFormat, | 28 return base::StringPrintf(kCombinedIDFormat, |
| 27 static_cast<int>(category), | 29 static_cast<int>(category), |
| 28 within_category_id.c_str()); | 30 within_category_id.c_str()); |
| 29 } | 31 } |
| 30 | 32 |
| 33 ContentSuggestionsCategory ContentSuggestionsProvider::GetCategoryFromUniqueID( | |
|
Marc Treib
2016/07/19 12:31:11
Add
// static
above, also for the other method bel
Philipp Keck
2016/07/19 13:02:38
Done.
| |
| 34 const std::string& unique_id) { | |
| 35 size_t colon_index = unique_id.find(kSeparator); | |
| 36 DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: " | |
| 37 << unique_id; | |
| 38 int category; | |
| 39 DCHECK(base::StringToInt(unique_id.substr(0, colon_index), &category)) | |
| 40 << "Non-numeric category part in unique_id: " << unique_id; | |
| 41 DCHECK(0 <= category && category < int(ContentSuggestionsCategory::COUNT)) | |
| 42 << "Category does not exist: " << category; | |
| 43 return ContentSuggestionsCategory(category); | |
| 44 } | |
| 45 | |
| 46 std::string ContentSuggestionsProvider::GetWithinCategoryIDFromUniqueID( | |
| 47 const std::string& unique_id) { | |
| 48 size_t colon_index = unique_id.find(kSeparator); | |
| 49 DCHECK_NE(std::string::npos, colon_index) << "Not a valid unique_id: " | |
| 50 << unique_id; | |
| 51 return unique_id.substr(colon_index + 1); | |
| 52 } | |
| 53 | |
| 31 } // namespace ntp_snippets | 54 } // namespace ntp_snippets |
| OLD | NEW |