Commit 1771f16a authored by kalman@chromium.org's avatar kalman@chromium.org

Cleanup: Make ExtensionIconSet::Get return a const std::string& rather than a

std::string.

R=mek@chromium.org

Review URL: https://codereview.chromium.org/448193002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288156 0039d316-1c4b-4281-b951-d872f2087c98
parent 88d32daf
......@@ -694,9 +694,8 @@ bool SandboxedUnpacker::RewriteImageFiles(SkBitmap* install_icon) {
}
}
std::string install_icon_path = IconsInfo::GetIcons(extension_).Get(
extension_misc::EXTENSION_ICON_LARGE,
ExtensionIconSet::MATCH_BIGGER);
const std::string& install_icon_path = IconsInfo::GetIcons(extension_).Get(
extension_misc::EXTENSION_ICON_LARGE, ExtensionIconSet::MATCH_BIGGER);
// Write our parsed images back to disk as well.
for (size_t i = 0; i < images.size(); ++i) {
......
......@@ -47,11 +47,9 @@ extensions::ExtensionResource GetExtensionIconResource(
const ExtensionIconSet& icons,
int size,
ExtensionIconSet::MatchType match_type) {
std::string path = icons.Get(size, match_type);
if (path.empty())
return extensions::ExtensionResource();
return extension->GetResource(path);
const std::string& path = icons.Get(size, match_type);
return path.empty() ? extensions::ExtensionResource()
: extension->GetResource(path);
}
class BlankImageSource : public gfx::CanvasImageSource {
......
......@@ -5,6 +5,7 @@
#include "extensions/common/extension_icon_set.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
ExtensionIconSet::ExtensionIconSet() {}
......@@ -19,12 +20,12 @@ void ExtensionIconSet::Add(int size, const std::string& path) {
map_[size] = path;
}
std::string ExtensionIconSet::Get(int size, MatchType match_type) const {
const 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(size);
return result == map_.end() ? std::string() : result->second;
return result == map_.end() ? base::EmptyString() : result->second;
} else if (match_type == MATCH_SMALLER) {
IconMap::const_reverse_iterator result = map_.rend();
for (IconMap::const_reverse_iterator iter = map_.rbegin();
......@@ -34,7 +35,7 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const {
break;
}
}
return result == map_.rend() ? std::string() : result->second;
return result == map_.rend() ? base::EmptyString() : result->second;
} else {
DCHECK(match_type == MATCH_BIGGER);
IconMap::const_iterator result = map_.end();
......@@ -45,7 +46,7 @@ std::string ExtensionIconSet::Get(int size, MatchType match_type) const {
break;
}
}
return result == map_.end() ? std::string() : result->second;
return result == map_.end() ? base::EmptyString() : result->second;
}
}
......
......@@ -37,7 +37,7 @@ class ExtensionIconSet {
// Gets path value of the icon found when searching for |size| using
// |mathc_type|.
std::string Get(int size, MatchType match_type) const;
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;
......
......@@ -37,7 +37,7 @@ ExtensionResource IconsInfo::GetIconResource(
const Extension* extension,
int size,
ExtensionIconSet::MatchType match_type) {
std::string path = GetIcons(extension).Get(size, match_type);
const std::string& path = GetIcons(extension).Get(size, match_type);
return path.empty() ? ExtensionResource() : extension->GetResource(path);
}
......@@ -45,7 +45,7 @@ ExtensionResource IconsInfo::GetIconResource(
GURL IconsInfo::GetIconURL(const Extension* extension,
int size,
ExtensionIconSet::MatchType match_type) {
std::string path = GetIcons(extension).Get(size, match_type);
const std::string& path = GetIcons(extension).Get(size, match_type);
return path.empty() ? GURL() : extension->GetResourceURL(path);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment