This source file includes following definitions.
- Clear
- Add
- Get
- ContainsPath
- GetIconSizeFromPath
#include "chrome/common/extensions/extension_icon_set.h"
#include "base/logging.h"
ExtensionIconSet::ExtensionIconSet() {}
ExtensionIconSet::~ExtensionIconSet() {}
void ExtensionIconSet::Clear() {
map_.clear();
}
void ExtensionIconSet::Add(int size, const std::string& path) {
DCHECK(!path.empty() && path[0] != '/');
map_[size] = path;
}
std::string ExtensionIconSet::Get(int size, MatchType match_type) const {
if (match_type == MATCH_EXACTLY) {
IconMap::const_iterator result = map_.find(size);
return result == map_.end() ? std::string() : result->second;
} else if (match_type == MATCH_SMALLER) {
IconMap::const_reverse_iterator result = map_.rend();
for (IconMap::const_reverse_iterator iter = map_.rbegin();
iter != map_.rend(); ++iter) {
if (iter->first <= size) {
result = iter;
break;
}
}
return result == map_.rend() ? std::string() : result->second;
} else {
DCHECK(match_type == MATCH_BIGGER);
IconMap::const_iterator result = map_.end();
for (IconMap::const_iterator iter = map_.begin(); iter != map_.end();
++iter) {
if (iter->first >= size) {
result = iter;
break;
}
}
return result == map_.end() ? std::string() : result->second;
}
}
bool ExtensionIconSet::ContainsPath(const std::string& path) const {
return GetIconSizeFromPath(path) != 0;
}
int ExtensionIconSet::GetIconSizeFromPath(const std::string& path) const {
if (path.empty())
return 0;
DCHECK(path[0] != '/') <<
"ExtensionIconSet stores icon paths without leading slash.";
for (IconMap::const_iterator iter = map_.begin(); iter != map_.end();
++iter) {
if (iter->second == path)
return iter->first;
}
return 0;
}