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

Side by Side Diff: chrome/browser/favicon/favicon_service.cc

Issue 835903005: [Favicon] Add new fallback icon rendering flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor by extracting FallbackIconSpecsBuilder. Created 5 years, 11 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/favicon/favicon_service.h" 5 #include "chrome/browser/favicon/favicon_service.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "chrome/browser/history/history_backend.h" 11 #include "chrome/browser/history/history_backend.h"
12 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
13 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 14 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
15 #include "chrome/common/importer/imported_favicon_usage.h" 15 #include "chrome/common/importer/imported_favicon_usage.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "components/favicon_base/favicon_types.h" 17 #include "components/favicon_base/fallback_icon_service.h"
18 #include "components/favicon_base/favicon_util.h" 18 #include "components/favicon_base/favicon_util.h"
19 #include "components/favicon_base/select_favicon_frames.h" 19 #include "components/favicon_base/select_favicon_frames.h"
20 #include "extensions/common/constants.h" 20 #include "extensions/common/constants.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/codec/png_codec.h" 22 #include "ui/gfx/codec/png_codec.h"
23 #include "ui/gfx/favicon_size.h" 23 #include "ui/gfx/favicon_size.h"
24 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 #include "url/gurl.h"
25 26
26 using base::Bind; 27 using base::Bind;
27 28
28 namespace { 29 namespace {
29 30
31 const int kMaxFallbackFaviconSize = 288;
32
30 void CancelOrRunFaviconResultsCallback( 33 void CancelOrRunFaviconResultsCallback(
31 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled, 34 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled,
32 const favicon_base::FaviconResultsCallback& callback, 35 const favicon_base::FaviconResultsCallback& callback,
33 const std::vector<favicon_base::FaviconRawBitmapResult>& results) { 36 const std::vector<favicon_base::FaviconRawBitmapResult>& results) {
34 if (is_canceled.Run()) 37 if (is_canceled.Run())
35 return; 38 return;
36 callback.Run(results); 39 callback.Run(results);
37 } 40 }
38 41
39 // Helper to run callback with empty results if we cannot get the history 42 // Helper to run callback with empty results if we cannot get the history
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 77 }
75 return sizes_in_pixel; 78 return sizes_in_pixel;
76 } 79 }
77 80
78 } // namespace 81 } // namespace
79 82
80 FaviconService::FaviconService(Profile* profile, FaviconClient* favicon_client) 83 FaviconService::FaviconService(Profile* profile, FaviconClient* favicon_client)
81 : history_service_(HistoryServiceFactory::GetForProfile( 84 : history_service_(HistoryServiceFactory::GetForProfile(
82 profile, 85 profile,
83 ServiceAccessType::EXPLICIT_ACCESS)), 86 ServiceAccessType::EXPLICIT_ACCESS)),
87 fallback_icon_service_(new favicon_base::FallbackIconService()),
84 profile_(profile), 88 profile_(profile),
85 favicon_client_(favicon_client) { 89 favicon_client_(favicon_client) {
86 } 90 }
87 91
88 // static 92 // static
89 void FaviconService::FaviconResultsCallbackRunner( 93 void FaviconService::FaviconResultsCallbackRunner(
90 const favicon_base::FaviconResultsCallback& callback, 94 const favicon_base::FaviconResultsCallback& callback,
91 const std::vector<favicon_base::FaviconRawBitmapResult>* results) { 95 const std::vector<favicon_base::FaviconRawBitmapResult>* results) {
92 callback.Run(*results); 96 callback.Run(*results);
93 } 97 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 page_url, 167 page_url,
164 favicon_base::FAVICON, 168 favicon_base::FAVICON,
165 GetPixelSizesForFaviconScales(gfx::kFaviconSize), 169 GetPixelSizesForFaviconScales(gfx::kFaviconSize),
166 Bind(&FaviconService::RunFaviconImageCallbackWithBitmapResults, 170 Bind(&FaviconService::RunFaviconImageCallbackWithBitmapResults,
167 base::Unretained(this), 171 base::Unretained(this),
168 callback, 172 callback,
169 gfx::kFaviconSize), 173 gfx::kFaviconSize),
170 tracker); 174 tracker);
171 } 175 }
172 176
177 base::CancelableTaskTracker::TaskId FaviconService::GetRawFallbackFaviconImage(
178 const GURL& icon_url,
179 favicon_base::IconType icon_type,
180 int desired_size_in_pixel,
181 const favicon_base::FallbackIconSpecs& specs,
182 const favicon_base::FaviconRawBitmapCallback& callback,
183 base::CancelableTaskTracker* tracker) {
184 int size_to_use = desired_size_in_pixel;
185 if (desired_size_in_pixel == 0 ||
186 desired_size_in_pixel > kMaxFallbackFaviconSize) {
187 size_to_use = kMaxFallbackFaviconSize;
188 }
189
190 favicon_base::FaviconResultsCallback callback_runner =
191 Bind(&FaviconService::RunFaviconRawBitmapCallbackWithBitmapResults,
192 base::Unretained(this),
193 callback,
194 size_to_use);
195
196 return fallback_icon_service_->GetFallbackIcon(
197 icon_url, size_to_use, specs, callback_runner, tracker);
198 }
199
173 base::CancelableTaskTracker::TaskId FaviconService::GetRawFaviconForPageURL( 200 base::CancelableTaskTracker::TaskId FaviconService::GetRawFaviconForPageURL(
174 const GURL& page_url, 201 const GURL& page_url,
175 int icon_types, 202 int icon_types,
176 int desired_size_in_pixel, 203 int desired_size_in_pixel,
177 const favicon_base::FaviconRawBitmapCallback& callback, 204 const favicon_base::FaviconRawBitmapCallback& callback,
178 base::CancelableTaskTracker* tracker) { 205 base::CancelableTaskTracker* tracker) {
179 std::vector<int> desired_sizes_in_pixel; 206 std::vector<int> desired_sizes_in_pixel;
180 desired_sizes_in_pixel.push_back(desired_size_in_pixel); 207 desired_sizes_in_pixel.push_back(desired_size_in_pixel);
181 return GetFaviconForPageURLImpl( 208 return GetFaviconForPageURLImpl(
182 page_url, 209 page_url,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false, 445 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false,
419 &resized_bitmap_data)) { 446 &resized_bitmap_data)) {
420 callback.Run(favicon_base::FaviconRawBitmapResult()); 447 callback.Run(favicon_base::FaviconRawBitmapResult());
421 return; 448 return;
422 } 449 }
423 450
424 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( 451 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector(
425 &resized_bitmap_data); 452 &resized_bitmap_data);
426 callback.Run(bitmap_result); 453 callback.Run(bitmap_result);
427 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698