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 "chrome/browser/ui/webui/snippets_internals_message_handler.h" | 5 #include "chrome/browser/ui/webui/snippets_internals_message_handler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | 22 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 23 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" | 23 #include "chrome/browser/ntp_snippets/ntp_snippets_service_factory.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "components/ntp_snippets/ntp_snippet.h" | 25 #include "components/ntp_snippets/ntp_snippet.h" |
| 26 #include "components/ntp_snippets/switches.h" | 26 #include "components/ntp_snippets/switches.h" |
| 27 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
| 28 | 28 |
| 29 using ntp_snippets::ContentSuggestion; | 29 using ntp_snippets::ContentSuggestion; |
| 30 using ntp_snippets::ContentSuggestionsCategory; | 30 using ntp_snippets::ContentSuggestionsCategory; |
| 31 using ntp_snippets::ContentSuggestionsCategoryStatus; | 31 using ntp_snippets::ContentSuggestionsCategoryStatus; |
| 32 using ntp_snippets::KnownSuggestionsCategories; | |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 std::unique_ptr<base::DictionaryValue> PrepareSnippet( | 36 std::unique_ptr<base::DictionaryValue> PrepareSnippet( |
| 36 const ntp_snippets::NTPSnippet& snippet, | 37 const ntp_snippets::NTPSnippet& snippet, |
| 37 int index, | 38 int index, |
| 38 bool dismissed) { | 39 bool dismissed) { |
| 39 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 40 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 40 entry->SetString("snippetId", snippet.id()); | 41 entry->SetString("snippetId", snippet.id()); |
| 41 entry->SetString("title", snippet.title()); | 42 entry->SetString("title", snippet.title()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 67 entry->SetString("ampUrl", suggestion.amp_url().spec()); | 68 entry->SetString("ampUrl", suggestion.amp_url().spec()); |
| 68 entry->SetString("title", suggestion.title()); | 69 entry->SetString("title", suggestion.title()); |
| 69 entry->SetString("snippetText", suggestion.snippet_text()); | 70 entry->SetString("snippetText", suggestion.snippet_text()); |
| 70 entry->SetString("publishDate", | 71 entry->SetString("publishDate", |
| 71 TimeFormatShortDateAndTime(suggestion.publish_date())); | 72 TimeFormatShortDateAndTime(suggestion.publish_date())); |
| 72 entry->SetString("publisherName", suggestion.publisher_name()); | 73 entry->SetString("publisherName", suggestion.publisher_name()); |
| 73 entry->SetString("id", "content-suggestion-" + base::IntToString(index)); | 74 entry->SetString("id", "content-suggestion-" + base::IntToString(index)); |
| 74 return entry; | 75 return entry; |
| 75 } | 76 } |
| 76 | 77 |
| 77 std::string MapCategoryName(ContentSuggestionsCategory category) { | 78 std::string MapCategoryName(ContentSuggestionsCategory category) { |
|
Marc Treib
2016/07/28 11:41:45
Should this be called GetCategoryName? Not sure wh
Philipp Keck
2016/07/28 13:50:53
Done. GetCategoryTitle.
Marc Treib
2016/07/28 14:31:16
It's not actually the title though, it's just a de
| |
| 78 switch (category) { | 79 // TODO(pke): Replace this with the category's title. |
|
Marc Treib
2016/07/28 11:41:45
I guess this should be a comment on the function?
Philipp Keck
2016/07/28 13:50:53
Done.
| |
| 79 case ContentSuggestionsCategory::ARTICLES: | 80 if (category == KnownSuggestionsCategories::ARTICLES) { |
| 80 return "Articles"; | 81 return "Articles"; |
| 81 case ContentSuggestionsCategory::OFFLINE_PAGES: | 82 } |
| 82 return "Offline pages (continue browsing)"; | 83 if (category == KnownSuggestionsCategories::OFFLINE_PAGES) { |
| 83 case ContentSuggestionsCategory::COUNT: | 84 return "Offline pages (continue browsing)"; |
| 84 NOTREACHED() << "Category::COUNT must not be used as a value"; | |
| 85 } | 85 } |
| 86 return std::string(); | 86 return std::string(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::string MapCategoryStatus(ContentSuggestionsCategoryStatus status) { | 89 std::string MapCategoryStatus(ContentSuggestionsCategoryStatus status) { |
|
Marc Treib
2016/07/28 11:41:45
Similar here - GetCategoryStatusName?
Philipp Keck
2016/07/28 13:50:53
Done.
| |
| 90 switch (status) { | 90 switch (status) { |
| 91 case ContentSuggestionsCategoryStatus::INITIALIZING: | 91 case ContentSuggestionsCategoryStatus::INITIALIZING: |
| 92 return "INITIALIZING"; | 92 return "INITIALIZING"; |
| 93 case ContentSuggestionsCategoryStatus::AVAILABLE: | 93 case ContentSuggestionsCategoryStatus::AVAILABLE: |
| 94 return "AVAILABLE"; | 94 return "AVAILABLE"; |
| 95 case ContentSuggestionsCategoryStatus::AVAILABLE_LOADING: | 95 case ContentSuggestionsCategoryStatus::AVAILABLE_LOADING: |
| 96 return "AVAILABLE_LOADING"; | 96 return "AVAILABLE_LOADING"; |
| 97 case ContentSuggestionsCategoryStatus::NOT_PROVIDED: | 97 case ContentSuggestionsCategoryStatus::NOT_PROVIDED: |
| 98 return "NOT_PROVIDED"; | 98 return "NOT_PROVIDED"; |
| 99 case ContentSuggestionsCategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED: | 99 case ContentSuggestionsCategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED: |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 } | 374 } |
| 375 | 375 |
| 376 void SnippetsInternalsMessageHandler::SendString(const std::string& name, | 376 void SnippetsInternalsMessageHandler::SendString(const std::string& name, |
| 377 const std::string& value) { | 377 const std::string& value) { |
| 378 base::StringValue string_name(name); | 378 base::StringValue string_name(name); |
| 379 base::StringValue string_value(value); | 379 base::StringValue string_value(value); |
| 380 | 380 |
| 381 web_ui()->CallJavascriptFunctionUnsafe( | 381 web_ui()->CallJavascriptFunctionUnsafe( |
| 382 "chrome.SnippetsInternals.receiveProperty", string_name, string_value); | 382 "chrome.SnippetsInternals.receiveProperty", string_name, string_value); |
| 383 } | 383 } |
| OLD | NEW |