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

Unified Diff: chrome/browser/ui/webui/theme_source.cc

Issue 874483007: Make sure ResourceBundle::GetImageSkiaNamed running on UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/theme_source.cc
diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc
index bccb665fcd82fd4af766ff15782444f16d35b59e..d7793ed6db83c6442f1ecc9a23abf95e76a2384b 100644
--- a/chrome/browser/ui/webui/theme_source.cc
+++ b/chrome/browser/ui/webui/theme_source.cc
@@ -40,6 +40,24 @@ std::string GetThemePath() {
static const char* kNewTabCSSPath = "css/new_tab_theme.css";
static const char* kNewIncognitoTabCSSPath = "css/incognito_new_tab_theme.css";
+void ProcessImageOnUIThread(const gfx::ImageSkia& image,
+ float scale_factor,
+ scoped_refptr<base::RefCountedBytes> data) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ const gfx::ImageSkiaRep& rep = image.GetRepresentation(scale_factor);
+ gfx::PNGCodec::EncodeBGRASkBitmap(
+ rep.sk_bitmap(), false /* discard transparency */, &data->data());
+}
+
+void ProcessResourceOnUIThread(int resource_id,
+ float scale_factor,
+ scoped_refptr<base::RefCountedBytes> data) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ ProcessImageOnUIThread(
+ *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id),
+ scale_factor, data);
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -179,24 +197,23 @@ void ThemeSource::SendThemeImage(
// rescale the bitmap if its backend doesn't contain the representation for
// the specified scale factor. This is the fallback path in case chrome is
// shipped without 2x resource pack but needs to use HighDPI display, which
- // can happen in ChromeOS.
- // TODO(mukai): remove this method itself when we ship 2x resource to all
- // ChromeOS devices.
- gfx::ImageSkia image;
+ // can happen in ChromeOS or Linux.
+ scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
if (BrowserThemePack::IsPersistentImageID(resource_id)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
DCHECK(tp);
- image = *tp->GetImageSkiaNamed(resource_id);
+ ProcessImageOnUIThread(*tp->GetImageSkiaNamed(resource_id), scale_factor,
+ data);
+ callback.Run(data.get());
} else {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- image = *rb.GetImageSkiaNamed(resource_id);
+ // Fetching image data in ResourceBundle should happen on the UI thread. See
+ // crbug.com/449277
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&ProcessResourceOnUIThread, resource_id, scale_factor, data),
+ base::Bind(callback, data));
}
-
- const gfx::ImageSkiaRep& rep = image.GetRepresentation(scale_factor);
- scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
- gfx::PNGCodec::EncodeBGRASkBitmap(
- rep.sk_bitmap(), false /* discard transparency */, &data->data());
- callback.Run(data.get());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698