Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 } | 173 } |
| 174 | 174 |
| 175 void FaviconSource::SendDefaultResponse( | 175 void FaviconSource::SendDefaultResponse( |
| 176 const content::URLDataSource::GotDataCallback& callback) { | 176 const content::URLDataSource::GotDataCallback& callback) { |
| 177 SendDefaultResponse(IconRequest(callback, GURL(), 16, 1.0f)); | 177 SendDefaultResponse(IconRequest(callback, GURL(), 16, 1.0f)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { | 180 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { |
| 181 int favicon_index; | 181 int favicon_index; |
| 182 int resource_id; | 182 int resource_id; |
| 183 switch (icon_request.size_in_dip) { | 183 bool desired_size_not_found = false; |
| 184 | |
| 185 int desired_size_in_pixel = | |
| 186 std::ceil(icon_request.size_in_dip * icon_request.device_scale_factor); | |
|
Peter Kasting
2016/11/26 06:22:30
Why ceil, and not round?
minggang
2016/11/28 02:53:07
1 pixel higher resolution is always better if the
Peter Kasting
2016/11/28 03:42:42
I'm not any more sure that code is correct than th
| |
| 187 | |
| 188 switch (desired_size_in_pixel) { | |
| 184 case 64: | 189 case 64: |
| 185 favicon_index = SIZE_64; | 190 favicon_index = SIZE_64; |
| 186 resource_id = IDR_DEFAULT_FAVICON_64; | 191 resource_id = IDR_DEFAULT_FAVICON_64; |
| 187 break; | 192 break; |
| 188 case 32: | 193 case 32: |
| 189 favicon_index = SIZE_32; | 194 favicon_index = SIZE_32; |
| 190 resource_id = IDR_DEFAULT_FAVICON_32; | 195 resource_id = IDR_DEFAULT_FAVICON_32; |
| 191 break; | 196 break; |
| 192 default: | 197 case 16: |
| 193 favicon_index = SIZE_16; | 198 favicon_index = SIZE_16; |
| 194 resource_id = IDR_DEFAULT_FAVICON; | 199 resource_id = IDR_DEFAULT_FAVICON; |
| 195 break; | 200 break; |
| 201 default: | |
|
Peter Kasting
2016/11/26 06:22:30
What other values are falling into here? 0? If s
minggang
2016/11/28 02:53:07
To assign a value to |resource_id| here is not pro
Peter Kasting
2016/11/28 03:42:42
You didn't answer my question: what values are fal
| |
| 202 desired_size_not_found = true; | |
|
Peter Kasting
2016/11/26 06:22:30
It's very confusing that we set a temp here, and t
minggang
2016/11/28 02:53:07
Please see the comment above.
On 2016/11/26 06:22:
| |
| 203 break; | |
| 196 } | 204 } |
| 197 base::RefCountedMemory* default_favicon = | |
| 198 default_favicons_[favicon_index].get(); | |
| 199 | 205 |
| 200 if (!default_favicon) { | 206 base::RefCountedMemory* default_favicon = nullptr; |
| 207 | |
| 208 if (!desired_size_not_found) { | |
|
Peter Kasting
2016/11/26 06:22:30
This is super-confusing to read, because you have
minggang
2016/11/28 02:53:07
Yes, |desired_size_not_found| with the if...else..
Peter Kasting
2016/11/28 03:42:43
Aim to leave the code in the best state possible,
| |
| 209 default_favicon = default_favicons_[favicon_index].get(); | |
| 210 | |
| 211 if (!default_favicon) { | |
| 212 default_favicon = | |
| 213 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | |
| 214 resource_id); | |
| 215 default_favicons_[favicon_index] = default_favicon; | |
| 216 } | |
| 217 } else { | |
| 201 ui::ScaleFactor resource_scale_factor = | 218 ui::ScaleFactor resource_scale_factor = |
| 202 ui::GetSupportedScaleFactor(icon_request.device_scale_factor); | 219 ui::GetSupportedScaleFactor(icon_request.device_scale_factor); |
| 220 | |
| 203 default_favicon = | 221 default_favicon = |
| 204 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 222 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
| 205 resource_id, resource_scale_factor); | 223 IDR_DEFAULT_FAVICON, resource_scale_factor); |
|
Peter Kasting
2016/11/26 06:22:30
We go to the trouble of caching the favicons above
| |
| 206 default_favicons_[favicon_index] = default_favicon; | |
| 207 } | 224 } |
| 208 | 225 |
| 209 icon_request.callback.Run(default_favicon); | 226 icon_request.callback.Run(default_favicon); |
| 210 } | 227 } |
| OLD | NEW |