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" | |
mlamouri (slow - plz ping)
2015/08/21 09:27:11
Do you need bind.h or callback_fwd.h?
Lalit Maganti
2015/08/21 12:14:19
Done.
| |
10 #include "base/memory/ref_counted.h" | |
mlamouri (slow - plz ping)
2015/08/21 09:27:12
Do you need this include?
Lalit Maganti
2015/08/21 12:14:19
Done.
| |
11 #include "content/public/browser/web_contents_observer.h" | |
mlamouri (slow - plz ping)
2015/08/21 09:27:12
I think you can remove this #include.
Lalit Maganti
2015/08/21 12:14:19
Done.
Lalit Maganti
2015/08/21 12:14:19
Done.
| |
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 // Downloads the icon located at icon_url. If the file contains multiple icons | |
25 // then it attempts to pick the one closest in size bigger than or | |
26 // equal to ideal_icon_size_in_dp, taking into account the density of the | |
27 // device. If a bigger icon is chosen then, the icon is scaled down to be | |
28 // equal to ideal_icon_size_in_dp. | |
29 class ManifestIconDownloader { | |
mlamouri (slow - plz ping)
2015/08/21 09:27:11
make it final?
Lalit Maganti
2015/08/21 12:14:19
Done.
| |
30 public: | |
31 using IconFetchCallback = base::Callback<void(const SkBitmap&)>; | |
32 | |
33 ManifestIconDownloader() = default; | |
34 ~ManifestIconDownloader() = default; | |
35 | |
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. | |
mlamouri (slow - plz ping)
2015/08/21 09:27:11
nit: line break after the first sentence.
Lalit Maganti
2015/08/21 12:14:19
Done.
| |
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(int ideal_icon_size_in_px, | |
47 int minimum_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(int ideal_icon_size_in_px, | |
56 const SkBitmap& bitmap, | |
57 const IconFetchCallback& callback); | |
58 | |
59 // |bitmaps| is assumed to be a vector of bitmaps sorted by size from biggest | |
60 // to smallest. | |
61 static int FindClosestBitmapIndex(int ideal_icon_size_in_px, | |
62 int minimum_icon_size_in_px, | |
63 const std::vector<SkBitmap>& bitmaps); | |
64 | |
65 friend class ManifestIconDownloaderTest; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader); | |
68 }; | |
69 | |
70 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ | |
OLD | NEW |