Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/renderer/image_downloader/single_image_downloader.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 // Static | |
| 13 void SingleImageDownloader::DownloadImage( | |
| 14 base::WeakPtr<RenderFrame> render_frame, | |
| 15 const GURL& url, | |
| 16 const DownloadImageCallback& cb) { | |
| 17 DCHECK(!cb.is_null()); | |
| 18 if (!render_frame) { | |
| 19 cb.Run(SkBitmap()); | |
| 20 return; | |
| 21 } | |
| 22 | |
| 23 std::unique_ptr<ImageDownloaderBase> image_downloader( | |
| 24 new ImageDownloaderBase(render_frame.get())); | |
| 25 ImageDownloaderBase* image_downloader_ptr = image_downloader.get(); | |
| 26 image_downloader_ptr->DownloadImage( | |
| 27 url, false, false, base::Bind(&SingleImageDownloader::DidDownloadImage, | |
| 28 base::Passed(&image_downloader), cb)); | |
| 29 } | |
| 30 | |
| 31 // Static | |
| 32 void SingleImageDownloader::DidDownloadImage( | |
| 33 std::unique_ptr<ImageDownloaderBase> image_downloader, | |
|
nasko
2017/01/04 17:45:33
nit: Maybe put a comment as to why image_download
xjz
2017/01/04 18:37:58
Done. Yes, this is to keep it alive while download
| |
| 34 const DownloadImageCallback& callback, | |
| 35 int http_status_code, | |
| 36 const std::vector<SkBitmap>& images) { | |
| 37 DCHECK(!callback.is_null()); | |
| 38 callback.Run(images.empty() ? SkBitmap() : images[0]); | |
| 39 } | |
| 40 | |
| 41 } // namespace content | |
| OLD | NEW |