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

Side by Side Diff: ios/chrome/browser/suggestions/image_fetcher_impl.mm

Issue 805713004: Cleanup image_fetcher::ImageFetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/threading/sequenced_worker_pool.h" 9 #include "base/threading/sequenced_worker_pool.h"
10 #include "ios/chrome/browser/net/image_fetcher.h" 10 #include "ios/chrome/browser/net/image_fetcher.h"
11 #include "net/url_request/url_request_context_getter.h"
11 #include "skia/ext/skia_utils_ios.h" 12 #include "skia/ext/skia_utils_ios.h"
12 13
13 namespace suggestions { 14 namespace suggestions {
14 15
15 ImageFetcherImpl::ImageFetcherImpl( 16 ImageFetcherImpl::ImageFetcherImpl(
16 net::URLRequestContextGetter* url_request_context, 17 net::URLRequestContextGetter* url_request_context,
17 base::SequencedWorkerPool* blocking_pool) { 18 base::SequencedWorkerPool* blocking_pool) {
18 imageFetcher_.reset(new image_fetcher::ImageFetcher(blocking_pool)); 19 imageFetcher_.reset(new image_fetcher::ImageFetcher(blocking_pool));
19 imageFetcher_->SetRequestContextGetter(url_request_context); 20 imageFetcher_->SetRequestContextGetter(url_request_context);
20 } 21 }
(...skipping 12 matching lines...) Expand all
33 base::Callback<void(const GURL&, const SkBitmap*)> callback) { 34 base::Callback<void(const GURL&, const SkBitmap*)> callback) {
34 if (image_url.is_empty()) { 35 if (image_url.is_empty()) {
35 callback.Run(url, nullptr); 36 callback.Run(url, nullptr);
36 if (delegate_) { 37 if (delegate_) {
37 delegate_->OnImageFetched(url, nullptr); 38 delegate_->OnImageFetched(url, nullptr);
38 } 39 }
39 return; 40 return;
40 } 41 }
41 // Copy url reference so it's retained. 42 // Copy url reference so it's retained.
42 const GURL page_url(url); 43 const GURL page_url(url);
43 image_fetcher::Callback fetcher_callback = 44 image_fetcher::ImageFetchedCallback fetcher_callback =
44 ^(const GURL& original_url, int response_code, NSData* data) { 45 ^(const GURL& original_url, int response_code, NSData* data) {
45 if (data) { 46 if (data) {
46 // Most likely always returns 1x images. 47 // Most likely always returns 1x images.
47 UIImage* image = [UIImage imageWithData:data scale:1]; 48 UIImage* image = [UIImage imageWithData:data scale:1];
48 if (image) { 49 if (image) {
49 SkBitmap bitmap = 50 SkBitmap bitmap =
50 gfx::CGImageToSkBitmap(image.CGImage, [image size], YES); 51 gfx::CGImageToSkBitmap(image.CGImage, [image size], YES);
51 callback.Run(page_url, &bitmap); 52 callback.Run(page_url, &bitmap);
52 if (delegate_) { 53 if (delegate_) {
53 delegate_->OnImageFetched(page_url, &bitmap); 54 delegate_->OnImageFetched(page_url, &bitmap);
54 } 55 }
55 return; 56 return;
56 } 57 }
57 } 58 }
58 callback.Run(page_url, nullptr); 59 callback.Run(page_url, nullptr);
59 if (delegate_) { 60 if (delegate_) {
60 delegate_->OnImageFetched(page_url, nullptr); 61 delegate_->OnImageFetched(page_url, nullptr);
61 } 62 }
62 }; 63 };
63 imageFetcher_->StartDownload(image_url, fetcher_callback); 64 imageFetcher_->StartDownload(image_url, fetcher_callback);
64 } 65 }
65 66
66 } // namespace suggestions 67 } // namespace suggestions
OLDNEW
« ios/chrome/browser/net/image_fetcher.mm ('K') | « ios/chrome/browser/net/image_fetcher_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698