Commit d2af5fd8 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Make const the Resource Bundle APIs

This CL is making const the function that are not modifying the
state of the resource bundle.

This step is required to make the transition to a Reader/Writer
lock.

Bug: 1123115
Change-Id: I764a8657fe358ce8cc5097d7ca7140a48682afd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401324Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805414}
parent 7db305e2
......@@ -68,12 +68,12 @@ base::RefCountedStaticMemory* CastResourceDelegate::LoadDataResourceBytes(
bool CastResourceDelegate::GetRawDataResource(int resource_id,
ui::ScaleFactor scale_factor,
base::StringPiece* value) {
base::StringPiece* value) const {
return false;
}
bool CastResourceDelegate::GetLocalizedString(int message_id,
base::string16* value) {
base::string16* value) const {
ExtraLocaledStringMap::const_iterator it =
extra_localized_strings_.find(message_id);
if (it != extra_localized_strings_.end()) {
......
......@@ -47,8 +47,8 @@ class CastResourceDelegate : public ui::ResourceBundle::Delegate {
ui::ScaleFactor scale_factor) override;
bool GetRawDataResource(int resource_id,
ui::ScaleFactor scale_factor,
base::StringPiece* value) override;
bool GetLocalizedString(int message_id, base::string16* value) override;
base::StringPiece* value) const override;
bool GetLocalizedString(int message_id, base::string16* value) const override;
// Adds/removes/clears extra localized strings.
void AddExtraLocalizedString(int resource_id,
......
......@@ -26,11 +26,12 @@ class MockResourceBundleDelegate : public ResourceBundle::Delegate {
MOCK_METHOD2(LoadDataResourceBytes,
base::RefCountedMemory*(int resource_id,
ScaleFactor scale_factor));
MOCK_METHOD3(GetRawDataResource,
bool(int resource_id,
ScaleFactor scale_factor,
base::StringPiece* value));
MOCK_METHOD2(GetLocalizedString, bool(int message_id, base::string16* value));
MOCK_CONST_METHOD3(GetRawDataResource,
bool(int resource_id,
ScaleFactor scale_factor,
base::StringPiece* value));
MOCK_CONST_METHOD2(GetLocalizedString,
bool(int message_id, base::string16* value));
};
} // namespace ui
......
......@@ -492,12 +492,12 @@ void ResourceBundle::OverrideLocaleStringResource(
overridden_locale_strings_[resource_id] = string;
}
const base::FilePath& ResourceBundle::GetOverriddenPakPath() {
const base::FilePath& ResourceBundle::GetOverriddenPakPath() const {
return overridden_pak_path_;
}
base::string16 ResourceBundle::MaybeMangleLocalizedString(
const base::string16& str) {
const base::string16& str) const {
if (!mangle_localized_strings_)
return str;
......@@ -720,7 +720,7 @@ base::string16 ResourceBundle::GetLocalizedString(int resource_id) {
}
base::RefCountedMemory* ResourceBundle::LoadLocalizedResourceBytes(
int resource_id) {
int resource_id) const {
{
base::AutoLock lock_scope(*locale_resources_data_lock_);
base::StringPiece data;
......@@ -1055,7 +1055,7 @@ gfx::Image& ResourceBundle::GetEmptyImage() {
return empty_image_;
}
base::string16 ResourceBundle::GetLocalizedStringImpl(int resource_id) {
base::string16 ResourceBundle::GetLocalizedStringImpl(int resource_id) const {
base::string16 string;
if (delegate_ && delegate_->GetLocalizedString(resource_id, &string))
return MaybeMangleLocalizedString(string);
......
......@@ -109,11 +109,12 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
// false to attempt retrieval of the default resource.
virtual bool GetRawDataResource(int resource_id,
ScaleFactor scale_factor,
base::StringPiece* value) = 0;
base::StringPiece* value) const = 0;
// Retrieve a localized string. Return true if a string was provided or
// false to attempt retrieval of the default string.
virtual bool GetLocalizedString(int message_id, base::string16* value) = 0;
virtual bool GetLocalizedString(int message_id,
base::string16* value) const = 0;
protected:
virtual ~Delegate() {}
......@@ -277,7 +278,7 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
// Get a localized resource (for example, localized image logo) given a
// resource id.
base::RefCountedMemory* LoadLocalizedResourceBytes(int resource_id);
base::RefCountedMemory* LoadLocalizedResourceBytes(int resource_id) const;
// Returns a font list derived from the platform-specific "Base" font list.
// The result is always cached and exists for the lifetime of the process.
......@@ -457,19 +458,19 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle {
// bright red bitmap.
gfx::Image& GetEmptyImage();
const base::FilePath& GetOverriddenPakPath();
const base::FilePath& GetOverriddenPakPath() const;
// If mangling of localized strings is enabled, mangles |str| to make it
// longer and to add begin and end markers so that any truncation of it is
// visible and returns the mangled string. If not, returns |str|.
base::string16 MaybeMangleLocalizedString(const base::string16& str);
base::string16 MaybeMangleLocalizedString(const base::string16& str) const;
// An internal implementation of |GetLocalizedString()| without setting the
// flag of whether overriding locale strings is supported to false. We don't
// update this flag only in |InitDefaultFontList()| which is called earlier
// than the overriding. This is okay, because the font list doesn't need to be
// overridden by variations.
base::string16 GetLocalizedStringImpl(int resource_id);
base::string16 GetLocalizedStringImpl(int resource_id) const;
// This pointer is guaranteed to outlive the ResourceBundle instance and may
// be null.
......
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