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