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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ios/chrome/browser/suggestions/image_fetcher_impl.h" 5 #include "ios/chrome/browser/suggestions/image_fetcher_impl.h"
6 6
7 #include <UIKit/UIKit.h> 7 #include <UIKit/UIKit.h>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
10 #include "components/image_fetcher/image_fetcher_delegate.h" 11 #include "components/image_fetcher/image_fetcher_delegate.h"
11 #include "ios/chrome/browser/net/image_fetcher.h" 12 #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.
12 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
13 #include "skia/ext/skia_utils_ios.h" 14 #include "skia/ext/skia_utils_ios.h"
14 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
15 16
16 namespace suggestions { 17 namespace suggestions {
17 18
18 ImageFetcherImpl::ImageFetcherImpl( 19 ImageFetcherImpl::ImageFetcherImpl(
19 net::URLRequestContextGetter* url_request_context, 20 net::URLRequestContextGetter* url_request_context,
20 base::SequencedWorkerPool* blocking_pool) { 21 base::SequencedWorkerPool* blocking_pool)
21 imageFetcher_.reset(new ::ImageFetcher(blocking_pool)); 22 : image_fetcher_(base::MakeUnique<web::ImageDataFetcher>(blocking_pool)) {
22 imageFetcher_->SetRequestContextGetter(url_request_context); 23 image_fetcher_->SetRequestContextGetter(url_request_context);
23 } 24 }
24 25
25 ImageFetcherImpl::~ImageFetcherImpl() { 26 ImageFetcherImpl::~ImageFetcherImpl() {
26 } 27 }
27 28
28 void ImageFetcherImpl::SetImageFetcherDelegate( 29 void ImageFetcherImpl::SetImageFetcherDelegate(
29 image_fetcher::ImageFetcherDelegate* delegate) { 30 image_fetcher::ImageFetcherDelegate* delegate) {
30 DCHECK(delegate); 31 DCHECK(delegate);
31 delegate_ = delegate; 32 delegate_ = delegate;
32 } 33 }
(...skipping 12 matching lines...) Expand all
45 if (image_url.is_empty()) { 46 if (image_url.is_empty()) {
46 gfx::Image empty_image; 47 gfx::Image empty_image;
47 callback.Run(id, empty_image); 48 callback.Run(id, empty_image);
48 if (delegate_) { 49 if (delegate_) {
49 delegate_->OnImageFetched(id, empty_image); 50 delegate_->OnImageFetched(id, empty_image);
50 } 51 }
51 return; 52 return;
52 } 53 }
53 // Copy string reference so it's retained. 54 // Copy string reference so it's retained.
54 const std::string fetch_id(id); 55 const std::string fetch_id(id);
55 ImageFetchedCallback fetcher_callback = 56 // If image_fetcher_ is destroyed the request will be cancelled and this block
57 // will never be called. A reference to delegate_ can be kept.
58 web::ImageFetchedCallback fetcher_callback =
56 ^(const GURL& original_url, int response_code, NSData* data) { 59 ^(const GURL& original_url, int response_code, NSData* data) {
57 if (data) { 60 if (data) {
58 // Most likely always returns 1x images. 61 // Most likely always returns 1x images.
59 UIImage* ui_image = [UIImage imageWithData:data scale:1]; 62 UIImage* ui_image = [UIImage imageWithData:data scale:1];
60 if (ui_image) { 63 if (ui_image) {
61 gfx::Image gfx_image(ui_image); 64 gfx::Image gfx_image(ui_image);
62 callback.Run(fetch_id, gfx_image); 65 callback.Run(fetch_id, gfx_image);
63 if (delegate_) { 66 if (delegate_) {
64 delegate_->OnImageFetched(fetch_id, gfx_image); 67 delegate_->OnImageFetched(fetch_id, gfx_image);
68 }
69 return;
65 } 70 }
66 return;
67 } 71 }
68 } 72 gfx::Image empty_image;
69 gfx::Image empty_image; 73 callback.Run(fetch_id, empty_image);
70 callback.Run(fetch_id, empty_image); 74 if (delegate_) {
71 if (delegate_) { 75 delegate_->OnImageFetched(fetch_id, empty_image);
72 delegate_->OnImageFetched(fetch_id, empty_image); 76 }
73 } 77 };
74 }; 78 image_fetcher_->StartDownload(image_url, fetcher_callback);
75 imageFetcher_->StartDownload(image_url, fetcher_callback);
76 } 79 }
77 80
78 } // namespace suggestions 81 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698