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 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |
| 6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 |
| 14 namespace content { |
| 15 class WebContents; |
| 16 } // namespace content |
| 17 |
| 18 namespace gfx { |
| 19 class Size; |
| 20 } // namespace gfx |
| 21 |
| 22 class GURL; |
| 23 |
| 24 class ManifestIconDownloader { |
| 25 public: |
| 26 using IconFetchCallback = base::Callback<void(const SkBitmap&)>; |
| 27 |
| 28 ManifestIconDownloader() = default; |
| 29 ~ManifestIconDownloader() = default; |
| 30 |
| 31 // Downloads the icon located at icon_url. If the file contains multiple icons |
| 32 // then it attempts to pick the one closest in size bigger than or |
| 33 // equal to ideal_icon_size_in_dp, taking into account the density of the |
| 34 // device. If a bigger icon is chosen then ,the icon is scaled down to be |
| 35 // equal to ideal_icon_size_in_dp. |
| 36 // Returns whether the download has started. It will return false if the |
| 37 // current context or information do not allow to download the image. |
| 38 bool Download(content::WebContents* web_contents, |
| 39 const GURL& icon_url, |
| 40 int ideal_icon_size_in_dp, |
| 41 const IconFetchCallback& callback); |
| 42 |
| 43 private: |
| 44 // Callback run after the manifest icon downloaded successfully or the |
| 45 // download failed. |
| 46 static void OnIconFetched(const int ideal_icon_size_in_px, |
| 47 const int lowest_icon_size_in_px, |
| 48 const IconFetchCallback& callback, |
| 49 int id, |
| 50 int http_status_code, |
| 51 const GURL& url, |
| 52 const std::vector<SkBitmap>& bitmaps, |
| 53 const std::vector<gfx::Size>& sizes); |
| 54 |
| 55 static void ScaleIcon(const int ideal_icon_size_in_px, |
| 56 const SkBitmap& bitmap, |
| 57 const IconFetchCallback& callback); |
| 58 |
| 59 static int FindClosestBitmapIndex(const int ideal_icon_size_in_px, |
| 60 const int lowest_icon_size_in_px, |
| 61 const std::vector<SkBitmap>& bitmaps); |
| 62 |
| 63 friend class ManifestIconDownloaderTest; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader); |
| 66 }; |
| 67 |
| 68 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ |
OLD | NEW |