Index: chrome/browser/ui/webui/snippets_internals_message_handler.cc |
diff --git a/chrome/browser/ui/webui/snippets_internals_message_handler.cc b/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
index 2b0d34c00893831e0b9575e10c9576d59cf97fe1..8e369ffc6f9dc382893be38df6c4ff8c276550a9 100644 |
--- a/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
+++ b/chrome/browser/ui/webui/snippets_internals_message_handler.cc |
@@ -15,12 +15,14 @@ |
#include "base/i18n/time_formatting.h" |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
+#include "base/optional.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_split.h" |
#include "base/values.h" |
#include "chrome/browser/android/chrome_feature_list.h" |
#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "components/ntp_snippets/category_info.h" |
#include "components/ntp_snippets/features.h" |
#include "components/ntp_snippets/ntp_snippet.h" |
#include "components/ntp_snippets/switches.h" |
@@ -28,6 +30,7 @@ |
using ntp_snippets::ContentSuggestion; |
using ntp_snippets::Category; |
+using ntp_snippets::CategoryInfo; |
using ntp_snippets::CategoryStatus; |
using ntp_snippets::KnownCategories; |
@@ -75,20 +78,6 @@ std::unique_ptr<base::DictionaryValue> PrepareSuggestion( |
return entry; |
} |
-// TODO(pke): Replace this as soon as the service delivers the title directly. |
-std::string GetCategoryTitle(Category category) { |
- if (category.IsKnownCategory(KnownCategories::ARTICLES)) { |
- return "Articles"; |
- } |
- if (category.IsKnownCategory(KnownCategories::OFFLINE_PAGES)) { |
- return "Offline pages (continue browsing)"; |
- } |
- if (category.IsKnownCategory(KnownCategories::BOOKMARKS)) { |
- return "Recently visited bookmarks"; |
- } |
- return std::string(); |
-} |
- |
std::string GetCategoryStatusName(CategoryStatus status) { |
switch (status) { |
case CategoryStatus::INITIALIZING: |
@@ -327,8 +316,12 @@ void SnippetsInternalsMessageHandler::SendContentSuggestions() { |
for (Category category : content_suggestions_service_->GetCategories()) { |
CategoryStatus status = |
content_suggestions_service_->GetCategoryStatus(category); |
+ base::Optional<CategoryInfo> info = |
+ content_suggestions_service_->GetCategoryInfo(category); |
const std::vector<ContentSuggestion>& suggestions = |
content_suggestions_service_->GetSuggestionsForCategory(category); |
+ if (!info) |
Bernhard Bauer
2016/08/09 09:18:33
This shouldn't really happen if we're iterating ov
Bernhard Bauer
2016/08/09 12:38:39
^^^
Philipp Keck
2016/08/09 12:45:14
Done.
|
+ continue; |
std::unique_ptr<base::ListValue> suggestions_list(new base::ListValue); |
for (const ContentSuggestion& suggestion : suggestions) { |
@@ -337,7 +330,7 @@ void SnippetsInternalsMessageHandler::SendContentSuggestions() { |
std::unique_ptr<base::DictionaryValue> category_entry( |
new base::DictionaryValue); |
- category_entry->SetString("title", GetCategoryTitle(category)); |
+ category_entry->SetString("title", info->title()); |
category_entry->SetString("status", GetCategoryStatusName(status)); |
category_entry->Set("suggestions", std::move(suggestions_list)); |
categories_list->Append(std::move(category_entry)); |