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 content::WebContentsObserver { | |
26 public: | |
27 using IconFetchCallback = base::Callback<void(const SkBitmap&)>; | |
28 | |
29 explicit ManifestIconDownloader(content::WebContents* web_contents); | |
30 ~ManifestIconDownloader() override = default; | |
31 | |
32 // Downloads the icon located at icon_url. If the file contains multiple icons | |
33 // then it attempts to pick the one closest in size bigger than or | |
34 // equal to ideal_icon_size_in_dp, taking into account the density of the | |
35 // device. If a bigger icon is chosen then ,the icon is scaled down to be | |
36 // equal to ideal_icon_size_in_dp. | |
37 // The boolean return value indicates if the download could be successfully | |
38 // started. If this is false then the callback will NOT be called. | |
mlamouri (slow - plz ping)
2015/08/07 10:11:12
Could you change the last two lines to:
Returns wh
Lalit Maganti
2015/08/07 13:04:30
Done.
| |
39 bool Download(const GURL& icon_url, | |
40 int ideal_icon_size_in_dp, | |
41 const IconFetchCallback& callback); | |
42 | |
43 private: | |
44 // Callback run after an attempt to download the manifest icon has been made. | |
mlamouri (slow - plz ping)
2015/08/07 10:11:11
nit: this comment is confusing because it might be
Lalit Maganti
2015/08/07 13:04:30
Fixed.
| |
45 static void OnIconFetched(const int ideal_icon_size_in_px, | |
46 const IconFetchCallback& callback, | |
47 int id, | |
48 int http_status_code, | |
49 const GURL& url, | |
50 const std::vector<SkBitmap>& bitmaps, | |
51 const std::vector<gfx::Size>& sizes); | |
52 | |
53 static int FindClosestBitmapIndex(const int ideal_icon_size_in_px, | |
54 const std::vector<SkBitmap>& bitmaps); | |
55 | |
56 friend class ManifestIconDownloaderTest; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader); | |
59 }; | |
60 | |
61 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_ | |
OLD | NEW |