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