summaryrefslogtreecommitdiffstats
path: root/app/resource_bundle.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 21:11:45 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 21:11:45 +0000
commitc0336d30f5a822ebc55a49f019e00a2104aced18 (patch)
tree16bd873562d7de18bdd6c17333cc2d9e12b8f69c /app/resource_bundle.cc
parentf36d009a08cb5eaddde1e3c891b793b1c5b3495e (diff)
downloadchromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.zip
chromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.tar.gz
chromium_src-c0336d30f5a822ebc55a49f019e00a2104aced18.tar.bz2
Cleanup: Put #ifdefed typedef below non-#ifdefed declarations. Reorder definitions to match declarations. Use STL util function. Eliminate pointless comment.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6224005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/resource_bundle.cc')
-rw-r--r--app/resource_bundle.cc135
1 files changed, 68 insertions, 67 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index 93669bc..79d6cd8 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -7,6 +7,7 @@
#include "app/data_pack.h"
#include "base/lock.h"
#include "base/logging.h"
+#include "base/stl_util-inl.h"
#include "base/string_piece.h"
#include "build/build_config.h"
#include "gfx/codec/png_codec.h"
@@ -90,51 +91,6 @@ ResourceBundle& ResourceBundle::GetSharedInstance() {
return *g_shared_instance_;
}
-ResourceBundle::ResourceBundle()
- : lock_(new Lock),
- resources_data_(NULL),
- locale_resources_data_(NULL) {
-}
-
-void ResourceBundle::FreeImages() {
- for (SkImageMap::iterator i = skia_images_.begin();
- i != skia_images_.end(); i++) {
- delete i->second;
- }
- skia_images_.clear();
-}
-
-/* static */
-SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) {
- scoped_refptr<RefCountedMemory> memory(
- LoadResourceBytes(data_handle, resource_id));
- if (!memory)
- return NULL;
-
- SkBitmap bitmap;
- if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) {
- NOTREACHED() << "Unable to decode theme image resource " << resource_id;
- return NULL;
- }
-
- return new SkBitmap(bitmap);
-}
-
-RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
- int resource_id) const {
- RefCountedStaticMemory* bytes =
- LoadResourceBytes(resources_data_, resource_id);
-
- // Check all our additional data packs for the resources if it wasn't loaded
- // from our main source.
- for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin();
- !bytes && it != data_packs_.end(); ++it) {
- bytes = (*it)->GetStaticMemory(resource_id);
- }
-
- return bytes;
-}
-
SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {
// Check to see if we already have the Skia image in the cache.
{
@@ -180,29 +136,19 @@ SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {
}
}
-void ResourceBundle::LoadFontsIfNecessary() {
- AutoLock lock_scope(*lock_);
- if (!base_font_.get()) {
- base_font_.reset(new gfx::Font());
-
- bold_font_.reset(new gfx::Font());
- *bold_font_ =
- base_font_->DeriveFont(0, base_font_->GetStyle() | gfx::Font::BOLD);
-
- small_font_.reset(new gfx::Font());
- *small_font_ = base_font_->DeriveFont(kSmallFontSizeDelta);
-
- medium_font_.reset(new gfx::Font());
- *medium_font_ = base_font_->DeriveFont(kMediumFontSizeDelta);
-
- medium_bold_font_.reset(new gfx::Font());
- *medium_bold_font_ =
- base_font_->DeriveFont(kMediumFontSizeDelta,
- base_font_->GetStyle() | gfx::Font::BOLD);
+RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
+ int resource_id) const {
+ RefCountedStaticMemory* bytes =
+ LoadResourceBytes(resources_data_, resource_id);
- large_font_.reset(new gfx::Font());
- *large_font_ = base_font_->DeriveFont(kLargeFontSizeDelta);
+ // Check all our additional data packs for the resources if it wasn't loaded
+ // from our main source.
+ for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin();
+ !bytes && it != data_packs_.end(); ++it) {
+ bytes = (*it)->GetStaticMemory(resource_id);
}
+
+ return bytes;
}
const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
@@ -234,7 +180,62 @@ gfx::NativeImage ResourceBundle::GetNativeImageNamed(int resource_id) {
#endif
}
-// LoadedDataPack implementation
+ResourceBundle::ResourceBundle()
+ : lock_(new Lock),
+ resources_data_(NULL),
+ locale_resources_data_(NULL) {
+}
+
+void ResourceBundle::FreeImages() {
+ STLDeleteContainerPairSecondPointers(skia_images_.begin(),
+ skia_images_.end());
+ skia_images_.clear();
+}
+
+void ResourceBundle::LoadFontsIfNecessary() {
+ AutoLock lock_scope(*lock_);
+ if (!base_font_.get()) {
+ base_font_.reset(new gfx::Font());
+
+ bold_font_.reset(new gfx::Font());
+ *bold_font_ =
+ base_font_->DeriveFont(0, base_font_->GetStyle() | gfx::Font::BOLD);
+
+ small_font_.reset(new gfx::Font());
+ *small_font_ = base_font_->DeriveFont(kSmallFontSizeDelta);
+
+ medium_font_.reset(new gfx::Font());
+ *medium_font_ = base_font_->DeriveFont(kMediumFontSizeDelta);
+
+ medium_bold_font_.reset(new gfx::Font());
+ *medium_bold_font_ =
+ base_font_->DeriveFont(kMediumFontSizeDelta,
+ base_font_->GetStyle() | gfx::Font::BOLD);
+
+ large_font_.reset(new gfx::Font());
+ *large_font_ = base_font_->DeriveFont(kLargeFontSizeDelta);
+ }
+}
+
+/* static */
+SkBitmap* ResourceBundle::LoadBitmap(DataHandle data_handle, int resource_id) {
+ scoped_refptr<RefCountedMemory> memory(
+ LoadResourceBytes(data_handle, resource_id));
+ if (!memory)
+ return NULL;
+
+ SkBitmap bitmap;
+ if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) {
+ NOTREACHED() << "Unable to decode theme image resource " << resource_id;
+ return NULL;
+ }
+
+ return new SkBitmap(bitmap);
+}
+
+
+// LoadedDataPack -------------------------------------------------------------
+
ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path)
: path_(path) {
// Always preload the data packs so we can maintain constness.