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 | |
gone
2015/08/19 22:21:07
nit: This sounds more like a class comment. Consi
Lalit Maganti
2015/08/20 16:48:00
Done.
| |
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 IconFetchCallback& callback, | |
48 int id, | |
49 int http_status_code, | |
50 const GURL& url, | |
51 const std::vector<SkBitmap>& bitmaps, | |
52 const std::vector<gfx::Size>& sizes); | |
53 | |
54 static void ScaleIcon(const int ideal_icon_size_in_px, | |
55 const SkBitmap& bitmap, | |
56 const IconFetchCallback& callback); | |
57 | |
58 static int FindClosestBitmapIndex(const int ideal_icon_size_in_px, | |
59 const std::vector<SkBitmap>& bitmaps); | |
60 | |
61 friend class ManifestIconDownloaderTest; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader); | |
64 }; | |
65 | |
66 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ | |
OLD | NEW |