Index: content/browser/image_downloader/image_downloader_dispatcher.cc |
diff --git a/content/browser/image_downloader/image_downloader_dispatcher.cc b/content/browser/image_downloader/image_downloader_dispatcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aecf17ca5acd8fb359d4c4506f6462c8ef3bbfdb |
--- /dev/null |
+++ b/content/browser/image_downloader/image_downloader_dispatcher.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2015 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 "content/browser/image_downloader/image_downloader_dispatcher.h" |
+ |
+#include "content/public/browser/render_frame_host.h" |
+#include "content/public/common/service_registry.h" |
+#include "mojo/common/url_type_converters.h" |
+#include "mojo/converters/geometry/geometry_type_converters.h" |
+#include "skia/public/type_converters.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "url/gurl.h" |
+ |
+namespace content { |
+namespace { |
+ |
+void DidDownload(const WebContents::ImageDownloadCallback& callback, |
+ int id, |
+ image_downloader::DownloadResultPtr result) { |
+ DCHECK(result); |
+ |
+ const GURL image_url = result->url.To<GURL>(); |
+ const std::vector<SkBitmap> images = |
+ result->images.To<std::vector<SkBitmap>>(); |
+ const std::vector<gfx::Size> original_image_sizes = |
+ result->original_image_sizes.To<std::vector<gfx::Size>>(); |
+ |
+ callback.Run(id, result->http_status_code, image_url, images, |
+ original_image_sizes); |
+} |
+ |
+} // namespace |
+ |
+// static |
+int ImageDownloaderDispatcher::next_image_download_id_ = 0; |
+ |
+ImageDownloaderDispatcher::ImageDownloaderDispatcher( |
+ RenderFrameHost* render_frame_host) |
+ : render_frame_host_(render_frame_host) { |
+ DCHECK(render_frame_host_); |
+} |
+ |
+ImageDownloaderDispatcher::~ImageDownloaderDispatcher() { |
+} |
+ |
+int ImageDownloaderDispatcher::StartDownload( |
+ const GURL& url, |
+ bool is_favicon, |
+ uint32_t max_bitmap_size, |
+ bool bypass_cache, |
+ const WebContents::ImageDownloadCallback& callback) { |
+ image_downloader::DownloadReqPtr req = image_downloader::DownloadReq::New(); |
+ |
+ if (!downloader_.get()) { |
+ render_frame_host_->GetServiceRegistry()->ConnectToRemoteService( |
+ &downloader_); |
+ downloader_.set_error_handler(this); |
+ } |
+ |
+ req->url = mojo::String::From(url); |
+ req->is_favicon = is_favicon; |
+ req->max_bitmap_size = max_bitmap_size; |
+ req->bypass_cache = bypass_cache; |
+ |
+ downloader_->DownloadImage(req.Pass(), base::Bind(&DidDownload, callback, |
+ ++next_image_download_id_)); |
+ return next_image_download_id_; |
+} |
+ |
+void ImageDownloaderDispatcher::OnConnectionError() { |
+ downloader_.reset(); |
+} |
+ |
+} // namespace content |