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

Side by Side Diff: chrome/browser/search/thumbnail_source.cc

Issue 2794343002: Network traffic annotation added to image_data_fetcher. (Closed)
Patch Set: Annotation updated. 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/search/thumbnail_source.h" 5 #include "chrome/browser/search/thumbnail_source.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/instant_io_context.h" 10 #include "chrome/browser/search/instant_io_context.h"
11 #include "chrome/browser/thumbnails/thumbnail_service.h" 11 #include "chrome/browser/thumbnails/thumbnail_service.h"
12 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" 12 #include "chrome/browser/thumbnails/thumbnail_service_factory.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "net/traffic_annotation/network_traffic_annotation.h"
14 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 // The delimiter between the first url and the fallback url passed to 18 // The delimiter between the first url and the fallback url passed to
18 // StartDataRequest. 19 // StartDataRequest.
19 const char kUrlDelimiter[] = "?fb="; 20 const char kUrlDelimiter[] = "?fb=";
20 21
21 // Set ThumbnailService now as Profile isn't thread safe. 22 // Set ThumbnailService now as Profile isn't thread safe.
22 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails) 23 ThumbnailSource::ThumbnailSource(Profile* profile, bool capture_thumbnails)
23 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)), 24 : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)),
(...skipping 16 matching lines...) Expand all
40 GURL fallback_thumbnail_url; 41 GURL fallback_thumbnail_url;
41 ExtractPageAndThumbnailUrls(path, &page_url, &fallback_thumbnail_url); 42 ExtractPageAndThumbnailUrls(path, &page_url, &fallback_thumbnail_url);
42 43
43 scoped_refptr<base::RefCountedMemory> data; 44 scoped_refptr<base::RefCountedMemory> data;
44 if (page_url.is_valid() && thumbnail_service_->GetPageThumbnail( 45 if (page_url.is_valid() && thumbnail_service_->GetPageThumbnail(
45 page_url, 46 page_url,
46 /*prefix_match=*/capture_thumbnails_, &data)) { 47 /*prefix_match=*/capture_thumbnails_, &data)) {
47 // If a local thumbnail is available for the page's URL, provide it. 48 // If a local thumbnail is available for the page's URL, provide it.
48 callback.Run(data.get()); 49 callback.Run(data.get());
49 } else if (fallback_thumbnail_url.is_valid()) { 50 } else if (fallback_thumbnail_url.is_valid()) {
51 net::NetworkTrafficAnnotationTag traffic_annotation =
52 net::DefineNetworkTrafficAnnotation("thumbnail_source", R"(
53 semantics {
54 sender: "Thumbnail Source"
55 description:
56 "Retrieves thumbnails for site suggestions based on the user's "
57 "synced browsing history, for use e.g. on the New Tab page."
58 trigger:
59 "Triggered when a thumbnail for a suggestion is required (e.g. on "
60 "the New Tab page), and no local thumbnail is available."
61 data: "The URL for which to retrieve a thumbnail."
62 destination: GOOGLE_OWNED_SERVICE
63 }
64 policy {
65 cookies_allowed: false
66 setting:
67 "Users can disable this feature by signing out of Chrome, or "
68 "disabling Sync or History Sync in Chrome settings under 'Advanced "
69 "sync settings...'. The feature is enabled by default."
70 chrome_policy {
71 SyncDisabled {
72 policy_options {mode: MANDATORY}
73 SyncDisabled: true
74 }
75 }
76 chrome_policy {
77 SigninAllowed {
78 policy_options {mode: MANDATORY}
79 SigninAllowed: false
80 }
81 }
82 })");
50 // Otherwise, if a fallback thumbnail URL was provided, fetch it and 83 // Otherwise, if a fallback thumbnail URL was provided, fetch it and
51 // eventually return it. 84 // eventually return it.
52 image_data_fetcher_.FetchImageData( 85 image_data_fetcher_.FetchImageData(
53 fallback_thumbnail_url, 86 fallback_thumbnail_url,
54 base::Bind(&ThumbnailSource::SendFetchedUrlImage, 87 base::Bind(&ThumbnailSource::SendFetchedUrlImage,
55 weak_ptr_factory_.GetWeakPtr(), callback)); 88 weak_ptr_factory_.GetWeakPtr(), callback),
89 traffic_annotation);
56 } else { 90 } else {
57 callback.Run(nullptr); 91 callback.Run(nullptr);
58 } 92 }
59 if (page_url.is_valid() && capture_thumbnails_) 93 if (page_url.is_valid() && capture_thumbnails_)
60 thumbnail_service_->AddForcedURL(page_url); 94 thumbnail_service_->AddForcedURL(page_url);
61 } 95 }
62 96
63 std::string ThumbnailSource::GetMimeType(const std::string&) const { 97 std::string ThumbnailSource::GetMimeType(const std::string&) const {
64 // We need to explicitly return a mime type, otherwise if the user tries to 98 // We need to explicitly return a mime type, otherwise if the user tries to
65 // drag the image they get no extension. 99 // drag the image they get no extension.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const content::URLDataSource::GotDataCallback& callback, 150 const content::URLDataSource::GotDataCallback& callback,
117 const std::string& image_data, 151 const std::string& image_data,
118 const image_fetcher::RequestMetadata& metadata) { 152 const image_fetcher::RequestMetadata& metadata) {
119 if (image_data.empty()) { 153 if (image_data.empty()) {
120 callback.Run(nullptr); 154 callback.Run(nullptr);
121 return; 155 return;
122 } 156 }
123 std::string image_data_copy = image_data; 157 std::string image_data_copy = image_data;
124 callback.Run(base::RefCountedString::TakeString(&image_data_copy)); 158 callback.Run(base::RefCountedString::TakeString(&image_data_copy));
125 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698