Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / manifest / manifest_icon_selector.h
blobc0c582d729c26cf2440f97cedfa247aed36ea4f5
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 // 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);
42 private:
43 explicit ManifestIconSelector(float preferred_icon_size_in_pixels);
44 virtual ~ManifestIconSelector() {}
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);
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);
61 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
62 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes);
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);
69 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
70 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
72 const int preferred_icon_size_in_pixels_;
74 friend class ManifestIconSelectorTest;
76 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
79 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_