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 <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
16 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/optional.h" | 19 #include "base/optional.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 22 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "base/values.h" | 24 #include "base/values.h" |
24 #include "chrome/browser/android/chrome_feature_list.h" | 25 #include "chrome/browser/android/chrome_feature_list.h" |
25 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | 26 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/common/chrome_features.h" | 28 #include "chrome/common/chrome_features.h" |
28 #include "components/ntp_snippets/category.h" | 29 #include "components/ntp_snippets/category.h" |
29 #include "components/ntp_snippets/category_info.h" | 30 #include "components/ntp_snippets/category_info.h" |
30 #include "components/ntp_snippets/features.h" | 31 #include "components/ntp_snippets/features.h" |
31 #include "components/ntp_snippets/pref_names.h" | 32 #include "components/ntp_snippets/pref_names.h" |
(...skipping 17 matching lines...) Expand all Loading... |
49 std::unique_ptr<base::DictionaryValue> PrepareSuggestion( | 50 std::unique_ptr<base::DictionaryValue> PrepareSuggestion( |
50 const ContentSuggestion& suggestion, | 51 const ContentSuggestion& suggestion, |
51 int index) { | 52 int index) { |
52 auto entry = base::MakeUnique<base::DictionaryValue>(); | 53 auto entry = base::MakeUnique<base::DictionaryValue>(); |
53 entry->SetString("idWithinCategory", suggestion.id().id_within_category()); | 54 entry->SetString("idWithinCategory", suggestion.id().id_within_category()); |
54 entry->SetString("url", suggestion.url().spec()); | 55 entry->SetString("url", suggestion.url().spec()); |
55 entry->SetString("title", suggestion.title()); | 56 entry->SetString("title", suggestion.title()); |
56 entry->SetString("snippetText", suggestion.snippet_text()); | 57 entry->SetString("snippetText", suggestion.snippet_text()); |
57 entry->SetString("publishDate", | 58 entry->SetString("publishDate", |
58 TimeFormatShortDateAndTime(suggestion.publish_date())); | 59 TimeFormatShortDateAndTime(suggestion.publish_date())); |
| 60 entry->SetString("fetchDate", |
| 61 TimeFormatShortDateAndTime(suggestion.fetch_date())); |
59 entry->SetString("publisherName", suggestion.publisher_name()); | 62 entry->SetString("publisherName", suggestion.publisher_name()); |
60 entry->SetString("id", "content-suggestion-" + base::IntToString(index)); | 63 entry->SetString("id", "content-suggestion-" + base::IntToString(index)); |
| 64 entry->SetDouble("score", suggestion.score()); |
| 65 |
| 66 if (suggestion.download_suggestion_extra()) { |
| 67 const auto& extra = *suggestion.download_suggestion_extra(); |
| 68 auto value = base::MakeUnique<base::DictionaryValue>(); |
| 69 value->SetString("downloadGUID", extra.download_guid); |
| 70 value->SetString("targetFilePath", |
| 71 extra.target_file_path.LossyDisplayName()); |
| 72 value->SetString("mimeType", extra.mime_type); |
| 73 value->SetString( |
| 74 "offlinePageID", |
| 75 base::StringPrintf("0x%016llx", static_cast<long long unsigned int>( |
| 76 extra.offline_page_id))); |
| 77 value->SetBoolean("isDownloadAsset", extra.is_download_asset); |
| 78 entry->Set("downloadSuggestionExtra", std::move(value)); |
| 79 } |
| 80 |
| 81 if (suggestion.recent_tab_suggestion_extra()) { |
| 82 const auto& extra = *suggestion.recent_tab_suggestion_extra(); |
| 83 auto value = base::MakeUnique<base::DictionaryValue>(); |
| 84 value->SetInteger("tabID", extra.tab_id); |
| 85 value->SetString( |
| 86 "offlinePageID", |
| 87 base::StringPrintf("0x%016llx", static_cast<long long unsigned int>( |
| 88 extra.offline_page_id))); |
| 89 entry->Set("recentTabSuggestionExtra", std::move(value)); |
| 90 } |
| 91 |
| 92 if (suggestion.notification_extra()) { |
| 93 const auto& extra = *suggestion.notification_extra(); |
| 94 auto value = base::MakeUnique<base::DictionaryValue>(); |
| 95 value->SetString("deadline", TimeFormatShortDateAndTime(extra.deadline)); |
| 96 entry->Set("notificationExtra", std::move(value)); |
| 97 } |
| 98 |
61 return entry; | 99 return entry; |
62 } | 100 } |
63 | 101 |
64 std::string GetCategoryStatusName(CategoryStatus status) { | 102 std::string GetCategoryStatusName(CategoryStatus status) { |
65 switch (status) { | 103 switch (status) { |
66 case CategoryStatus::INITIALIZING: | 104 case CategoryStatus::INITIALIZING: |
67 return "INITIALIZING"; | 105 return "INITIALIZING"; |
68 case CategoryStatus::AVAILABLE: | 106 case CategoryStatus::AVAILABLE: |
69 return "AVAILABLE"; | 107 return "AVAILABLE"; |
70 case CategoryStatus::AVAILABLE_LOADING: | 108 case CategoryStatus::AVAILABLE_LOADING: |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( | 454 void SnippetsInternalsMessageHandler::OnDismissedSuggestionsLoaded( |
417 Category category, | 455 Category category, |
418 std::vector<ContentSuggestion> dismissed_suggestions) { | 456 std::vector<ContentSuggestion> dismissed_suggestions) { |
419 if (dismissed_state_[category] == DismissedState::HIDDEN) { | 457 if (dismissed_state_[category] == DismissedState::HIDDEN) { |
420 return; | 458 return; |
421 } | 459 } |
422 dismissed_suggestions_[category] = std::move(dismissed_suggestions); | 460 dismissed_suggestions_[category] = std::move(dismissed_suggestions); |
423 dismissed_state_[category] = DismissedState::VISIBLE; | 461 dismissed_state_[category] = DismissedState::VISIBLE; |
424 SendContentSuggestions(); | 462 SendContentSuggestions(); |
425 } | 463 } |
OLD | NEW |