extension_icon_set.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2014 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. #ifndef EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_
  5. #define EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include "base/strings/string_piece.h"
  10. namespace base {
  11. class FilePath;
  12. }
  13. // Represents the set of icons for an extension.
  14. class ExtensionIconSet {
  15. public:
  16. // Get an icon from the set, optionally falling back to a smaller or bigger
  17. // size. MatchType is exclusive (do not OR them together).
  18. enum MatchType {
  19. MATCH_EXACTLY,
  20. MATCH_BIGGER,
  21. MATCH_SMALLER
  22. };
  23. // Access to the underlying map from icon size->{path, bitmap}.
  24. typedef std::map<int, std::string> IconMap;
  25. ExtensionIconSet();
  26. ExtensionIconSet(const ExtensionIconSet& other);
  27. ~ExtensionIconSet();
  28. const IconMap& map() const { return map_; }
  29. bool empty() const { return map_.empty(); }
  30. // Remove all icons from the set.
  31. void Clear();
  32. // Add an icon path to the set. If a path for the specified size_in_px is
  33. // already present, it is overwritten.
  34. void Add(int size_in_px, const std::string& path);
  35. // Gets path value of the icon found when searching for |size_in_px| using
  36. // |match_type|.
  37. const std::string& Get(int size_in_px, MatchType match_type) const;
  38. // Returns true iff the set contains the specified path.
  39. bool ContainsPath(base::StringPiece path) const;
  40. // Returns icon size (in pixels) if the set contains the specified path or 0
  41. // if not found.
  42. int GetIconSizeFromPath(base::StringPiece path) const;
  43. // Add the paths of all icons in this set into |paths|, handling the
  44. // conversion of (string) -> (base::FilePath). Note that these paths are not
  45. // validated in any way, so they may be invalid paths or reference
  46. // nonexistent files.
  47. void GetPaths(std::set<base::FilePath>* paths) const;
  48. private:
  49. IconMap map_;
  50. };
  51. #endif // EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_