Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: chrome/browser/manifest/manifest_icon_downloader.h

Issue 1261143004: Implement manifest icon downloader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix favicon fallback in add to homescreen helper Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/callback_fwd.h"
10 #include "third_party/skia/include/core/SkBitmap.h"
11
12 namespace content {
13 class WebContents;
14 } // namespace content
15
16 namespace gfx {
17 class Size;
18 } // namespace gfx
19
20 class GURL;
21
22 // Downloads the icon located at icon_url. If the file contains multiple icons
23 // then it attempts to pick the one closest in size bigger than or
24 // equal to ideal_icon_size_in_dp, taking into account the density of the
25 // device. If a bigger icon is chosen then, the icon is scaled down to be
26 // equal to ideal_icon_size_in_dp.
27 class ManifestIconDownloader final {
28 public:
29 using IconFetchCallback = base::Callback<void(const SkBitmap&)>;
30
31 ManifestIconDownloader() = default;
32 ~ManifestIconDownloader() = default;
33
34 // Returns whether the download has started.
35 // It will return false if the current context or information do not allow to
36 // download the image.
37 bool Download(content::WebContents* web_contents,
mlamouri (slow - plz ping) 2015/08/21 12:59:08 Hmm, again sorry for seeing that so late but it se
Lalit Maganti 2015/08/21 13:21:34 Done.
38 const GURL& icon_url,
39 int ideal_icon_size_in_dp,
40 const IconFetchCallback& callback);
41
42 private:
43 // Callback run after the manifest icon downloaded successfully or the
44 // download failed.
45 static void OnIconFetched(int ideal_icon_size_in_px,
46 int minimum_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(int ideal_icon_size_in_px,
55 const SkBitmap& bitmap,
56 const IconFetchCallback& callback);
57
58 static int FindClosestBitmapIndex(int ideal_icon_size_in_px,
59 int minimum_icon_size_in_px,
60 const std::vector<SkBitmap>& bitmaps);
61
62 friend class ManifestIconDownloaderTest;
63
64 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader);
65 };
66
67 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698