Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / manifest / manifest_icon_selector.h
blob8bad2144871d30cba2c6bfb0f064117bf6bee222
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.
5 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
8 #include "base/basictypes.h"
9 #include "content/public/common/manifest.h"
10 #include "url/gurl.h"
12 namespace content {
13 class WebContents;
14 } // namespace content
16 namespace IPC {
17 class Message;
18 } // namespace IPC
20 namespace gfx {
21 class Screen;
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.
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.
36 // The icon returned will have a minimum size of an image one density bucket
37 // smaller than the device denisity * preferred_icon_size_in_dp.
39 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
40 static GURL FindBestMatchingIcon(
41 const std::vector<content::Manifest::Icon>& icons,
42 float preferred_icon_size_in_dp,
43 const gfx::Screen* screen);
45 private:
46 ManifestIconSelector(float preferred_icon_size_in_pixels,
47 float minimum_icon_size_in_pixels);
48 virtual ~ManifestIconSelector() {}
50 // Runs the algorithm to find the best matching icon in the icons listed in
51 // the Manifest.
52 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
53 int FindBestMatchingIcon(
54 const std::vector<content::Manifest::Icon>& icons,
55 float density);
57 // Runs an algorithm only based on icon declared sizes. It will try to find
58 // size that is the closest to preferred_icon_size_in_pixels_ but bigger than
59 // preferred_icon_size_in_pixels_ if possible.
60 // Returns the index of a suitable icon if one is found. -1 otherwise.
61 int FindBestMatchingIconForDensity(
62 const std::vector<content::Manifest::Icon>& icons,
63 float density);
65 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
66 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes);
68 // Returns whether a size bigger than |minimun_icon_size_in_pixels_| is in
69 // |sizes|.
70 bool IconSizesContainsBiggerThanMinimumSize(
71 const std::vector<gfx::Size>& sizes);
73 // Returns an array containing the items in |icons| without the unsupported
74 // image MIME types.
75 static std::vector<content::Manifest::Icon> FilterIconsByType(
76 const std::vector<content::Manifest::Icon>& icons);
78 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
79 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
81 const int preferred_icon_size_in_pixels_;
82 const int minimum_icon_size_in_pixels_;
84 friend class ManifestIconSelectorTest;
86 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
89 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_