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

Unified Diff: ui/base/resource/resource_bundle.cc

Issue 2699323002: Restrict cross-thread access to gfx::Image and gfx::Font in ResourceBundle (Closed)
Patch Set: rebase Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle.cc
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index b5a9a4f81e42c511581aaf5c3ce95a63c8ec4cf1..66ca7eadde86f5e22551c09b38adbeb271015c9a 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -407,12 +407,11 @@ gfx::ImageSkia* ResourceBundle::GetImageSkiaNamed(int resource_id) {
}
gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
+ DCHECK(sequence_checker_.CalledOnValidSequence());
+
// Check to see if the image is already in the cache.
- {
- base::AutoLock lock_scope(*images_and_fonts_lock_);
- if (images_.count(resource_id))
- return images_[resource_id];
- }
+ if (images_.count(resource_id))
+ return images_[resource_id];
gfx::Image image;
if (delegate_)
@@ -450,12 +449,6 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
}
// The load was successful, so cache the image.
- base::AutoLock lock_scope(*images_and_fonts_lock_);
-
- // Another thread raced the load and has already cached the image.
- if (images_.count(resource_id))
- return images_[resource_id];
-
images_[resource_id] = image;
return images_[resource_id];
}
@@ -586,7 +579,7 @@ const gfx::FontList& ResourceBundle::GetFontListWithDelta(
int size_delta,
gfx::Font::FontStyle style,
gfx::Font::Weight weight) {
- base::AutoLock lock_scope(*images_and_fonts_lock_);
+ DCHECK(sequence_checker_.CalledOnValidSequence());
const FontKey styled_key(size_delta, style, weight);
@@ -655,7 +648,7 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
}
void ResourceBundle::ReloadFonts() {
- base::AutoLock lock_scope(*images_and_fonts_lock_);
+ DCHECK(sequence_checker_.CalledOnValidSequence());
InitDefaultFontList();
font_cache_.clear();
}
@@ -678,7 +671,6 @@ bool ResourceBundle::IsScaleFactorSupported(ScaleFactor scale_factor) {
ResourceBundle::ResourceBundle(Delegate* delegate)
: delegate_(delegate),
- images_and_fonts_lock_(new base::Lock),
locale_resources_data_lock_(new base::Lock),
max_scale_factor_(SCALE_FACTOR_100P) {
}
@@ -862,7 +854,7 @@ bool ResourceBundle::LoadBitmap(int resource_id,
}
gfx::Image& ResourceBundle::GetEmptyImage() {
- base::AutoLock lock(*images_and_fonts_lock_);
+ DCHECK(sequence_checker_.CalledOnValidSequence());
if (empty_image_.IsEmpty()) {
// The placeholder bitmap is bright red so people notice the problem.

Powered by Google App Engine
This is Rietveld 408576698