| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/remote/remote_suggestions_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" | |
| 21 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/default_clock.h" | 21 #include "base/time/default_clock.h" |
| 23 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 24 #include "base/values.h" | 23 #include "base/values.h" |
| 25 #include "components/data_use_measurement/core/data_use_user_data.h" | 24 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 26 #include "components/history/core/browser/history_service.h" | 25 #include "components/history/core/browser/history_service.h" |
| 27 #include "components/image_fetcher/image_decoder.h" | 26 #include "components/image_fetcher/image_decoder.h" |
| 28 #include "components/image_fetcher/image_fetcher.h" | 27 #include "components/image_fetcher/image_fetcher.h" |
| 29 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 28 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 30 #include "components/ntp_snippets/features.h" | |
| 31 #include "components/ntp_snippets/pref_names.h" | 29 #include "components/ntp_snippets/pref_names.h" |
| 32 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 30 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
| 33 #include "components/ntp_snippets/switches.h" | 31 #include "components/ntp_snippets/switches.h" |
| 34 #include "components/prefs/pref_registry_simple.h" | 32 #include "components/prefs/pref_registry_simple.h" |
| 35 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
| 36 #include "components/variations/variations_associated_data.h" | 34 #include "components/variations/variations_associated_data.h" |
| 37 #include "grit/components_strings.h" | 35 #include "grit/components_strings.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 39 #include "ui/gfx/image/image.h" | 37 #include "ui/gfx/image/image.h" |
| 40 | 38 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const NTPSnippet::PtrVector& snippets) { | 138 const NTPSnippet::PtrVector& snippets) { |
| 141 std::vector<ContentSuggestion> result; | 139 std::vector<ContentSuggestion> result; |
| 142 for (const std::unique_ptr<NTPSnippet>& snippet : snippets) { | 140 for (const std::unique_ptr<NTPSnippet>& snippet : snippets) { |
| 143 // TODO(sfiera): if a snippet is not going to be displayed, move it | 141 // TODO(sfiera): if a snippet is not going to be displayed, move it |
| 144 // directly to content.dismissed on fetch. Otherwise, we might prune | 142 // directly to content.dismissed on fetch. Otherwise, we might prune |
| 145 // other snippets to get down to kMaxSnippetCount, only to hide one of the | 143 // other snippets to get down to kMaxSnippetCount, only to hide one of the |
| 146 // incomplete ones we kept. | 144 // incomplete ones we kept. |
| 147 if (!snippet->is_complete()) { | 145 if (!snippet->is_complete()) { |
| 148 continue; | 146 continue; |
| 149 } | 147 } |
| 150 GURL url = snippet->url(); | 148 result.emplace_back(snippet->ToContentSuggestion(category)); |
| 151 if (base::FeatureList::IsEnabled(kPreferAmpUrlsFeature) && | |
| 152 !snippet->amp_url().is_empty()) { | |
| 153 url = snippet->amp_url(); | |
| 154 } | |
| 155 ContentSuggestion suggestion(category, snippet->id(), url); | |
| 156 suggestion.set_title(base::UTF8ToUTF16(snippet->title())); | |
| 157 suggestion.set_snippet_text(base::UTF8ToUTF16(snippet->snippet())); | |
| 158 suggestion.set_publish_date(snippet->publish_date()); | |
| 159 suggestion.set_publisher_name(base::UTF8ToUTF16(snippet->publisher_name())); | |
| 160 suggestion.set_score(snippet->score()); | |
| 161 result.emplace_back(std::move(suggestion)); | |
| 162 } | 149 } |
| 163 return result; | 150 return result; |
| 164 } | 151 } |
| 165 | 152 |
| 166 void CallWithEmptyResults(const FetchDoneCallback& callback, | 153 void CallWithEmptyResults(const FetchDoneCallback& callback, |
| 167 const Status& status) { | 154 const Status& status) { |
| 168 if (callback.is_null()) { | 155 if (callback.is_null()) { |
| 169 return; | 156 return; |
| 170 } | 157 } |
| 171 callback.Run(status, std::vector<ContentSuggestion>()); | 158 callback.Run(status, std::vector<ContentSuggestion>()); |
| (...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( | 1281 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( |
| 1295 CategoryContent&&) = default; | 1282 CategoryContent&&) = default; |
| 1296 | 1283 |
| 1297 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; | 1284 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; |
| 1298 | 1285 |
| 1299 RemoteSuggestionsProviderImpl::CategoryContent& | 1286 RemoteSuggestionsProviderImpl::CategoryContent& |
| 1300 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = | 1287 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = |
| 1301 default; | 1288 default; |
| 1302 | 1289 |
| 1303 } // namespace ntp_snippets | 1290 } // namespace ntp_snippets |
| OLD | NEW |