1 // Copyright (c) 2012 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 #include "chrome/common/extensions/extension_icon_set.h"
7 #include "base/logging.h"
9 ExtensionIconSet::ExtensionIconSet() {}
11 ExtensionIconSet::~ExtensionIconSet() {}
13 void ExtensionIconSet::Clear() {
17 void ExtensionIconSet::Add(int size
, const std::string
& path
) {
18 DCHECK(!path
.empty() && path
[0] != '/');
22 std::string
ExtensionIconSet::Get(int size
, MatchType match_type
) const {
23 // The searches for MATCH_BIGGER and MATCH_SMALLER below rely on the fact that
24 // std::map is sorted. This is per the spec, so it should be safe to rely on.
25 if (match_type
== MATCH_EXACTLY
) {
26 IconMap::const_iterator result
= map_
.find(size
);
27 return result
== map_
.end() ? std::string() : result
->second
;
28 } else if (match_type
== MATCH_SMALLER
) {
29 IconMap::const_reverse_iterator result
= map_
.rend();
30 for (IconMap::const_reverse_iterator iter
= map_
.rbegin();
31 iter
!= map_
.rend(); ++iter
) {
32 if (iter
->first
<= size
) {
37 return result
== map_
.rend() ? std::string() : result
->second
;
39 DCHECK(match_type
== MATCH_BIGGER
);
40 IconMap::const_iterator result
= map_
.end();
41 for (IconMap::const_iterator iter
= map_
.begin(); iter
!= map_
.end();
43 if (iter
->first
>= size
) {
48 return result
== map_
.end() ? std::string() : result
->second
;
52 bool ExtensionIconSet::ContainsPath(const std::string
& path
) const {
53 return GetIconSizeFromPath(path
) != 0;
56 int ExtensionIconSet::GetIconSizeFromPath(const std::string
& path
) const {
60 DCHECK(path
[0] != '/') <<
61 "ExtensionIconSet stores icon paths without leading slash.";
63 for (IconMap::const_iterator iter
= map_
.begin(); iter
!= map_
.end();
65 if (iter
->second
== path
)