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

Unified 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: Header removal Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/manifest_icon_selector.h
diff --git a/chrome/browser/android/manifest_icon_selector.h b/chrome/browser/android/manifest_icon_selector.h
new file mode 100644
index 0000000000000000000000000000000000000000..0f076f4b3d9b24a5a595e08aa5b984477fcef624
--- /dev/null
+++ b/chrome/browser/android/manifest_icon_selector.h
@@ -0,0 +1,63 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_MANIFEST_ICON_SELECTOR_H_
+#define CHROME_BROWSER_ANDROID_MANIFEST_ICON_SELECTOR_H_
+
+#include "base/basictypes.h"
+#include "content/public/common/manifest.h"
+#include "url/gurl.h"
+
+namespace content {
+class WebContents;
+} // namespace content
+
+namespace IPC {
+class Message;
+} // namespace IPC
+
+// Selects the icon most closely matching the size constraints. This follows
+// very basic heuristics -- improvements are welcome.
+class ManifestIconSelector {
+ public:
+ // Runs the algorithm to find the best matching icon in the icons listed in
+ // the Manifest.
+ // Returns the icon url if a suitable icon is found. An empty URL otherwise.
+ static GURL FindBestMatchingIcon(
+ const std::vector<content::Manifest::Icon>& icons,
+ float preferred_size_in_dp,
+ content::WebContents* web_contents);
mlamouri (slow - plz ping) 2015/01/30 22:32:13 Wouldn't that be better to not depend on WebConten
gone 2015/01/30 22:43:30 The logic is used in three different places, thoug
+
+ private:
+ ManifestIconSelector() {}
+ virtual ~ManifestIconSelector() {}
+
+ // Returns an array containing the items in |icons| without the unsupported
+ // image MIME types.
+ static std::vector<content::Manifest::Icon> FilterIconsByType(
+ const std::vector<content::Manifest::Icon>& icons);
+
+ // Runs an algorithm only based on icon declared sizes. It will try to find
+ // size that is the closest to preferred_icon_size_in_px_ but bigger than
+ // preferred_icon_size_in_px_ if possible.
+ // Returns the icon url if a suitable icon is found. An empty URL otherwise.
+ static GURL FindBestMatchingIcon(
+ const std::vector<content::Manifest::Icon>& icons,
+ float density,
+ int preferred_icon_size_in_px);
+
+ // Returns whether the |preferred_icon_size_in_px| is in the given |sizes|.
+ static bool IconSizesContainsPreferredSize(
+ const std::vector<gfx::Size>& sizes,
+ int preferred_icon_size_in_px);
+
+ // Returns whether the 'any' (ie. gfx::Size(0,0)) is in the given |sizes|.
+ static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
+
+ friend class ManifestIconSelectorTest;
+
+ DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
+};
+
+#endif // CHROME_BROWSER_ANDROID_MANIFEST_ICON_SELECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698