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

Side by Side Diff: content/browser/image_downloader/image_downloader_dispatcher.cc

Issue 1085783002: Replace image_messages.h with Mojo service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to master@{#333882} Created 5 years, 6 months 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/image_downloader/image_downloader_dispatcher.h"
6
7 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/common/service_registry.h"
9 #include "mojo/common/url_type_converters.h"
10 #include "mojo/converters/geometry/geometry_type_converters.h"
11 #include "skia/public/type_converters.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "url/gurl.h"
15
16 namespace content {
17 namespace {
18
19 void DidDownload(const WebContents::ImageDownloadCallback& callback,
20 int id,
21 const GURL& image_url,
22 image_downloader::DownloadResultPtr result) {
23 DCHECK(result);
24
25 const std::vector<SkBitmap> images =
26 result->images.To<std::vector<SkBitmap>>();
27 const std::vector<gfx::Size> original_image_sizes =
28 result->original_image_sizes.To<std::vector<gfx::Size>>();
29
30 callback.Run(id, result->http_status_code, image_url, images,
31 original_image_sizes);
32 }
33
34 } // namespace
35
36 // static
37 int ImageDownloaderDispatcher::next_image_download_id_ = 0;
38
39 ImageDownloaderDispatcher::ImageDownloaderDispatcher(
40 RenderFrameHost* render_frame_host)
41 : render_frame_host_(render_frame_host) {
42 DCHECK(render_frame_host_);
43 }
44
45 ImageDownloaderDispatcher::~ImageDownloaderDispatcher() {
46 }
47
48 int ImageDownloaderDispatcher::StartDownload(
49 const GURL& url,
50 bool is_favicon,
51 uint32_t max_bitmap_size,
52 bool bypass_cache,
53 const WebContents::ImageDownloadCallback& callback) {
54 image_downloader::DownloadRequestPtr req =
55 image_downloader::DownloadRequest::New();
56
57 if (!downloader_.get()) {
58 render_frame_host_->GetServiceRegistry()->ConnectToRemoteService(
59 mojo::GetProxy(&downloader_));
60 downloader_.set_error_handler(this);
61 }
62
63 req->url = mojo::String::From(url);
64 req->is_favicon = is_favicon;
65 req->max_bitmap_size = max_bitmap_size;
66 req->bypass_cache = bypass_cache;
67
68 downloader_->DownloadImage(
69 req.Pass(),
70 base::Bind(&DidDownload, callback, ++next_image_download_id_, url));
71 return next_image_download_id_;
72 }
73
74 void ImageDownloaderDispatcher::OnConnectionError() {
75 downloader_.reset();
76 }
77
78 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698