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

Side by Side Diff: chrome/browser/ui/webui/theme_source.cc

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix that unittest Created 5 years 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
« no previous file with comments | « chrome/browser/ui/webui/theme_handler.cc ('k') | chrome/chrome_tests.gypi » ('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 "chrome/browser/ui/webui/theme_source.h" 5 #include "chrome/browser/ui/webui/theme_source.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // ThemeSource, private: 199 // ThemeSource, private:
200 200
201 void ThemeSource::SendThemeBitmap( 201 void ThemeSource::SendThemeBitmap(
202 const content::URLDataSource::GotDataCallback& callback, 202 const content::URLDataSource::GotDataCallback& callback,
203 int resource_id, 203 int resource_id,
204 float scale_factor) { 204 float scale_factor) {
205 ui::ScaleFactor resource_scale_factor = 205 ui::ScaleFactor resource_scale_factor =
206 ui::GetSupportedScaleFactor(scale_factor); 206 ui::GetSupportedScaleFactor(scale_factor);
207 if (BrowserThemePack::IsPersistentImageID(resource_id)) { 207 if (BrowserThemePack::IsPersistentImageID(resource_id)) {
208 DCHECK_CURRENTLY_ON(BrowserThread::UI); 208 DCHECK_CURRENTLY_ON(BrowserThread::UI);
209 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 209 const ui::ThemeProvider& tp =
210 DCHECK(tp); 210 ThemeService::GetThemeProviderForProfile(profile_);
211 211
212 scoped_refptr<base::RefCountedMemory> image_data( 212 scoped_refptr<base::RefCountedMemory> image_data(
213 tp->GetRawData(resource_id, resource_scale_factor)); 213 tp.GetRawData(resource_id, resource_scale_factor));
214 callback.Run(image_data.get()); 214 callback.Run(image_data.get());
215 } else { 215 } else {
216 DCHECK_CURRENTLY_ON(BrowserThread::IO); 216 DCHECK_CURRENTLY_ON(BrowserThread::IO);
217 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 217 const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
218 callback.Run( 218 callback.Run(
219 rb.LoadDataResourceBytesForScale(resource_id, resource_scale_factor)); 219 rb.LoadDataResourceBytesForScale(resource_id, resource_scale_factor));
220 } 220 }
221 } 221 }
222 222
223 void ThemeSource::SendThemeImage( 223 void ThemeSource::SendThemeImage(
224 const content::URLDataSource::GotDataCallback& callback, 224 const content::URLDataSource::GotDataCallback& callback,
225 int resource_id, 225 int resource_id,
226 float scale_factor) { 226 float scale_factor) {
227 // If the resource bundle contains the data pack for |scale_factor|, we can 227 // If the resource bundle contains the data pack for |scale_factor|, we can
228 // safely fallback to SendThemeBitmap(). 228 // safely fallback to SendThemeBitmap().
229 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 229 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
230 if (ui::GetScaleForScaleFactor(rb.GetMaxScaleFactor()) >= scale_factor) { 230 if (ui::GetScaleForScaleFactor(rb.GetMaxScaleFactor()) >= scale_factor) {
231 SendThemeBitmap(callback, resource_id, scale_factor); 231 SendThemeBitmap(callback, resource_id, scale_factor);
232 return; 232 return;
233 } 233 }
234 234
235 // Otherwise, we should use gfx::ImageSkia to obtain the data. ImageSkia can 235 // Otherwise, we should use gfx::ImageSkia to obtain the data. ImageSkia can
236 // rescale the bitmap if its backend doesn't contain the representation for 236 // rescale the bitmap if its backend doesn't contain the representation for
237 // the specified scale factor. This is the fallback path in case chrome is 237 // the specified scale factor. This is the fallback path in case chrome is
238 // shipped without 2x resource pack but needs to use HighDPI display, which 238 // shipped without 2x resource pack but needs to use HighDPI display, which
239 // can happen in ChromeOS or Linux. 239 // can happen in ChromeOS or Linux.
240 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); 240 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
241 if (BrowserThemePack::IsPersistentImageID(resource_id)) { 241 if (BrowserThemePack::IsPersistentImageID(resource_id)) {
242 DCHECK_CURRENTLY_ON(BrowserThread::UI); 242 DCHECK_CURRENTLY_ON(BrowserThread::UI);
243 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 243 const ui::ThemeProvider& tp =
244 DCHECK(tp); 244 ThemeService::GetThemeProviderForProfile(profile_);
245 245 ProcessImageOnUIThread(*tp.GetImageSkiaNamed(resource_id), scale_factor,
246 ProcessImageOnUIThread(*tp->GetImageSkiaNamed(resource_id), scale_factor,
247 data); 246 data);
248 callback.Run(data.get()); 247 callback.Run(data.get());
249 } else { 248 } else {
250 DCHECK_CURRENTLY_ON(BrowserThread::IO); 249 DCHECK_CURRENTLY_ON(BrowserThread::IO);
251 // Fetching image data in ResourceBundle should happen on the UI thread. See 250 // Fetching image data in ResourceBundle should happen on the UI thread. See
252 // crbug.com/449277 251 // crbug.com/449277
253 content::BrowserThread::PostTaskAndReply( 252 content::BrowserThread::PostTaskAndReply(
254 content::BrowserThread::UI, FROM_HERE, 253 content::BrowserThread::UI, FROM_HERE,
255 base::Bind(&ProcessResourceOnUIThread, resource_id, scale_factor, data), 254 base::Bind(&ProcessResourceOnUIThread, resource_id, scale_factor, data),
256 base::Bind(callback, data)); 255 base::Bind(callback, data));
257 } 256 }
258 } 257 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/theme_handler.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698