Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: ui/base/resource/resource_bundle_gtk.cc

Issue 10270023: Add new ResourceBundle::Delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/resource/resource_bundle.h" 5 #include "ui/base/resource/resource_bundle.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 FilePath GetResourcesPakFilePath(const std::string& pak_name) { 55 FilePath GetResourcesPakFilePath(const std::string& pak_name) {
56 FilePath path; 56 FilePath path;
57 if (PathService::Get(base::DIR_MODULE, &path)) 57 if (PathService::Get(base::DIR_MODULE, &path))
58 return path.AppendASCII(pak_name.c_str()); 58 return path.AppendASCII(pak_name.c_str());
59 return FilePath(); 59 return FilePath();
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 void ResourceBundle::LoadCommonResources() { 64 void ResourceBundle::LoadCommonResources() {
65 AddDataPack(GetResourcesPakFilePath("chrome.pak"), 65 AddDataPack("chrome",
66 GetResourcesPakFilePath("chrome.pak"),
66 ResourceHandle::kScaleFactor100x); 67 ResourceHandle::kScaleFactor100x);
67 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), 68 AddDataPack("theme_resources_standard",
69 GetResourcesPakFilePath("theme_resources_standard.pak"),
68 ResourceHandle::kScaleFactor100x); 70 ResourceHandle::kScaleFactor100x);
69 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), 71 AddDataPack("ui_resources_standard",
72 GetResourcesPakFilePath("ui_resources_standard.pak"),
70 ResourceHandle::kScaleFactor100x); 73 ResourceHandle::kScaleFactor100x);
71 } 74 }
72 75
73 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { 76 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
74 // Use the negative |resource_id| for the key for BIDI-aware images. 77 // Use the negative |resource_id| for the key for BIDI-aware images.
75 int key = rtl == RTL_ENABLED ? -resource_id : resource_id; 78 int key = rtl == RTL_ENABLED ? -resource_id : resource_id;
76 79
77 // Check to see if the image is already in the cache. 80 // Check to see if the image is already in the cache.
78 { 81 {
79 base::AutoLock lock_scope(*images_and_fonts_lock_); 82 base::AutoLock lock_scope(*images_and_fonts_lock_);
80 ImageMap::const_iterator found = images_.find(key); 83 ImageMap::const_iterator found = images_.find(key);
81 if (found != images_.end()) 84 if (found != images_.end())
82 return *found->second; 85 return *found->second;
83 } 86 }
84 87
85 scoped_refptr<base::RefCountedStaticMemory> data( 88 scoped_ptr<gfx::Image> image;
86 LoadDataResourceBytes(resource_id)); 89 if (delegate_)
87 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); 90 image.reset(delegate_->GetNativeImageNamed(resource_id, rtl).release());
88 91
89 // The load was successful, so cache the image. 92 if (!image.get()) {
90 if (pixbuf) { 93 scoped_refptr<base::RefCountedStaticMemory> data(
91 base::AutoLock lock_scope(*images_and_fonts_lock_); 94 LoadDataResourceBytes(resource_id));
95 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED);
92 96
93 // Another thread raced the load and has already cached the image. 97 if (!pixbuf) {
94 if (images_.count(key)) { 98 LOG(WARNING) << "Unable to load pixbuf with id " << resource_id;
95 g_object_unref(pixbuf); 99 NOTREACHED(); // Want to assert in debug mode.
96 return *images_[key]; 100 return *GetEmptyImage();
97 } 101 }
98 102
99 gfx::Image* image = new gfx::Image(pixbuf); // Takes ownership. 103 image.reset(new gfx::Image(pixbuf)); // Takes ownership.
100 images_[key] = image;
101 return *image;
102 } 104 }
103 105
104 LOG(WARNING) << "Unable to pixbuf with id " << resource_id; 106 base::AutoLock lock_scope(*images_and_fonts_lock_);
105 NOTREACHED(); // Want to assert in debug mode. 107
106 return *GetEmptyImage(); 108 // Another thread raced the load and has already cached the image.
109 if (images_.count(key))
110 return *images_[key];
111
112 images_[key] = image.release();
113 return *images_[key];
107 } 114 }
108 115
109 } // namespace ui 116 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698