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

Unified Diff: chrome/browser/ui/webui/large_icon_source.cc

Issue 1092873002: [Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to f… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/large_icon_source.cc
diff --git a/chrome/browser/ui/webui/large_icon_source.cc b/chrome/browser/ui/webui/large_icon_source.cc
index df1e285f6c307e717c86b2056980cffeed9f7785..3881e4981113b648a238417867d7f4b8de9d8f13 100644
--- a/chrome/browser/ui/webui/large_icon_source.cc
+++ b/chrome/browser/ui/webui/large_icon_source.cc
@@ -4,53 +4,28 @@
#include "chrome/browser/ui/webui/large_icon_source.h"
+#include <vector>
+
#include "base/memory/ref_counted_memory.h"
#include "chrome/browser/search/instant_io_context.h"
#include "chrome/common/favicon/large_icon_url_parser.h"
#include "chrome/common/url_constants.h"
#include "components/favicon/core/fallback_icon_service.h"
-#include "components/favicon/core/favicon_service.h"
+#include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/fallback_icon_style.h"
#include "net/url_request/url_request.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/color_analysis.h"
-#include "ui/gfx/color_utils.h"
namespace {
-const int kDefaultLargeIconSize = 96;
const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint.
-const double kMaxBackgroundLuminance = 0.67;
-const SkColor kDarkGray = SkColorSetRGB(0x78, 0x78, 0x78);
-const SkColor kTextColor = SK_ColorWHITE;
-const SkColor kDefaultBackgroundColor = kDarkGray;
-
} // namespace
-LargeIconSource::IconRequest::IconRequest() : size(kDefaultLargeIconSize) {
-}
-
-LargeIconSource::IconRequest::IconRequest(
- const content::URLDataSource::GotDataCallback& callback_in,
- const GURL& url_in,
- int size_in)
- : callback(callback_in),
- url(url_in),
- size(size_in) {
-}
-
-LargeIconSource::IconRequest::~IconRequest() {
-}
-
LargeIconSource::LargeIconSource(
- favicon::FaviconService* favicon_service,
- favicon::FallbackIconService* fallback_icon_service)
- : favicon_service_(favicon_service),
- fallback_icon_service_(fallback_icon_service) {
- large_icon_types_.push_back(favicon_base::IconType::FAVICON);
- large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON);
- large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON);
+ favicon::FallbackIconService* fallback_icon_service,
+ favicon::LargeIconService* large_icon_service)
+ : fallback_icon_service_(fallback_icon_service),
+ large_icon_service_(large_icon_service) {
}
LargeIconSource::~LargeIconSource() {
@@ -65,7 +40,7 @@ void LargeIconSource::StartDataRequest(
int render_process_id,
int render_frame_id,
const content::URLDataSource::GotDataCallback& callback) {
- if (!favicon_service_) {
+ if (!large_icon_service_) {
SendNotFoundResponse(callback);
return;
}
@@ -85,14 +60,11 @@ void LargeIconSource::StartDataRequest(
return;
}
- favicon_service_->GetLargestRawFaviconForPageURL(
+ large_icon_service_->GetLargeIconOrFallbackStyle(
url,
- large_icon_types_,
parser.size_in_pixels(),
- base::Bind(
- &LargeIconSource::OnIconDataAvailable,
- base::Unretained(this),
- IconRequest(callback, url, parser.size_in_pixels())),
+ base::Bind(&LargeIconSource::OnIconDataAvailable, base::Unretained(this),
huangs 2015/04/21 05:00:28 OnLargeIconDataAvailable()
beaudoin 2015/04/21 15:11:11 Done.
+ callback, url, parser.size_in_pixels()),
&cancelable_task_tracker_);
}
@@ -116,53 +88,24 @@ bool LargeIconSource::ShouldServiceRequest(
}
void LargeIconSource::OnIconDataAvailable(
huangs 2015/04/21 05:00:28 NIT: OnLargeIconDataAvailable().
beaudoin 2015/04/21 15:11:11 Done.
- const IconRequest& request,
- const favicon_base::FaviconRawBitmapResult& bitmap_result) {
- if (!bitmap_result.is_valid()) {
- SendDefaultFallbackIcon(request);
+ const content::URLDataSource::GotDataCallback& callback,
+ const GURL& url,
+ int size,
+ const favicon_base::LargeIconResult& result) {
+ if (result.bitmap.is_valid()) {
+ callback.Run(result.bitmap.bitmap_data.get());
return;
}
- // If we found a bitmap, but it's smaller than the requested size, we
- // generate a fallback using the dominant color from the too-small bitmap.
- // We adjust the luminance of the background so we can put light text over it.
- if (bitmap_result.pixel_size.width() < request.size ||
- bitmap_result.pixel_size.height() < request.size) {
- SkColor background =
- color_utils::CalculateKMeanColorOfPNG(bitmap_result.bitmap_data);
- color_utils::HSL background_hsl;
- color_utils::SkColorToHSL(background, &background_hsl);
- background_hsl.l = std::min(background_hsl.l, kMaxBackgroundLuminance);
- background = color_utils::HSLToSkColor(background_hsl, SK_AlphaOPAQUE);
-
- // Now we can construct the fallback icon.
- SendFallbackIcon(request, kTextColor, background);
- return;
- }
-
- request.callback.Run(bitmap_result.bitmap_data.get());
-}
-
-void LargeIconSource::SendDefaultFallbackIcon(const IconRequest& request) {
- SendFallbackIcon(request, kTextColor, kDefaultBackgroundColor);
-}
-
-void LargeIconSource::SendFallbackIcon(const IconRequest& request,
- SkColor text_color,
- SkColor background_color) {
- if (!fallback_icon_service_) {
- SendNotFoundResponse(request.callback);
+ // Bitmap is invalid, use the fallback if service is available.
+ if (!fallback_icon_service_ || !result.fallback_icon_style) {
+ SendNotFoundResponse(callback);
return;
}
- favicon_base::FallbackIconStyle style;
- style.background_color = background_color;
- style.text_color = text_color;
- style.font_size_ratio = 0.44;
- style.roundness = 0; // Square. Round corners can be applied by JavaScript.
std::vector<unsigned char> bitmap_data =
fallback_icon_service_->RenderFallbackIconBitmap(
- request.url, request.size, style);
- request.callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
+ url, size, *result.fallback_icon_style);
+ callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
}
void LargeIconSource::SendNotFoundResponse(

Powered by Google App Engine
This is Rietveld 408576698