| OLD | NEW |
| 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 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if (delegate_) { | 52 if (delegate_) { |
| 53 delegate_->OnImageFetched(id, empty_image); | 53 delegate_->OnImageFetched(id, empty_image); |
| 54 } | 54 } |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 // Copy string reference so it's retained. | 57 // Copy string reference so it's retained. |
| 58 const std::string fetch_id(id); | 58 const std::string fetch_id(id); |
| 59 // If image_fetcher_ is destroyed the request will be cancelled and this block | 59 // If image_fetcher_ is destroyed the request will be cancelled and this block |
| 60 // will never be called. A reference to delegate_ can be kept. | 60 // will never be called. A reference to delegate_ can be kept. |
| 61 image_fetcher::IOSImageDataFetcherCallback fetcher_callback = | 61 image_fetcher::IOSImageDataFetcherCallback fetcher_callback = |
| 62 ^(NSData* data) { | 62 ^(NSData* data, const std::string& mime_type) { |
| 63 if (data) { | 63 if (data) { |
| 64 // Most likely always returns 1x images. | 64 // Most likely always returns 1x images. |
| 65 UIImage* ui_image = [UIImage imageWithData:data scale:1]; | 65 UIImage* ui_image = [UIImage imageWithData:data scale:1]; |
| 66 if (ui_image) { | 66 if (ui_image) { |
| 67 gfx::Image gfx_image(ui_image, base::scoped_policy::ASSUME); | 67 gfx::Image gfx_image(ui_image, base::scoped_policy::ASSUME); |
| 68 callback.Run(fetch_id, gfx_image); | 68 callback.Run(fetch_id, gfx_image); |
| 69 if (delegate_) { | 69 if (delegate_) { |
| 70 delegate_->OnImageFetched(fetch_id, gfx_image); | 70 delegate_->OnImageFetched(fetch_id, gfx_image); |
| 71 } | 71 } |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 gfx::Image empty_image; | 75 gfx::Image empty_image; |
| 76 callback.Run(fetch_id, empty_image); | 76 callback.Run(fetch_id, empty_image); |
| 77 if (delegate_) { | 77 if (delegate_) { |
| 78 delegate_->OnImageFetched(fetch_id, empty_image); | 78 delegate_->OnImageFetched(fetch_id, empty_image); |
| 79 } | 79 } |
| 80 }; | 80 }; |
| 81 image_fetcher_->FetchImageDataWebpDecoded(image_url, fetcher_callback); | 81 image_fetcher_->FetchImageDataWebpDecoded(image_url, fetcher_callback); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace suggestions | 84 } // namespace suggestions |
| OLD | NEW |