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

Unified Diff: components/favicon/ios/web_favicon_driver.mm

Issue 2677993002: Use IOSImageDataFetcherWrapper for favicon (Closed)
Patch Set: Actually adding the header Created 3 years, 10 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
« no previous file with comments | « components/favicon/ios/web_favicon_driver.h ('k') | components/image_fetcher/image_data_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/favicon/ios/web_favicon_driver.mm
diff --git a/components/favicon/ios/web_favicon_driver.mm b/components/favicon/ios/web_favicon_driver.mm
index 03777812d270aaab8087036341b4f3035fc340a0..cf5185f2f817f1ab7ef0cdbffceccb3c7255825a 100644
--- a/components/favicon/ios/web_favicon_driver.mm
+++ b/components/favicon/ios/web_favicon_driver.mm
@@ -5,6 +5,7 @@
#include "components/favicon/ios/web_favicon_driver.h"
#include "base/bind.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "components/favicon/core/favicon_url.h"
#include "components/favicon/ios/favicon_url_util.h"
#include "ios/web/public/browser_state.h"
@@ -12,10 +13,21 @@
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/navigation_manager.h"
#include "ios/web/public/web_state/web_state.h"
+#include "ios/web/public/web_thread.h"
+#include "skia/ext/skia_utils_ios.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver);
+// Callback for the download of favicon.
+using ImageDownloadCallback =
+ base::Callback<void(int image_id,
+ int http_status_code,
+ const GURL& image_url,
+ const std::vector<SkBitmap>& bitmaps,
+ const std::vector<gfx::Size>& sizes)>;
+
namespace favicon {
// static
@@ -55,10 +67,33 @@ int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) {
return 0;
}
- return web_state()->DownloadImage(
- url, true, max_image_size, false,
- base::Bind(&FaviconDriverImpl::DidDownloadFavicon,
- base::Unretained(this)));
+ static int downloaded_image_count = 0;
+ int local_download_id = ++downloaded_image_count;
+
+ ImageDownloadCallback local_image_callback = base::Bind(
+ &FaviconDriverImpl::DidDownloadFavicon, base::Unretained(this));
+ GURL local_url(url);
+
+ image_fetcher::IOSImageDataFetcherCallback local_callback =
+ ^(NSData* data, const image_fetcher::RequestMetadata& metadata) {
+ if (metadata.response_code ==
+ image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID)
+ return;
+
+ std::vector<SkBitmap> frames;
+ std::vector<gfx::Size> sizes;
+ if (data) {
+ frames = skia::ImageDataToSkBitmaps(data);
+ for (const auto& frame : frames) {
+ sizes.push_back(gfx::Size(frame.width(), frame.height()));
+ }
+ }
+ local_image_callback.Run(local_download_id, metadata.response_code,
+ local_url, frames, sizes);
+ };
+ image_fetcher_.FetchImageDataWebpDecoded(url, local_callback);
+
+ return downloaded_image_count;
}
bool WebFaviconDriver::IsOffTheRecord() {
@@ -96,8 +131,9 @@ WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
history::HistoryService* history_service,
bookmarks::BookmarkModel* bookmark_model)
: web::WebStateObserver(web_state),
- FaviconDriverImpl(favicon_service, history_service, bookmark_model) {
-}
+ FaviconDriverImpl(favicon_service, history_service, bookmark_model),
+ image_fetcher_(web_state->GetBrowserState()->GetRequestContext(),
+ web::WebThread::GetBlockingPool()) {}
WebFaviconDriver::~WebFaviconDriver() {
}
« no previous file with comments | « components/favicon/ios/web_favicon_driver.h ('k') | components/image_fetcher/image_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698