summaryrefslogtreecommitdiffstats
path: root/extensions/common/extension_icon_set.h
blob: e491b72c111724200c792dde5c0fd9be98ce72da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2014 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 EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_
#define EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_

#include <map>
#include <set>
#include <string>

namespace base {
class FilePath;
}

// Represents the set of icons for an extension.
class ExtensionIconSet {
 public:
  // Get an icon from the set, optionally falling back to a smaller or bigger
  // size. MatchType is exclusive (do not OR them together).
  enum MatchType {
    MATCH_EXACTLY,
    MATCH_BIGGER,
    MATCH_SMALLER
  };

  // Access to the underlying map from icon size->{path, bitmap}.
  typedef std::map<int, std::string> IconMap;

  ExtensionIconSet();
  ~ExtensionIconSet();

  const IconMap& map() const { return map_; }
  bool empty() const { return map_.empty(); }

  // Remove all icons from the set.
  void Clear();

  // Add an icon path to the set. If a path for the specified size is already
  // present, it is overwritten.
  void Add(int size, const std::string& path);

  // Gets path value of the icon found when searching for |size| using
  // |mathc_type|.
  const std::string& Get(int size, MatchType match_type) const;

  // Returns true iff the set contains the specified path.
  bool ContainsPath(const std::string& path) const;

  // Returns icon size if the set contains the specified path or 0 if not found.
  int GetIconSizeFromPath(const std::string& path) const;

  // Add the paths of all icons in this set into |paths|, handling the
  // conversion of (string) -> (base::FilePath). Note that these paths are not
  // validated in any way, so they may be invalid paths or reference
  // nonexistent files.
  void GetPaths(std::set<base::FilePath>* paths) const;

 private:
  IconMap map_;
};

#endif  // EXTENSIONS_COMMON_EXTENSION_ICON_SET_H_