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

Side by Side Diff: chrome/browser/ui/webui/favicon_source.cc

Issue 331163003: [Refactor] Change FaviconService API to take in a desired pixel size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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/ui/webui/favicon_source.h" 5 #include "chrome/browser/ui/webui/favicon_source.h"
6 6
7 #include <cmath>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/favicon/favicon_service_factory.h" 12 #include "chrome/browser/favicon/favicon_service_factory.h"
11 #include "chrome/browser/history/top_sites.h" 13 #include "chrome/browser/history/top_sites.h"
12 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/instant_io_context.h" 15 #include "chrome/browser/search/instant_io_context.h"
14 #include "chrome/browser/sync/open_tabs_ui_delegate.h" 16 #include "chrome/browser/sync/open_tabs_ui_delegate.h"
15 #include "chrome/browser/sync/profile_sync_service.h" 17 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 72 }
71 73
72 chrome::ParsedFaviconPath parsed; 74 chrome::ParsedFaviconPath parsed;
73 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); 75 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed);
74 if (!success) { 76 if (!success) {
75 SendDefaultResponse(callback); 77 SendDefaultResponse(callback);
76 return; 78 return;
77 } 79 }
78 80
79 GURL url(parsed.url); 81 GURL url(parsed.url);
82 int desired_size_in_pixel =
83 std::ceil(parsed.size_in_dip * parsed.device_scale_factor);
80 84
81 if (parsed.is_icon_url) { 85 if (parsed.is_icon_url) {
82 // TODO(michaelbai): Change GetRawFavicon to support combination of 86 // TODO(michaelbai): Change GetRawFavicon to support combination of
83 // IconType. 87 // IconType.
84 favicon_service->GetRawFavicon( 88 favicon_service->GetRawFavicon(
85 url, 89 url,
86 favicon_base::FAVICON, 90 favicon_base::FAVICON,
87 parsed.size_in_dip, 91 desired_size_in_pixel,
88 parsed.device_scale_factor,
89 base::Bind( 92 base::Bind(
90 &FaviconSource::OnFaviconDataAvailable, 93 &FaviconSource::OnFaviconDataAvailable,
91 base::Unretained(this), 94 base::Unretained(this),
92 IconRequest( 95 IconRequest(
93 callback, url, parsed.size_in_dip, parsed.device_scale_factor)), 96 callback, url, parsed.size_in_dip, parsed.device_scale_factor)),
94 &cancelable_task_tracker_); 97 &cancelable_task_tracker_);
95 } else { 98 } else {
96 // Intercept requests for prepopulated pages. 99 // Intercept requests for prepopulated pages.
97 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { 100 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
98 if (url.spec() == 101 if (url.spec() ==
99 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { 102 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
100 ui::ScaleFactor resource_scale_factor = 103 ui::ScaleFactor resource_scale_factor =
101 ui::GetSupportedScaleFactor(parsed.device_scale_factor); 104 ui::GetSupportedScaleFactor(parsed.device_scale_factor);
102 callback.Run( 105 callback.Run(
103 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 106 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
104 history::kPrepopulatedPages[i].favicon_id, 107 history::kPrepopulatedPages[i].favicon_id,
105 resource_scale_factor)); 108 resource_scale_factor));
106 return; 109 return;
107 } 110 }
108 } 111 }
109 112
110 favicon_service->GetRawFaviconForPageURL( 113 favicon_service->GetRawFaviconForPageURL(
111 FaviconService::FaviconForPageURLParams( 114 url,
112 url, icon_types_, parsed.size_in_dip), 115 icon_types_,
113 parsed.device_scale_factor, 116 desired_size_in_pixel,
114 base::Bind( 117 base::Bind(
115 &FaviconSource::OnFaviconDataAvailable, 118 &FaviconSource::OnFaviconDataAvailable,
116 base::Unretained(this), 119 base::Unretained(this),
117 IconRequest( 120 IconRequest(
118 callback, url, parsed.size_in_dip, parsed.device_scale_factor)), 121 callback, url, parsed.size_in_dip, parsed.device_scale_factor)),
119 &cancelable_task_tracker_); 122 &cancelable_task_tracker_);
120 } 123 }
121 } 124 }
122 125
123 std::string FaviconSource::GetMimeType(const std::string&) const { 126 std::string FaviconSource::GetMimeType(const std::string&) const {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 ui::ScaleFactor resource_scale_factor = 198 ui::ScaleFactor resource_scale_factor =
196 ui::GetSupportedScaleFactor(icon_request.device_scale_factor); 199 ui::GetSupportedScaleFactor(icon_request.device_scale_factor);
197 default_favicon = 200 default_favicon =
198 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 201 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
199 resource_id, resource_scale_factor); 202 resource_id, resource_scale_factor);
200 default_favicons_[favicon_index] = default_favicon; 203 default_favicons_[favicon_index] = default_favicon;
201 } 204 }
202 205
203 icon_request.callback.Run(default_favicon); 206 icon_request.callback.Run(default_favicon);
204 } 207 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_icon_source.cc ('k') | chrome/browser/ui/webui/ntp/app_launcher_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698