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

Unified Diff: ios/chrome/browser/suggestions/image_fetcher_impl.mm

Issue 2526773002: Move iOS ImageFetcher to ios/web/public (Closed)
Patch Set: Rename to image data fetcher Created 4 years 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: ios/chrome/browser/suggestions/image_fetcher_impl.mm
diff --git a/ios/chrome/browser/suggestions/image_fetcher_impl.mm b/ios/chrome/browser/suggestions/image_fetcher_impl.mm
index 70d93428d5d597d3fdd4bb2fe9b7ddd5c812bc81..98841038559ed78a849d354285b41297d73517ae 100644
--- a/ios/chrome/browser/suggestions/image_fetcher_impl.mm
+++ b/ios/chrome/browser/suggestions/image_fetcher_impl.mm
@@ -6,9 +6,10 @@
#include <UIKit/UIKit.h>
+#include "base/memory/ptr_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "components/image_fetcher/image_fetcher_delegate.h"
-#include "ios/chrome/browser/net/image_fetcher.h"
+#include "ios/web/public/image_fetcher/image_data_fetcher.h"
Eugene But (OOO till 7-30) 2016/12/01 16:52:01 s/include/import
gambard 2016/12/02 08:06:12 Done.
#include "net/url_request/url_request_context_getter.h"
#include "skia/ext/skia_utils_ios.h"
#include "ui/gfx/image/image.h"
@@ -17,9 +18,9 @@ namespace suggestions {
ImageFetcherImpl::ImageFetcherImpl(
net::URLRequestContextGetter* url_request_context,
- base::SequencedWorkerPool* blocking_pool) {
- imageFetcher_.reset(new ::ImageFetcher(blocking_pool));
- imageFetcher_->SetRequestContextGetter(url_request_context);
+ base::SequencedWorkerPool* blocking_pool)
+ : image_fetcher_(base::MakeUnique<web::ImageDataFetcher>(blocking_pool)) {
+ image_fetcher_->SetRequestContextGetter(url_request_context);
}
ImageFetcherImpl::~ImageFetcherImpl() {
@@ -52,27 +53,29 @@ void ImageFetcherImpl::StartOrQueueNetworkRequest(
}
// Copy string reference so it's retained.
const std::string fetch_id(id);
- ImageFetchedCallback fetcher_callback =
+ // If image_fetcher_ is destroyed the request will be cancelled and this block
+ // will never be called. A reference to delegate_ can be kept.
+ web::ImageFetchedCallback fetcher_callback =
^(const GURL& original_url, int response_code, NSData* data) {
- if (data) {
- // Most likely always returns 1x images.
- UIImage* ui_image = [UIImage imageWithData:data scale:1];
- if (ui_image) {
- gfx::Image gfx_image(ui_image);
- callback.Run(fetch_id, gfx_image);
- if (delegate_) {
- delegate_->OnImageFetched(fetch_id, gfx_image);
+ if (data) {
+ // Most likely always returns 1x images.
+ UIImage* ui_image = [UIImage imageWithData:data scale:1];
+ if (ui_image) {
+ gfx::Image gfx_image(ui_image);
+ callback.Run(fetch_id, gfx_image);
+ if (delegate_) {
+ delegate_->OnImageFetched(fetch_id, gfx_image);
+ }
+ return;
}
- return;
}
- }
- gfx::Image empty_image;
- callback.Run(fetch_id, empty_image);
- if (delegate_) {
- delegate_->OnImageFetched(fetch_id, empty_image);
- }
- };
- imageFetcher_->StartDownload(image_url, fetcher_callback);
+ gfx::Image empty_image;
+ callback.Run(fetch_id, empty_image);
+ if (delegate_) {
+ delegate_->OnImageFetched(fetch_id, empty_image);
+ }
+ };
+ image_fetcher_->StartDownload(image_url, fetcher_callback);
}
} // namespace suggestions

Powered by Google App Engine
This is Rietveld 408576698