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

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/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 int key = rtl == RTL_ENABLED ? -resource_id : resource_id; 56 int key = rtl == RTL_ENABLED ? -resource_id : resource_id;
57 57
58 // Check to see if the image is already in the cache. 58 // Check to see if the image is already in the cache.
59 { 59 {
60 base::AutoLock lock_scope(*images_and_fonts_lock_); 60 base::AutoLock lock_scope(*images_and_fonts_lock_);
61 ImageMap::const_iterator found = images_.find(key); 61 ImageMap::const_iterator found = images_.find(key);
62 if (found != images_.end()) 62 if (found != images_.end())
63 return *found->second; 63 return *found->second;
64 } 64 }
65 65
66 scoped_refptr<base::RefCountedStaticMemory> data( 66 gfx::Image* image = NULL;
67 LoadDataResourceBytes(resource_id)); 67 if (delegate_)
68 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED); 68 image = delegate_->GetNativeImageNamed(resource_id, rtl);
69 69
70 // The load was successful, so cache the image. 70 if (!image) {
71 if (pixbuf) { 71 scoped_refptr<base::RefCountedStaticMemory> data(
72 base::AutoLock lock_scope(*images_and_fonts_lock_); 72 LoadDataResourceBytes(resource_id));
73 GdkPixbuf* pixbuf = LoadPixbuf(data.get(), rtl == RTL_ENABLED);
73 74
74 // Another thread raced the load and has already cached the image. 75 if (!pixbuf) {
75 if (images_.count(key)) { 76 LOG(WARNING) << "Unable to load pixbuf with id " << resource_id;
76 g_object_unref(pixbuf); 77 NOTREACHED(); // Want to assert in debug mode.
77 return *images_[key]; 78 return *GetEmptyImage();
78 } 79 }
79 80
80 gfx::Image* image = new gfx::Image(pixbuf); // Takes ownership. 81 image = new gfx::Image(pixbuf); // Takes ownership.
81 images_[key] = image;
82 return *image;
83 } 82 }
84 83
85 LOG(WARNING) << "Unable to pixbuf with id " << resource_id; 84 base::AutoLock lock_scope(*images_and_fonts_lock_);
86 NOTREACHED(); // Want to assert in debug mode. 85
87 return *GetEmptyImage(); 86 // Another thread raced the load and has already cached the image.
87 if (images_.count(key)) {
88 delete image;
sail 2012/04/30 21:14:43 instead of doing a delete here, can you use a scop
Marshall 2012/04/30 21:50:10 Done.
89 return *images_[key];
90 }
91
92 images_[key] = image;
93 return *image;
88 } 94 }
89 95
90 } // namespace ui 96 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698