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

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
« no previous file with comments | « ui/base/resource/resource_bundle_aurax11.cc ('k') | ui/base/resource/resource_bundle_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // exists. 49 // exists.
50 g_object_ref(pixbuf); 50 g_object_ref(pixbuf);
51 return pixbuf; 51 return pixbuf;
52 } 52 }
53 } 53 }
54 54
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
60 // Return just the name of the pack file.
61 return FilePath(pak_name.c_str());
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 void ResourceBundle::LoadCommonResources() { 66 void ResourceBundle::LoadCommonResources() {
65 AddDataPack(GetResourcesPakFilePath("chrome.pak"), 67 AddDataPack(GetResourcesPakFilePath("chrome.pak"),
66 ResourceHandle::kScaleFactor100x); 68 ResourceHandle::kScaleFactor100x);
67 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"), 69 AddDataPack(GetResourcesPakFilePath("theme_resources_standard.pak"),
68 ResourceHandle::kScaleFactor100x); 70 ResourceHandle::kScaleFactor100x);
69 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"), 71 AddDataPack(GetResourcesPakFilePath("ui_resources_standard.pak"),
70 ResourceHandle::kScaleFactor100x); 72 ResourceHandle::kScaleFactor100x);
71 } 73 }
72 74
73 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { 75 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
74 // Use the negative |resource_id| for the key for BIDI-aware images. 76 // Use the negative |resource_id| for the key for BIDI-aware images.
75 int key = rtl == RTL_ENABLED ? -resource_id : resource_id; 77 int key = rtl == RTL_ENABLED ? -resource_id : resource_id;
76 78
77 // Check to see if the image is already in the cache. 79 // Check to see if the image is already in the cache.
78 { 80 {
79 base::AutoLock lock_scope(*images_and_fonts_lock_); 81 base::AutoLock lock_scope(*images_and_fonts_lock_);
80 ImageMap::const_iterator found = images_.find(key); 82 if (images_.count(key))
81 if (found != images_.end()) 83 return images_[key];
82 return *found->second;
83 } 84 }
84 85
85 scoped_refptr<base::RefCountedStaticMemory> data( 86 gfx::Image image;
86 LoadDataResourceBytes(resource_id)); 87 if (delegate_)
87 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); 88 image = delegate_->GetNativeImageNamed(resource_id, rtl);
88 89
89 // The load was successful, so cache the image. 90 if (image.IsEmpty()) {
90 if (pixbuf) { 91 scoped_refptr<base::RefCountedStaticMemory> data(
91 base::AutoLock lock_scope(*images_and_fonts_lock_); 92 LoadDataResourceBytes(resource_id));
93 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED);
92 94
93 // Another thread raced the load and has already cached the image. 95 if (!pixbuf) {
94 if (images_.count(key)) { 96 LOG(WARNING) << "Unable to load pixbuf with id " << resource_id;
95 g_object_unref(pixbuf); 97 NOTREACHED(); // Want to assert in debug mode.
96 return *images_[key]; 98 return GetEmptyImage();
97 } 99 }
98 100
99 gfx::Image* image = new gfx::Image(pixbuf); // Takes ownership. 101 image = gfx::Image(pixbuf); // Takes ownership.
100 images_[key] = image;
101 return *image;
102 } 102 }
103 103
104 LOG(WARNING) << "Unable to pixbuf with id " << resource_id; 104 base::AutoLock lock_scope(*images_and_fonts_lock_);
105 NOTREACHED(); // Want to assert in debug mode. 105
106 return *GetEmptyImage(); 106 // Another thread raced the load and has already cached the image.
107 if (images_.count(key))
108 return images_[key];
109
110 images_[key] = image;
111 return images_[key];
107 } 112 }
108 113
109 } // namespace ui 114 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_aurax11.cc ('k') | ui/base/resource/resource_bundle_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698