Chromium Code Reviews| Index: chrome/common/extensions/extension_icon_set.cc |
| diff --git a/chrome/common/extensions/extension_icon_set.cc b/chrome/common/extensions/extension_icon_set.cc |
| index 588d0546f12f0cd5baffee63fb8c3fce781f9fb3..f1750a5235f4eef93c091a3899565c9d1f5824df 100644 |
| --- a/chrome/common/extensions/extension_icon_set.cc |
| +++ b/chrome/common/extensions/extension_icon_set.cc |
| @@ -6,29 +6,52 @@ |
| #include "base/logging.h" |
| -ExtensionIconSet::ExtensionIconSet() {} |
| +namespace { |
| -ExtensionIconSet::~ExtensionIconSet() {} |
| - |
| -const ExtensionIconSet::Icons ExtensionIconSet::kIconSizes[] = { |
| - EXTENSION_ICON_GIGANTOR, |
| - EXTENSION_ICON_EXTRA_LARGE, |
| - EXTENSION_ICON_LARGE, |
| - EXTENSION_ICON_MEDIUM, |
| - EXTENSION_ICON_SMALL, |
| - EXTENSION_ICON_SMALLISH, |
| - EXTENSION_ICON_BITTY |
| +const int kExtensionIconSizes[] = { |
|
Aaron Boodman
2012/08/10 23:01:57
Now that this class is more general purpose, move
tbarzic
2012/08/11 00:58:45
Done.
|
| + ExtensionIconSet::EXTENSION_ICON_GIGANTOR, // 512 |
| + ExtensionIconSet::EXTENSION_ICON_EXTRA_LARGE, // 256 |
| + ExtensionIconSet::EXTENSION_ICON_LARGE, // 128 |
| + ExtensionIconSet::EXTENSION_ICON_MEDIUM, // 48 |
| + ExtensionIconSet::EXTENSION_ICON_SMALL, // 32 |
| + ExtensionIconSet::EXTENSION_ICON_SMALLISH, // 24 |
| + ExtensionIconSet::EXTENSION_ICON_BITTY // 16 |
| }; |
| -const size_t ExtensionIconSet::kNumIconSizes = |
| - arraysize(ExtensionIconSet::kIconSizes); |
| +bool IsInArray(const int* const array, size_t array_size, int value) { |
| + for (size_t i = 0; i < array_size; i++) { |
| + if (array[i] == value) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| +ExtensionIconSet::ExtensionIconSet(IconSetType type) |
| + : allowed_sizes_(NULL), |
| + num_allowed_sizes_(0){ |
| + switch (type) { |
| + case ICON_SET_MANIFEST_ICONS: |
| + allowed_sizes_ = kExtensionIconSizes; |
|
Aaron Boodman
2012/08/10 23:01:57
I do not think it is necessary to validate that th
tbarzic
2012/08/11 00:58:45
Done.
|
| + num_allowed_sizes_ = arraysize(kExtensionIconSizes); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| + |
| +} |
| + |
| +ExtensionIconSet::~ExtensionIconSet() {} |
| void ExtensionIconSet::Clear() { |
| map_.clear(); |
| } |
| -void ExtensionIconSet::Add(Icons size, const std::string& path) { |
| +void ExtensionIconSet::Add(int size, const std::string& path) { |
| DCHECK(!path.empty() && path[0] != '/'); |
| + CHECK(IsInArray(allowed_sizes_, num_allowed_sizes_, size)); |
| + |
| map_[size] = path; |
| } |
| @@ -36,7 +59,7 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const { |
| // The searches for MATCH_BIGGER and MATCH_SMALLER below rely on the fact that |
| // std::map is sorted. This is per the spec, so it should be safe to rely on. |
| if (match_type == MATCH_EXACTLY) { |
| - IconMap::const_iterator result = map_.find(static_cast<Icons>(size)); |
| + 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(); |
| @@ -63,13 +86,12 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const { |
| } |
| bool ExtensionIconSet::ContainsPath(const std::string& path) const { |
| - return GetIconSizeFromPath(path) != EXTENSION_ICON_INVALID; |
| + return GetIconSizeFromPath(path) != 0; |
| } |
| -ExtensionIconSet::Icons ExtensionIconSet::GetIconSizeFromPath( |
| - const std::string& path) const { |
| +int ExtensionIconSet::GetIconSizeFromPath(const std::string& path) const { |
| if (path.empty()) |
| - return EXTENSION_ICON_INVALID; |
| + return 0; |
| DCHECK(path[0] != '/') << |
| "ExtensionIconSet stores icon paths without leading slash."; |
| @@ -80,5 +102,5 @@ ExtensionIconSet::Icons ExtensionIconSet::GetIconSizeFromPath( |
| return iter->first; |
| } |
| - return EXTENSION_ICON_INVALID; |
| + return 0; |
| } |