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

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: Address comments on review 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/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
mlamouri (slow - plz ping) 2015/08/10 15:08:08 nit: two spaces between "}" and "//"
Lalit Maganti 2015/08/10 16:55:46 Done.
21
22 class GURL;
23
24 class ManifestIconDownloader
25 : public content::WebContentsObserver {
mlamouri (slow - plz ping) 2015/08/10 15:08:08 Sorry to point that so late but it seems that usin
Lalit Maganti 2015/08/10 16:55:46 Done.
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 // Returns whether the download has started. It will return false if the
38 // current context or information do not allow to download the image.
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 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 static void ScaleIcon(const int ideal_icon_size_in_px,
mlamouri (slow - plz ping) 2015/08/10 15:08:08 nit: to be consistent, leave an empty line before
Lalit Maganti 2015/08/10 16:55:46 Done.
54 const SkBitmap& bitmap,
55 const IconFetchCallback& callback);
56 static void RunCallbackOnUIThread(
mlamouri (slow - plz ping) 2015/08/10 15:08:08 ditto
Lalit Maganti 2015/08/10 16:55:46 Removed altogether.
57 const ManifestIconDownloader::IconFetchCallback& callback,
58 const SkBitmap& bitmap);
59
60 static int FindClosestBitmapIndex(const int ideal_icon_size_in_px,
61 const std::vector<SkBitmap>& bitmaps);
62
63 friend class ManifestIconDownloaderTest;
64
65 DISALLOW_COPY_AND_ASSIGN(ManifestIconDownloader);
66 };
67
68 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_DOWNLOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698