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

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: add a test 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 id) const {
456 DCHECK(CalledOnValidThread());
457 // Custom themes always use the original (non-incognito) color.
458 int original_id = Properties::IncognitoPropertyToProperty(id);
459 SkColor color;
pkotwicz 2015/12/04 23:16:49 CustomThemeProviders do provide some incognito col
Evan Stade 2015/12/09 00:57:10 changed to pkasting's suggestion
460 if (theme_supplier_ && theme_supplier_->GetColor(original_id, &color))
461 return color;
462
463 // For backward compat with older themes, some newer colors are generated from
464 // older ones if they are missing.
465 switch (id) {
466 case Properties::COLOR_TOOLBAR_BUTTON_ICON:
467 return color_utils::HSLShift(gfx::kChromeIconGrey,
468 GetTint(Properties::TINT_BUTTONS));
469 case Properties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
470 // The active color is overridden in Gtk2UI.
471 return SkColorSetA(GetColor(Properties::COLOR_TOOLBAR_BUTTON_ICON), 0x33);
472 case Properties::COLOR_NTP_SECTION_HEADER_TEXT:
473 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30);
474 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER:
475 return GetColor(Properties::COLOR_NTP_TEXT);
476 case Properties::COLOR_NTP_SECTION_HEADER_RULE:
477 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70);
478 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT:
479 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86);
480 case Properties::COLOR_NTP_TEXT_LIGHT:
481 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40);
482 case Properties::COLOR_TAB_THROBBER_SPINNING:
483 case Properties::COLOR_TAB_THROBBER_WAITING: {
484 SkColor base_color =
485 ui::GetAuraColor(id == Properties::COLOR_TAB_THROBBER_SPINNING
486 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
487 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
488 nullptr);
489 color_utils::HSL hsl = GetTint(Properties::TINT_BUTTONS);
490 return color_utils::HSLShift(base_color, hsl);
491 }
492 #if defined(ENABLE_SUPERVISED_USERS)
493 case Properties::COLOR_SUPERVISED_USER_LABEL:
494 return color_utils::GetReadableColor(
495 SK_ColorWHITE,
496 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND));
497 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
498 return color_utils::BlendTowardOppositeLuminance(
499 GetColor(Properties::COLOR_FRAME), 0x80);
500 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER:
501 return color_utils::AlphaBlend(
502 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND),
503 SK_ColorBLACK, 230);
504 #endif
505 case Properties::COLOR_STATUS_BAR_TEXT: {
506 // A long time ago, we blended the toolbar and the tab text together to
507 // get the status bar text because, at the time, our text rendering in
508 // views couldn't do alpha blending. Even though this is no longer the
509 // case, this blending decision is built into the majority of themes that
510 // exist, and we must keep doing it.
511 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR);
512 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT);
513 return SkColorSetARGB(
514 SkColorGetA(text_color),
515 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2,
516 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2,
517 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2);
518 }
519 }
520
521 return Properties::GetDefaultColor(id);
522 }
523
524 int ThemeService::GetDisplayProperty(int id) const {
525 int result = 0;
526 if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) {
527 return result;
528 }
529
530 switch (id) {
531 case Properties::NTP_BACKGROUND_ALIGNMENT:
532 return Properties::ALIGN_CENTER;
533
534 case Properties::NTP_BACKGROUND_TILING:
535 return Properties::NO_REPEAT;
536
537 case Properties::NTP_LOGO_ALTERNATE:
538 return UsingDefaultTheme() || UsingSystemTheme() ||
539 (!HasCustomImage(IDR_THEME_NTP_BACKGROUND) &&
540 IsColorGrayscale(
541 GetColor(Properties::COLOR_NTP_BACKGROUND)))
pkotwicz 2015/12/04 23:16:49 Nit: Alignment looks off
Evan Stade 2015/12/09 00:57:10 in what way? this is the output of git cl format
542 ? 0
543 : 1;
544
545 default:
546 return -1;
547 }
548 }
549
550 bool ThemeService::ShouldUseNativeFrame() const {
551 if (HasCustomImage(IDR_THEME_FRAME))
552 return false;
553 #if defined(OS_WIN)
554 return ui::win::IsAeroGlassEnabled();
555 #else
556 return false;
557 #endif
558 }
559
560 bool ThemeService::HasCustomImage(int id) const {
561 return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
562 theme_supplier_->HasCustomImage(id);
563 }
564
565 base::RefCountedMemory* ThemeService::GetRawData(
566 int id,
567 ui::ScaleFactor scale_factor) const {
568 // Check to see whether we should substitute some images.
569 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE);
570 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0)
571 id = IDR_PRODUCT_LOGO_WHITE;
572
573 base::RefCountedMemory* data = nullptr;
574 if (theme_supplier_)
575 data = theme_supplier_->GetRawData(id, scale_factor);
576 if (!data)
577 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P);
578
579 return data;
580 }
581
582 gfx::Image ThemeService::GetImageNamed(int id) const {
583 DCHECK(CalledOnValidThread());
584
585 gfx::Image image;
586 if (theme_supplier_)
587 image = theme_supplier_->GetImageNamed(id);
588
589 if (image.IsEmpty())
590 image = rb_.GetNativeImageNamed(id);
591
592 return image;
593 }
594
591 void ThemeService::OnExtensionServiceReady() { 595 void ThemeService::OnExtensionServiceReady() {
592 if (!ready_) { 596 if (!ready_) {
593 // If the ThemeService is not ready yet, the custom theme data pack needs to 597 // If the ThemeService is not ready yet, the custom theme data pack needs to
594 // be recreated from the extension. 598 // be recreated from the extension.
595 MigrateTheme(); 599 MigrateTheme();
596 set_ready(); 600 set_ready();
597 601
598 // Send notification in case anyone requested data and cached it when the 602 // Send notification in case anyone requested data and cached it when the
599 // theme service was not ready yet. 603 // theme service was not ready yet.
600 NotifyThemeChanged(); 604 NotifyThemeChanged();
(...skipping 26 matching lines...) Expand all
627 content::RecordAction(UserMetricsAction("Themes.Migrated")); 631 content::RecordAction(UserMetricsAction("Themes.Migrated"));
628 } else { 632 } else {
629 DLOG(ERROR) << "Theme is mysteriously gone."; 633 DLOG(ERROR) << "Theme is mysteriously gone.";
630 ClearAllThemeData(); 634 ClearAllThemeData();
631 content::RecordAction(UserMetricsAction("Themes.Gone")); 635 content::RecordAction(UserMetricsAction("Themes.Gone"));
632 } 636 }
633 } 637 }
634 638
635 void ThemeService::SwapThemeSupplier( 639 void ThemeService::SwapThemeSupplier(
636 scoped_refptr<CustomThemeSupplier> theme_supplier) { 640 scoped_refptr<CustomThemeSupplier> theme_supplier) {
637 if (theme_supplier_.get()) 641 if (theme_supplier_)
638 theme_supplier_->StopUsingTheme(); 642 theme_supplier_->StopUsingTheme();
639 theme_supplier_ = theme_supplier; 643 theme_supplier_ = theme_supplier;
640 if (theme_supplier_.get()) 644 if (theme_supplier_)
641 theme_supplier_->StartUsingTheme(); 645 theme_supplier_->StartUsingTheme();
642 } 646 }
643 647
644 void ThemeService::SavePackName(const base::FilePath& pack_path) { 648 void ThemeService::SavePackName(const base::FilePath& pack_path) {
645 profile_->GetPrefs()->SetFilePath( 649 profile_->GetPrefs()->SetFilePath(
646 prefs::kCurrentThemePackFilename, pack_path); 650 prefs::kCurrentThemePackFilename, pack_path);
647 } 651 }
648 652
649 void ThemeService::SaveThemeID(const std::string& id) { 653 void ThemeService::SaveThemeID(const std::string& id) {
650 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); 654 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 void ThemeService::OnInfobarDestroyed() { 701 void ThemeService::OnInfobarDestroyed() {
698 number_of_infobars_--; 702 number_of_infobars_--;
699 703
700 if (number_of_infobars_ == 0) 704 if (number_of_infobars_ == 0)
701 RemoveUnusedThemes(false); 705 RemoveUnusedThemes(false);
702 } 706 }
703 707
704 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { 708 ThemeSyncableService* ThemeService::GetThemeSyncableService() const {
705 return theme_syncable_service_.get(); 709 return theme_syncable_service_.get();
706 } 710 }
711
712 // static
713 const ui::ThemeProvider& ThemeService::GetThemeProviderForProfile(
pkotwicz 2015/12/04 23:16:49 I kind of like the idea of having ThemeProviderFac
Evan Stade 2015/12/09 00:57:11 hmm, pkasting, wdyt? I like having this factory fu
Peter Kasting 2015/12/09 01:31:59 I don't feel like I care much either way. The ide
714 Profile* profile) {
715 ThemeService* service = ThemeServiceFactory::GetForProfile(profile);
716 #if defined(OS_MACOSX)
717 // TODO(estade): this doesn't work for OSX yet; fall back to normal theming
718 // in incognito. Since the OSX version of ThemeService caches colors, and
719 // both ThemeProviders use the same ThemeService some code needs to be
720 // rearranged.
721 bool off_the_record = false;
722 #else
723 bool off_the_record = profile->IsOffTheRecord();
724 #endif
725 return off_the_record ? service->otr_theme_provider_
726 : service->original_theme_provider_;
727 }
728
729 ThemeService::BrowserThemeProvider::BrowserThemeProvider(
730 const ThemeService& theme_service,
731 bool otr)
732 : theme_service_(theme_service), otr_(otr) {}
733
734 ThemeService::BrowserThemeProvider::~BrowserThemeProvider() {}
735
736 gfx::ImageSkia* ThemeService::BrowserThemeProvider::GetImageSkiaNamed(
737 int id) const {
738 return theme_service_.GetImageSkiaNamed(id);
739 }
740
741 SkColor ThemeService::BrowserThemeProvider::GetColor(int id) const {
742 int id_for_profile =
743 otr_ ? ThemeProperties::PropertyToIncognitoProperty(id) : id;
Peter Kasting 2015/12/08 22:52:58 Rather than map here, and then map back the other
Evan Stade 2015/12/09 00:57:11 Done.
744 return theme_service_.GetColor(id_for_profile);
745 }
746
747 int ThemeService::BrowserThemeProvider::GetDisplayProperty(int id) const {
748 return theme_service_.GetDisplayProperty(id);
749 }
750
751 bool ThemeService::BrowserThemeProvider::ShouldUseNativeFrame() const {
752 return theme_service_.ShouldUseNativeFrame();
753 }
754
755 bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const {
756 return theme_service_.HasCustomImage(id);
757 }
758
759 base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData(
760 int id,
761 ui::ScaleFactor scale_factor) const {
762 return theme_service_.GetRawData(id, scale_factor);
763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698