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

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

Issue 790773003: Upstream iOS SuggestionsServiceFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@436897.1
Patch Set: Rebase 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 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
new file mode 100644
index 0000000000000000000000000000000000000000..78f20e625a6941e44172da092bee6bf672900f1b
--- /dev/null
+++ b/ios/chrome/browser/suggestions/image_fetcher_impl.mm
@@ -0,0 +1,66 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/suggestions/image_fetcher_impl.h"
+
+#include <UIKit/UIKit.h>
+
+#include "base/threading/sequenced_worker_pool.h"
+#include "ios/chrome/browser/net/image_fetcher.h"
+#include "skia/ext/skia_utils_ios.h"
+
+namespace suggestions {
+
+ImageFetcherImpl::ImageFetcherImpl(
+ net::URLRequestContextGetter* url_request_context,
+ base::SequencedWorkerPool* blocking_pool) {
+ imageFetcher_.reset(new image_fetcher::ImageFetcher(blocking_pool));
+ imageFetcher_->SetRequestContextGetter(url_request_context);
+}
+
+ImageFetcherImpl::~ImageFetcherImpl() {
+}
+
+void ImageFetcherImpl::SetImageFetcherDelegate(ImageFetcherDelegate* delegate) {
+ DCHECK(delegate);
+ delegate_ = delegate;
+}
+
+void ImageFetcherImpl::StartOrQueueNetworkRequest(
+ const GURL& url,
+ const GURL& image_url,
+ base::Callback<void(const GURL&, const SkBitmap*)> callback) {
+ if (image_url.is_empty()) {
+ callback.Run(url, nullptr);
+ if (delegate_) {
+ delegate_->OnImageFetched(url, nullptr);
+ }
+ return;
+ }
+ // Copy url reference so it's retained.
+ const GURL page_url(url);
+ image_fetcher::Callback fetcher_callback =
+ ^(const GURL& original_url, int response_code, NSData* data) {
+ if (data) {
+ // Most likely always returns 1x images.
+ UIImage* image = [UIImage imageWithData:data scale:1];
+ if (image) {
+ SkBitmap bitmap =
+ gfx::CGImageToSkBitmap(image.CGImage, [image size], YES);
+ callback.Run(page_url, &bitmap);
+ if (delegate_) {
+ delegate_->OnImageFetched(page_url, &bitmap);
+ }
+ return;
+ }
+ }
+ callback.Run(page_url, nullptr);
+ if (delegate_) {
+ delegate_->OnImageFetched(page_url, nullptr);
+ }
+ };
+ imageFetcher_->StartDownload(image_url, fetcher_callback);
+}
+
+} // namespace suggestions
« no previous file with comments | « ios/chrome/browser/suggestions/image_fetcher_impl.h ('k') | ios/chrome/browser/suggestions/suggestions_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698