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

Side by Side Diff: chrome/browser/android/manifest_icon_selector.h

Issue 880203004: Break out manifest icon logic from ShortcutHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing unittest Created 5 years, 10 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_ANDROID_MANIFEST_ICON_SELECTOR_H_
6 #define CHROME_BROWSER_ANDROID_MANIFEST_ICON_SELECTOR_H_
7
8 #include "base/basictypes.h"
9 #include "content/public/common/manifest.h"
10 #include "url/gurl.h"
11
12 namespace content {
13 class WebContents;
14 } // namespace content
15
16 namespace IPC {
17 class Message;
18 } // namespace IPC
19
20 namespace gfx {
21 class Screen;
22 }
23
24 // Selects the icon most closely matching the size constraints. This follows
25 // very basic heuristics -- improvements are welcome.
26 class ManifestIconSelector {
27 public:
28 // Runs the algorithm to find the best matching icon in the icons listed in
29 // the Manifest.
30 //
31 // Size is defined in Android's density-independent pixels (dp):
32 // http://developer.android.com/guide/practices/screens_support.html
33 // If/when this class is generalized, it may be a good idea to switch this to
34 // taking in pixels, instead.
35 //
36 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
37 static GURL FindBestMatchingIcon(
38 const std::vector<content::Manifest::Icon>& icons,
39 float preferred_icon_size_in_dp,
40 const gfx::Screen* screen);
41
42 private:
43 explicit ManifestIconSelector(float preferred_icon_size_in_pixels);
44 virtual ~ManifestIconSelector() {}
45
46 // Runs the algorithm to find the best matching icon in the icons listed in
47 // the Manifest.
48 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
49 GURL FindBestMatchingIcon(
50 const std::vector<content::Manifest::Icon>& icons,
51 float density);
52
53 // Runs an algorithm only based on icon declared sizes. It will try to find
54 // size that is the closest to preferred_icon_size_in_pixels_ but bigger than
55 // preferred_icon_size_in_pixels_ if possible.
56 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
57 GURL FindBestMatchingIconForDensity(
58 const std::vector<content::Manifest::Icon>& icons,
59 float density);
60
61 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
62 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes);
63
64 // Returns an array containing the items in |icons| without the unsupported
65 // image MIME types.
66 static std::vector<content::Manifest::Icon> FilterIconsByType(
67 const std::vector<content::Manifest::Icon>& icons);
68
69 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
70 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
71
72 const int preferred_icon_size_in_pixels_;
73
74 friend class ManifestIconSelectorTest;
75
76 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
77 };
78
79 #endif // CHROME_BROWSER_ANDROID_MANIFEST_ICON_SELECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_manager.cc ('k') | chrome/browser/android/manifest_icon_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698