| OLD | NEW |
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 ThemeService::~ThemeService() { | 219 ThemeService::~ThemeService() { |
| 220 FreePlatformCaches(); | 220 FreePlatformCaches(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ThemeService::Init(Profile* profile) { | 223 void ThemeService::Init(Profile* profile) { |
| 224 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
| 225 profile_ = profile; | 225 profile_ = profile; |
| 226 | 226 |
| 227 // Listen to EXTENSION_LOADED instead of EXTENSION_INSTALLED because |
| 228 // the extension cannot yet be found via GetExtensionById() if it is |
| 229 // installed but not loaded (which may confuse listeners to |
| 230 // BROWSER_THEME_CHANGED). |
| 231 registrar_.Add(this, |
| 232 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 233 content::Source<Profile>(profile_)); |
| 234 |
| 227 LoadThemePrefs(); | 235 LoadThemePrefs(); |
| 228 | 236 |
| 229 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 237 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
| 230 } | 238 } |
| 231 | 239 |
| 232 gfx::Image ThemeService::GetImageNamed(int id) const { | 240 gfx::Image ThemeService::GetImageNamed(int id) const { |
| 233 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
| 234 | 242 |
| 235 const gfx::Image* image = NULL; | 243 const gfx::Image* image = NULL; |
| 236 | 244 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 341 |
| 334 return data; | 342 return data; |
| 335 } | 343 } |
| 336 | 344 |
| 337 void ThemeService::SetTheme(const Extension* extension) { | 345 void ThemeService::SetTheme(const Extension* extension) { |
| 338 // Clear our image cache. | 346 // Clear our image cache. |
| 339 FreePlatformCaches(); | 347 FreePlatformCaches(); |
| 340 | 348 |
| 341 DCHECK(extension); | 349 DCHECK(extension); |
| 342 DCHECK(extension->is_theme()); | 350 DCHECK(extension->is_theme()); |
| 343 if (DCHECK_IS_ON()) { | |
| 344 ExtensionService* service = | |
| 345 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 346 DCHECK(service); | |
| 347 DCHECK(service->GetExtensionById(extension->id(), false)); | |
| 348 } | |
| 349 | 351 |
| 350 BuildFromExtension(extension); | 352 BuildFromExtension(extension); |
| 351 SaveThemeID(extension->id()); | 353 SaveThemeID(extension->id()); |
| 352 | 354 |
| 353 NotifyThemeChanged(); | 355 NotifyThemeChanged(); |
| 354 content::RecordAction(UserMetricsAction("Themes_Installed")); | 356 content::RecordAction(UserMetricsAction("Themes_Installed")); |
| 355 } | 357 } |
| 356 | 358 |
| 357 void ThemeService::RemoveUnusedThemes() { | 359 void ThemeService::RemoveUnusedThemes() { |
| 358 if (!profile_) | 360 if (!profile_) |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 theme_syncable_service_->OnThemeChange(); | 649 theme_syncable_service_->OnThemeChange(); |
| 648 } | 650 } |
| 649 } | 651 } |
| 650 | 652 |
| 651 #if defined(OS_WIN) || defined(USE_AURA) | 653 #if defined(OS_WIN) || defined(USE_AURA) |
| 652 void ThemeService::FreePlatformCaches() { | 654 void ThemeService::FreePlatformCaches() { |
| 653 // Views (Skia) has no platform image cache to clear. | 655 // Views (Skia) has no platform image cache to clear. |
| 654 } | 656 } |
| 655 #endif | 657 #endif |
| 656 | 658 |
| 659 void ThemeService::Observe(int type, |
| 660 const content::NotificationSource& source, |
| 661 const content::NotificationDetails& details) { |
| 662 DCHECK(type == chrome::NOTIFICATION_EXTENSION_LOADED); |
| 663 const Extension* extension = content::Details<const Extension>(details).ptr(); |
| 664 if (!extension->is_theme()) { |
| 665 return; |
| 666 } |
| 667 SetTheme(extension); |
| 668 } |
| 669 |
| 657 void ThemeService::SavePackName(const FilePath& pack_path) { | 670 void ThemeService::SavePackName(const FilePath& pack_path) { |
| 658 profile_->GetPrefs()->SetFilePath( | 671 profile_->GetPrefs()->SetFilePath( |
| 659 prefs::kCurrentThemePackFilename, pack_path); | 672 prefs::kCurrentThemePackFilename, pack_path); |
| 660 } | 673 } |
| 661 | 674 |
| 662 void ThemeService::SaveThemeID(const std::string& id) { | 675 void ThemeService::SaveThemeID(const std::string& id) { |
| 663 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); | 676 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); |
| 664 } | 677 } |
| 665 | 678 |
| 666 void ThemeService::BuildFromExtension(const Extension* extension) { | 679 void ThemeService::BuildFromExtension(const Extension* extension) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 695 void ThemeService::OnInfobarDestroyed() { | 708 void ThemeService::OnInfobarDestroyed() { |
| 696 number_of_infobars_--; | 709 number_of_infobars_--; |
| 697 | 710 |
| 698 if (number_of_infobars_ == 0) | 711 if (number_of_infobars_ == 0) |
| 699 RemoveUnusedThemes(); | 712 RemoveUnusedThemes(); |
| 700 } | 713 } |
| 701 | 714 |
| 702 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 715 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 703 return theme_syncable_service_.get(); | 716 return theme_syncable_service_.get(); |
| 704 } | 717 } |
| OLD | NEW |