Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Side by Side Diff: components/ntp_tiles/icon_cacher_impl.cc

Issue 2794343002: Network traffic annotation added to image_data_fetcher. (Closed)
Patch Set: All comments addressed. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/ntp_tiles/icon_cacher_impl.h" 5 #include "components/ntp_tiles/icon_cacher_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/favicon/core/favicon_service.h" 10 #include "components/favicon/core/favicon_service.h"
11 #include "components/favicon/core/favicon_util.h" 11 #include "components/favicon/core/favicon_util.h"
12 #include "components/favicon_base/favicon_types.h" 12 #include "components/favicon_base/favicon_types.h"
13 #include "components/favicon_base/favicon_util.h" 13 #include "components/favicon_base/favicon_util.h"
14 #include "components/image_fetcher/core/image_decoder.h" 14 #include "components/image_fetcher/core/image_decoder.h"
15 #include "components/image_fetcher/core/image_fetcher.h" 15 #include "components/image_fetcher/core/image_fetcher.h"
16 #include "net/traffic_annotation/network_traffic_annotation.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace ntp_tiles { 22 namespace ntp_tiles {
22 23
23 namespace { 24 namespace {
24 25
25 constexpr int kDesiredFrameSize = 128; 26 constexpr int kDesiredFrameSize = 128;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const base::Closure& icon_available, 72 const base::Closure& icon_available,
72 const base::Closure& preliminary_icon_available, 73 const base::Closure& preliminary_icon_available,
73 const favicon_base::FaviconImageResult& result) { 74 const favicon_base::FaviconImageResult& result) {
74 if (!result.image.IsEmpty()) { 75 if (!result.image.IsEmpty()) {
75 return; 76 return;
76 } 77 }
77 78
78 std::unique_ptr<CancelableImageCallback> preliminary_callback = 79 std::unique_ptr<CancelableImageCallback> preliminary_callback =
79 MaybeProvideDefaultIcon(site, preliminary_icon_available); 80 MaybeProvideDefaultIcon(site, preliminary_icon_available);
80 81
82 net::NetworkTrafficAnnotationTag traffic_annotation =
83 net::DefineNetworkTrafficAnnotation("icon_cacher", R"(
84 semantics {
85 sender: "Popular Sites New Tab Fetch"
86 description:
87 "Chrome may display a list of regionally-popular web sites on the "
88 "New Tab Page. This service fetches icons from those sites."
89 trigger:
90 "Whenever a popular site would be displayed, but its icon is not "
91 "yet cached in the browser."
92 data: "The URL for which to retrieve a thumbnail."
sfiera 2017/05/09 13:25:55 This does not fetch a thumbnail, just an icon. e.
Ramin Halavati 2017/05/09 13:57:50 Done.
93 destination: WEBSITE
94 }
95 policy {
96 cookies_allowed: false
97 setting: "This feature cannot be disabled in settings."
98 policy_exception_justification: "Not implemented."
99 })");
81 image_fetcher_->StartOrQueueNetworkRequest( 100 image_fetcher_->StartOrQueueNetworkRequest(
82 std::string(), IconURL(site), 101 std::string(), IconURL(site),
83 base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this), 102 base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this),
84 site, base::Passed(std::move(preliminary_callback)), 103 site, base::Passed(std::move(preliminary_callback)),
85 icon_available)); 104 icon_available),
105 traffic_annotation);
86 } 106 }
87 107
88 void IconCacherImpl::OnFaviconDownloaded( 108 void IconCacherImpl::OnFaviconDownloaded(
89 PopularSites::Site site, 109 PopularSites::Site site,
90 std::unique_ptr<CancelableImageCallback> preliminary_callback, 110 std::unique_ptr<CancelableImageCallback> preliminary_callback,
91 const base::Closure& icon_available, 111 const base::Closure& icon_available,
92 const std::string& id, 112 const std::string& id,
93 const gfx::Image& fetched_image, 113 const gfx::Image& fetched_image,
94 const image_fetcher::RequestMetadata& metadata) { 114 const image_fetcher::RequestMetadata& metadata) {
95 if (fetched_image.IsEmpty()) { 115 if (fetched_image.IsEmpty()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 image_fetcher_->GetImageDecoder()->DecodeImage( 154 image_fetcher_->GetImageDecoder()->DecodeImage(
135 ResourceBundle::GetSharedInstance() 155 ResourceBundle::GetSharedInstance()
136 .GetRawDataResource(site.default_icon_resource) 156 .GetRawDataResource(site.default_icon_resource)
137 .as_string(), 157 .as_string(),
138 gfx::Size(kDesiredFrameSize, kDesiredFrameSize), 158 gfx::Size(kDesiredFrameSize, kDesiredFrameSize),
139 preliminary_callback->callback()); 159 preliminary_callback->callback());
140 return preliminary_callback; 160 return preliminary_callback;
141 } 161 }
142 162
143 } // namespace ntp_tiles 163 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698