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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 26 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
27 #include "components/ntp_snippets/features.h" | 27 #include "components/ntp_snippets/features.h" |
28 #include "components/ntp_snippets/pref_names.h" | 28 #include "components/ntp_snippets/pref_names.h" |
29 #include "components/ntp_snippets/remote/remote_suggestions_database.h" | 29 #include "components/ntp_snippets/remote/remote_suggestions_database.h" |
30 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" | 30 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" |
31 #include "components/ntp_snippets/switches.h" | 31 #include "components/ntp_snippets/switches.h" |
32 #include "components/prefs/pref_registry_simple.h" | 32 #include "components/prefs/pref_registry_simple.h" |
33 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
34 #include "components/strings/grit/components_strings.h" | 34 #include "components/strings/grit/components_strings.h" |
35 #include "components/variations/variations_associated_data.h" | 35 #include "components/variations/variations_associated_data.h" |
| 36 #include "net/traffic_annotation/network_traffic_annotation.h" |
36 #include "ui/gfx/geometry/size.h" | 37 #include "ui/gfx/geometry/size.h" |
37 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
38 | 39 |
39 namespace ntp_snippets { | 40 namespace ntp_snippets { |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Number of suggestions requested to the server. Consider replacing sparse UMA | 44 // Number of suggestions requested to the server. Consider replacing sparse UMA |
44 // histograms with COUNTS() if this number increases beyond 50. | 45 // histograms with COUNTS() if this number increases beyond 50. |
45 const int kMaxSuggestionCount = 10; | 46 const int kMaxSuggestionCount = 10; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 const ImageFetchedCallback& callback) { | 282 const ImageFetchedCallback& callback) { |
282 if (url.is_empty() || !thumbnail_requests_throttler_.DemandQuotaForRequest( | 283 if (url.is_empty() || !thumbnail_requests_throttler_.DemandQuotaForRequest( |
283 /*interactive_request=*/true)) { | 284 /*interactive_request=*/true)) { |
284 // Return an empty image. Directly, this is never synchronous with the | 285 // Return an empty image. Directly, this is never synchronous with the |
285 // original FetchSuggestionImage() call - an asynchronous database query has | 286 // original FetchSuggestionImage() call - an asynchronous database query has |
286 // happened in the meantime. | 287 // happened in the meantime. |
287 callback.Run(gfx::Image()); | 288 callback.Run(gfx::Image()); |
288 return; | 289 return; |
289 } | 290 } |
290 | 291 |
| 292 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 293 net::DefineNetworkTrafficAnnotation("remote_suggestions_provider", R"( |
| 294 semantics { |
| 295 sender: "Content Suggestion Thumbnail Fetch" |
| 296 description: |
| 297 "Retrieves thumbnails for content suggestions, for display on the " |
| 298 "New Tab page or Chrome Home." |
| 299 trigger: |
| 300 "Triggered when the user looks at a content suggestion (and its " |
| 301 "thumbnail isn't cached yet)." |
| 302 data: "None." |
| 303 destination: GOOGLE_OWNED_SERVICE |
| 304 } |
| 305 policy { |
| 306 cookies_allowed: false |
| 307 setting: "Currently not available, but in progress: crbug.com/703684" |
| 308 chrome_policy { |
| 309 NTPContentSuggestionsEnabled { |
| 310 policy_options {mode: MANDATORY} |
| 311 NTPContentSuggestionsEnabled: false |
| 312 } |
| 313 } |
| 314 })"); |
291 image_fetcher_->StartOrQueueNetworkRequest( | 315 image_fetcher_->StartOrQueueNetworkRequest( |
292 suggestion_id.id_within_category(), url, | 316 suggestion_id.id_within_category(), url, |
293 base::Bind(&CachedImageFetcher::OnImageDecodingDone, | 317 base::Bind(&CachedImageFetcher::OnImageDecodingDone, |
294 base::Unretained(this), callback)); | 318 base::Unretained(this), callback), |
| 319 traffic_annotation); |
295 } | 320 } |
296 | 321 |
297 RemoteSuggestionsProviderImpl::RemoteSuggestionsProviderImpl( | 322 RemoteSuggestionsProviderImpl::RemoteSuggestionsProviderImpl( |
298 Observer* observer, | 323 Observer* observer, |
299 PrefService* pref_service, | 324 PrefService* pref_service, |
300 const std::string& application_language_code, | 325 const std::string& application_language_code, |
301 CategoryRanker* category_ranker, | 326 CategoryRanker* category_ranker, |
302 RemoteSuggestionsScheduler* scheduler, | 327 RemoteSuggestionsScheduler* scheduler, |
303 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher, | 328 std::unique_ptr<RemoteSuggestionsFetcher> suggestions_fetcher, |
304 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, | 329 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( | 1353 RemoteSuggestionsProviderImpl::CategoryContent::CategoryContent( |
1329 CategoryContent&&) = default; | 1354 CategoryContent&&) = default; |
1330 | 1355 |
1331 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; | 1356 RemoteSuggestionsProviderImpl::CategoryContent::~CategoryContent() = default; |
1332 | 1357 |
1333 RemoteSuggestionsProviderImpl::CategoryContent& | 1358 RemoteSuggestionsProviderImpl::CategoryContent& |
1334 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = | 1359 RemoteSuggestionsProviderImpl::CategoryContent::operator=(CategoryContent&&) = |
1335 default; | 1360 default; |
1336 | 1361 |
1337 } // namespace ntp_snippets | 1362 } // namespace ntp_snippets |
OLD | NEW |