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

Side by Side Diff: chrome/browser/themes/theme_service.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: respond to comments 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
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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/themes/browser_theme_pack.h" 21 #include "chrome/browser/themes/browser_theme_pack.h"
22 #include "chrome/browser/themes/custom_theme_supplier.h" 22 #include "chrome/browser/themes/custom_theme_supplier.h"
23 #include "chrome/browser/themes/theme_properties.h" 23 #include "chrome/browser/themes/theme_properties.h"
24 #include "chrome/browser/themes/theme_service_factory.h"
24 #include "chrome/browser/themes/theme_syncable_service.h" 25 #include "chrome/browser/themes/theme_syncable_service.h"
25 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/user_metrics.h" 29 #include "content/public/browser/user_metrics.h"
29 #include "extensions/browser/extension_prefs.h" 30 #include "extensions/browser/extension_prefs.h"
30 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
32 #include "extensions/browser/uninstall_reason.h" 33 #include "extensions/browser/uninstall_reason.h"
33 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ThemeService* theme_service_; 159 ThemeService* theme_service_;
159 }; 160 };
160 #endif // defined(ENABLE_EXTENSIONS) 161 #endif // defined(ENABLE_EXTENSIONS)
161 162
162 ThemeService::ThemeService() 163 ThemeService::ThemeService()
163 : ready_(false), 164 : ready_(false),
164 rb_(ResourceBundle::GetSharedInstance()), 165 rb_(ResourceBundle::GetSharedInstance()),
165 profile_(nullptr), 166 profile_(nullptr),
166 installed_pending_load_id_(kDefaultThemeID), 167 installed_pending_load_id_(kDefaultThemeID),
167 number_of_infobars_(0), 168 number_of_infobars_(0),
168 weak_ptr_factory_(this) { 169 original_theme_provider_(*this, false),
169 } 170 otr_theme_provider_(*this, true),
171 weak_ptr_factory_(this) {}
170 172
171 ThemeService::~ThemeService() { 173 ThemeService::~ThemeService() {
172 FreePlatformCaches(); 174 FreePlatformCaches();
173 } 175 }
174 176
175 void ThemeService::Init(Profile* profile) { 177 void ThemeService::Init(Profile* profile) {
176 DCHECK(CalledOnValidThread()); 178 DCHECK(CalledOnValidThread());
177 profile_ = profile; 179 profile_ = profile;
178 180
179 LoadThemePrefs(); 181 LoadThemePrefs();
180 182
181 registrar_.Add(this, 183 registrar_.Add(this,
182 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, 184 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
183 content::Source<Profile>(profile_)); 185 content::Source<Profile>(profile_));
184 186
185 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); 187 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this));
186 } 188 }
187 189
188 gfx::Image ThemeService::GetImageNamed(int id) const {
189 DCHECK(CalledOnValidThread());
190
191 gfx::Image image;
192 if (theme_supplier_.get())
193 image = theme_supplier_->GetImageNamed(id);
194
195 if (image.IsEmpty())
196 image = rb_.GetNativeImageNamed(id);
197
198 return image;
199 }
200
201 bool ThemeService::IsSystemThemeDistinctFromDefaultTheme() const { 190 bool ThemeService::IsSystemThemeDistinctFromDefaultTheme() const {
202 return false; 191 return false;
203 } 192 }
204 193
205 bool ThemeService::UsingSystemTheme() const {
206 return UsingDefaultTheme();
207 }
208
209 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const {
210 gfx::Image image = GetImageNamed(id);
211 if (image.IsEmpty())
212 return nullptr;
213 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
214 // its images const. GetImageSkiaNamed() also should but has many callsites.
215 return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
216 }
217
218 SkColor ThemeService::GetColor(int id) const {
219 DCHECK(CalledOnValidThread());
220 SkColor color;
221 if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color))
222 return color;
223
224 // For backward compat with older themes, some newer colors are generated from
225 // older ones if they are missing.
226 switch (id) {
227 case Properties::COLOR_TOOLBAR_BUTTON_ICON:
228 return color_utils::HSLShift(gfx::kChromeIconGrey,
229 GetTint(Properties::TINT_BUTTONS));
230 case Properties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
231 // The active color is overridden in Gtk2UI.
232 return SkColorSetA(GetColor(Properties::COLOR_TOOLBAR_BUTTON_ICON), 0x33);
233 case Properties::COLOR_NTP_SECTION_HEADER_TEXT:
234 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30);
235 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER:
236 return GetColor(Properties::COLOR_NTP_TEXT);
237 case Properties::COLOR_NTP_SECTION_HEADER_RULE:
238 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70);
239 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT:
240 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86);
241 case Properties::COLOR_NTP_TEXT_LIGHT:
242 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40);
243 case Properties::COLOR_TAB_THROBBER_SPINNING:
244 case Properties::COLOR_TAB_THROBBER_WAITING: {
245 SkColor base_color =
246 ui::GetAuraColor(id == Properties::COLOR_TAB_THROBBER_SPINNING
247 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
248 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
249 nullptr);
250 color_utils::HSL hsl = GetTint(Properties::TINT_BUTTONS);
251 return color_utils::HSLShift(base_color, hsl);
252 }
253 #if defined(ENABLE_SUPERVISED_USERS)
254 case Properties::COLOR_SUPERVISED_USER_LABEL:
255 return color_utils::GetReadableColor(
256 SK_ColorWHITE,
257 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND));
258 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
259 return color_utils::BlendTowardOppositeLuminance(
260 GetColor(Properties::COLOR_FRAME), 0x80);
261 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER:
262 return color_utils::AlphaBlend(
263 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND),
264 SK_ColorBLACK,
265 230);
266 #endif
267 case Properties::COLOR_STATUS_BAR_TEXT: {
268 // A long time ago, we blended the toolbar and the tab text together to
269 // get the status bar text because, at the time, our text rendering in
270 // views couldn't do alpha blending. Even though this is no longer the
271 // case, this blending decision is built into the majority of themes that
272 // exist, and we must keep doing it.
273 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR);
274 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT);
275 return SkColorSetARGB(
276 SkColorGetA(text_color),
277 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2,
278 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2,
279 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2);
280 }
281 }
282
283 return Properties::GetDefaultColor(id);
284 }
285
286 int ThemeService::GetDisplayProperty(int id) const {
287 int result = 0;
288 if (theme_supplier_.get() &&
289 theme_supplier_->GetDisplayProperty(id, &result)) {
290 return result;
291 }
292
293 switch (id) {
294 case Properties::NTP_BACKGROUND_ALIGNMENT:
295 return Properties::ALIGN_CENTER;
296
297 case Properties::NTP_BACKGROUND_TILING:
298 return Properties::NO_REPEAT;
299
300 case Properties::NTP_LOGO_ALTERNATE:
301 return UsingDefaultTheme() || UsingSystemTheme() ||
302 (!HasCustomImage(IDR_THEME_NTP_BACKGROUND) &&
303 IsColorGrayscale(GetColor(Properties::COLOR_NTP_BACKGROUND))) ?
304 0 : 1;
305
306 default:
307 return -1;
308 }
309 }
310
311 bool ThemeService::ShouldUseNativeFrame() const {
312 if (HasCustomImage(IDR_THEME_FRAME))
313 return false;
314 #if defined(OS_WIN)
315 return ui::win::IsAeroGlassEnabled();
316 #else
317 return false;
318 #endif
319 }
320
321 bool ThemeService::HasCustomImage(int id) const {
322 return BrowserThemePack::IsPersistentImageID(id) &&
323 theme_supplier_ && theme_supplier_->HasCustomImage(id);
324 }
325
326 base::RefCountedMemory* ThemeService::GetRawData(
327 int id,
328 ui::ScaleFactor scale_factor) const {
329 // Check to see whether we should substitute some images.
330 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE);
331 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0)
332 id = IDR_PRODUCT_LOGO_WHITE;
333
334 base::RefCountedMemory* data = nullptr;
335 if (theme_supplier_.get())
336 data = theme_supplier_->GetRawData(id, scale_factor);
337 if (!data)
338 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P);
339
340 return data;
341 }
342
343 void ThemeService::Shutdown() { 194 void ThemeService::Shutdown() {
344 #if defined(ENABLE_EXTENSIONS) 195 #if defined(ENABLE_EXTENSIONS)
345 theme_observer_.reset(); 196 theme_observer_.reset();
346 #endif 197 #endif
347 } 198 }
348 199
349 void ThemeService::Observe(int type, 200 void ThemeService::Observe(int type,
350 const content::NotificationSource& source, 201 const content::NotificationSource& source,
351 const content::NotificationDetails& details) { 202 const content::NotificationDetails& details) {
352 using content::Details; 203 using content::Details;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 336 }
486 337
487 std::string ThemeService::GetThemeID() const { 338 std::string ThemeService::GetThemeID() const {
488 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); 339 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
489 } 340 }
490 341
491 color_utils::HSL ThemeService::GetTint(int id) const { 342 color_utils::HSL ThemeService::GetTint(int id) const {
492 DCHECK(CalledOnValidThread()); 343 DCHECK(CalledOnValidThread());
493 344
494 color_utils::HSL hsl; 345 color_utils::HSL hsl;
495 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) 346 if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl))
496 return hsl; 347 return hsl;
497 348
498 return ThemeProperties::GetDefaultTint(id); 349 return ThemeProperties::GetDefaultTint(id);
499 } 350 }
500 351
501 void ThemeService::ClearAllThemeData() { 352 void ThemeService::ClearAllThemeData() {
502 if (!ready_) 353 if (!ready_)
503 return; 354 return;
504 355
505 SwapThemeSupplier(nullptr); 356 SwapThemeSupplier(nullptr);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 bool loaded_pack = false; 394 bool loaded_pack = false;
544 395
545 // If we don't have a file pack, we're updating from an old version, or the 396 // If we don't have a file pack, we're updating from an old version, or the
546 // pack was created for an alternative MaterialDesignController::Mode. 397 // pack was created for an alternative MaterialDesignController::Mode.
547 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); 398 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
548 if (path != base::FilePath()) { 399 if (path != base::FilePath()) {
549 path = path.Append(ui::MaterialDesignController::IsModeMaterial() 400 path = path.Append(ui::MaterialDesignController::IsModeMaterial()
550 ? chrome::kThemePackMaterialDesignFilename 401 ? chrome::kThemePackMaterialDesignFilename
551 : chrome::kThemePackFilename); 402 : chrome::kThemePackFilename);
552 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); 403 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id));
553 loaded_pack = theme_supplier_.get() != nullptr; 404 loaded_pack = theme_supplier_ != nullptr;
554 } 405 }
555 406
556 if (loaded_pack) { 407 if (loaded_pack) {
557 content::RecordAction(UserMetricsAction("Themes.Loaded")); 408 content::RecordAction(UserMetricsAction("Themes.Loaded"));
558 set_ready(); 409 set_ready();
559 } 410 }
560 // Else: wait for the extension service to be ready so that the theme pack 411 // Else: wait for the extension service to be ready so that the theme pack
561 // can be recreated from the extension. 412 // can be recreated from the extension.
562 } 413 }
563 414
(...skipping 17 matching lines...) Expand all
581 theme_syncable_service_->OnThemeChange(); 432 theme_syncable_service_->OnThemeChange();
582 } 433 }
583 } 434 }
584 435
585 #if defined(USE_AURA) 436 #if defined(USE_AURA)
586 void ThemeService::FreePlatformCaches() { 437 void ThemeService::FreePlatformCaches() {
587 // Views (Skia) has no platform image cache to clear. 438 // Views (Skia) has no platform image cache to clear.
588 } 439 }
589 #endif 440 #endif
590 441
442 bool ThemeService::UsingSystemTheme() const {
443 return UsingDefaultTheme();
444 }
445
446 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const {
447 gfx::Image image = GetImageNamed(id);
448 if (image.IsEmpty())
449 return nullptr;
450 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
451 // its images const. GetImageSkiaNamed() also should but has many callsites.
452 return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
453 }
454
455 SkColor ThemeService::GetColor(int original_id, bool otr) const {
456 DCHECK(CalledOnValidThread());
457 // Custom themes always use the original (non-incognito) color.
458 SkColor color;
459 if (theme_supplier_ && theme_supplier_->GetColor(id, &color))
460 return color;
461
462 int id = otr ? ThemeProperties::PropertyToIncognitoProperty(original_id)
463 : original_id;
464
465 // For backward compat with older themes, some newer colors are generated from
466 // older ones if they are missing.
467 switch (id) {
468 case Properties::COLOR_TOOLBAR_BUTTON_ICON:
469 return color_utils::HSLShift(gfx::kChromeIconGrey,
470 GetTint(Properties::TINT_BUTTONS));
471 case Properties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
472 // The active color is overridden in Gtk2UI.
473 return SkColorSetA(GetColor(Properties::COLOR_TOOLBAR_BUTTON_ICON, otr),
474 0x33);
475 case Properties::COLOR_NTP_SECTION_HEADER_TEXT:
476 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.30);
477 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER:
478 return GetColor(Properties::COLOR_NTP_TEXT, otr);
479 case Properties::COLOR_NTP_SECTION_HEADER_RULE:
480 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.70);
481 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT:
482 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.86);
483 case Properties::COLOR_NTP_TEXT_LIGHT:
484 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.40);
485 case Properties::COLOR_TAB_THROBBER_SPINNING:
486 case Properties::COLOR_TAB_THROBBER_WAITING: {
487 SkColor base_color =
488 ui::GetAuraColor(id == Properties::COLOR_TAB_THROBBER_SPINNING
489 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
490 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
491 nullptr);
492 color_utils::HSL hsl = GetTint(Properties::TINT_BUTTONS);
493 return color_utils::HSLShift(base_color, hsl);
494 }
495 #if defined(ENABLE_SUPERVISED_USERS)
496 case Properties::COLOR_SUPERVISED_USER_LABEL:
497 return color_utils::GetReadableColor(
498 SK_ColorWHITE,
499 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND, otr));
500 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
501 return color_utils::BlendTowardOppositeLuminance(
502 GetColor(Properties::COLOR_FRAME, otr), 0x80);
503 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER:
504 return color_utils::AlphaBlend(
505 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND, otr),
506 SK_ColorBLACK, 230);
507 #endif
508 case Properties::COLOR_STATUS_BAR_TEXT: {
509 // A long time ago, we blended the toolbar and the tab text together to
510 // get the status bar text because, at the time, our text rendering in
511 // views couldn't do alpha blending. Even though this is no longer the
512 // case, this blending decision is built into the majority of themes that
513 // exist, and we must keep doing it.
514 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR, otr);
515 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT, otr);
516 return SkColorSetARGB(
517 SkColorGetA(text_color),
518 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2,
519 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2,
520 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2);
521 }
522 }
523
524 return Properties::GetDefaultColor(id);
525 }
526
527 int ThemeService::GetDisplayProperty(int id) const {
528 int result = 0;
529 if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) {
530 return result;
531 }
532
533 switch (id) {
534 case Properties::NTP_BACKGROUND_ALIGNMENT:
535 return Properties::ALIGN_CENTER;
536
537 case Properties::NTP_BACKGROUND_TILING:
538 return Properties::NO_REPEAT;
539
540 case Properties::NTP_LOGO_ALTERNATE:
541 return UsingDefaultTheme() || UsingSystemTheme() ||
542 (!HasCustomImage(IDR_THEME_NTP_BACKGROUND) &&
543 IsColorGrayscale(
544 GetColor(Properties::COLOR_NTP_BACKGROUND, false)))
545 ? 0
546 : 1;
547
548 default:
549 return -1;
550 }
551 }
552
553 bool ThemeService::ShouldUseNativeFrame() const {
554 if (HasCustomImage(IDR_THEME_FRAME))
555 return false;
556 #if defined(OS_WIN)
557 return ui::win::IsAeroGlassEnabled();
558 #else
559 return false;
560 #endif
561 }
562
563 bool ThemeService::HasCustomImage(int id) const {
564 return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
565 theme_supplier_->HasCustomImage(id);
566 }
567
568 base::RefCountedMemory* ThemeService::GetRawData(
569 int id,
570 ui::ScaleFactor scale_factor) const {
571 // Check to see whether we should substitute some images.
572 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE);
573 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0)
574 id = IDR_PRODUCT_LOGO_WHITE;
575
576 base::RefCountedMemory* data = nullptr;
577 if (theme_supplier_)
578 data = theme_supplier_->GetRawData(id, scale_factor);
579 if (!data)
580 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P);
581
582 return data;
583 }
584
585 gfx::Image ThemeService::GetImageNamed(int id) const {
586 DCHECK(CalledOnValidThread());
587
588 gfx::Image image;
589 if (theme_supplier_)
590 image = theme_supplier_->GetImageNamed(id);
591
592 if (image.IsEmpty())
593 image = rb_.GetNativeImageNamed(id);
594
595 return image;
596 }
597
591 void ThemeService::OnExtensionServiceReady() { 598 void ThemeService::OnExtensionServiceReady() {
592 if (!ready_) { 599 if (!ready_) {
593 // If the ThemeService is not ready yet, the custom theme data pack needs to 600 // If the ThemeService is not ready yet, the custom theme data pack needs to
594 // be recreated from the extension. 601 // be recreated from the extension.
595 MigrateTheme(); 602 MigrateTheme();
596 set_ready(); 603 set_ready();
597 604
598 // Send notification in case anyone requested data and cached it when the 605 // Send notification in case anyone requested data and cached it when the
599 // theme service was not ready yet. 606 // theme service was not ready yet.
600 NotifyThemeChanged(); 607 NotifyThemeChanged();
(...skipping 26 matching lines...) Expand all
627 content::RecordAction(UserMetricsAction("Themes.Migrated")); 634 content::RecordAction(UserMetricsAction("Themes.Migrated"));
628 } else { 635 } else {
629 DLOG(ERROR) << "Theme is mysteriously gone."; 636 DLOG(ERROR) << "Theme is mysteriously gone.";
630 ClearAllThemeData(); 637 ClearAllThemeData();
631 content::RecordAction(UserMetricsAction("Themes.Gone")); 638 content::RecordAction(UserMetricsAction("Themes.Gone"));
632 } 639 }
633 } 640 }
634 641
635 void ThemeService::SwapThemeSupplier( 642 void ThemeService::SwapThemeSupplier(
636 scoped_refptr<CustomThemeSupplier> theme_supplier) { 643 scoped_refptr<CustomThemeSupplier> theme_supplier) {
637 if (theme_supplier_.get()) 644 if (theme_supplier_)
638 theme_supplier_->StopUsingTheme(); 645 theme_supplier_->StopUsingTheme();
639 theme_supplier_ = theme_supplier; 646 theme_supplier_ = theme_supplier;
640 if (theme_supplier_.get()) 647 if (theme_supplier_)
641 theme_supplier_->StartUsingTheme(); 648 theme_supplier_->StartUsingTheme();
642 } 649 }
643 650
644 void ThemeService::SavePackName(const base::FilePath& pack_path) { 651 void ThemeService::SavePackName(const base::FilePath& pack_path) {
645 profile_->GetPrefs()->SetFilePath( 652 profile_->GetPrefs()->SetFilePath(
646 prefs::kCurrentThemePackFilename, pack_path); 653 prefs::kCurrentThemePackFilename, pack_path);
647 } 654 }
648 655
649 void ThemeService::SaveThemeID(const std::string& id) { 656 void ThemeService::SaveThemeID(const std::string& id) {
650 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); 657 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 void ThemeService::OnInfobarDestroyed() { 704 void ThemeService::OnInfobarDestroyed() {
698 number_of_infobars_--; 705 number_of_infobars_--;
699 706
700 if (number_of_infobars_ == 0) 707 if (number_of_infobars_ == 0)
701 RemoveUnusedThemes(false); 708 RemoveUnusedThemes(false);
702 } 709 }
703 710
704 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 711 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
705 return theme_syncable_service_.get(); 712 return theme_syncable_service_.get();
706 } 713 }
714
715 // static
716 const ui::ThemeProvider& ThemeService::GetThemeProviderForProfile(
717 Profile* profile) {
718 ThemeService* service = ThemeServiceFactory::GetForProfile(profile);
719 #if defined(OS_MACOSX)
720 // TODO(estade): this doesn't work for OSX yet; fall back to normal theming
721 // in incognito. Since the OSX version of ThemeService caches colors, and
722 // both ThemeProviders use the same ThemeService some code needs to be
723 // rearranged.
724 bool off_the_record = false;
725 #else
726 bool off_the_record = profile->IsOffTheRecord();
727 #endif
728 return off_the_record ? service->otr_theme_provider_
729 : service->original_theme_provider_;
730 }
731
732 ThemeService::BrowserThemeProvider::BrowserThemeProvider(
733 const ThemeService& theme_service,
734 bool off_the_record)
735 : theme_service_(theme_service), off_the_record_(off_the_record) {}
736
737 ThemeService::BrowserThemeProvider::~BrowserThemeProvider() {}
738
739 gfx::ImageSkia* ThemeService::BrowserThemeProvider::GetImageSkiaNamed(
740 int id) const {
741 return theme_service_.GetImageSkiaNamed(id);
742 }
743
744 SkColor ThemeService::BrowserThemeProvider::GetColor(int id) const {
745 return theme_service_.GetColor(id_for_profile, off_the_record_);
746 }
747
748 int ThemeService::BrowserThemeProvider::GetDisplayProperty(int id) const {
749 return theme_service_.GetDisplayProperty(id);
750 }
751
752 bool ThemeService::BrowserThemeProvider::ShouldUseNativeFrame() const {
753 return theme_service_.ShouldUseNativeFrame();
754 }
755
756 bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const {
757 return theme_service_.HasCustomImage(id);
758 }
759
760 base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData(
761 int id,
762 ui::ScaleFactor scale_factor) const {
763 return theme_service_.GetRawData(id, scale_factor);
764 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698