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 | |
235 LoadThemePrefs(); | 227 LoadThemePrefs(); |
236 | 228 |
237 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 229 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
238 } | 230 } |
239 | 231 |
240 gfx::Image ThemeService::GetImageNamed(int id) const { | 232 gfx::Image ThemeService::GetImageNamed(int id) const { |
241 DCHECK(CalledOnValidThread()); | 233 DCHECK(CalledOnValidThread()); |
242 | 234 |
243 const gfx::Image* image = NULL; | 235 const gfx::Image* image = NULL; |
244 | 236 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 333 |
342 return data; | 334 return data; |
343 } | 335 } |
344 | 336 |
345 void ThemeService::SetTheme(const Extension* extension) { | 337 void ThemeService::SetTheme(const Extension* extension) { |
346 // Clear our image cache. | 338 // Clear our image cache. |
347 FreePlatformCaches(); | 339 FreePlatformCaches(); |
348 | 340 |
349 DCHECK(extension); | 341 DCHECK(extension); |
350 DCHECK(extension->is_theme()); | 342 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 } |
351 | 349 |
352 BuildFromExtension(extension); | 350 BuildFromExtension(extension); |
353 SaveThemeID(extension->id()); | 351 SaveThemeID(extension->id()); |
354 | 352 |
355 NotifyThemeChanged(); | 353 NotifyThemeChanged(); |
356 content::RecordAction(UserMetricsAction("Themes_Installed")); | 354 content::RecordAction(UserMetricsAction("Themes_Installed")); |
357 } | 355 } |
358 | 356 |
359 void ThemeService::RemoveUnusedThemes() { | 357 void ThemeService::RemoveUnusedThemes() { |
360 if (!profile_) | 358 if (!profile_) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 theme_syncable_service_->OnThemeChange(); | 647 theme_syncable_service_->OnThemeChange(); |
650 } | 648 } |
651 } | 649 } |
652 | 650 |
653 #if defined(OS_WIN) || defined(USE_AURA) | 651 #if defined(OS_WIN) || defined(USE_AURA) |
654 void ThemeService::FreePlatformCaches() { | 652 void ThemeService::FreePlatformCaches() { |
655 // Views (Skia) has no platform image cache to clear. | 653 // Views (Skia) has no platform image cache to clear. |
656 } | 654 } |
657 #endif | 655 #endif |
658 | 656 |
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 | |
670 void ThemeService::SavePackName(const FilePath& pack_path) { | 657 void ThemeService::SavePackName(const FilePath& pack_path) { |
671 profile_->GetPrefs()->SetFilePath( | 658 profile_->GetPrefs()->SetFilePath( |
672 prefs::kCurrentThemePackFilename, pack_path); | 659 prefs::kCurrentThemePackFilename, pack_path); |
673 } | 660 } |
674 | 661 |
675 void ThemeService::SaveThemeID(const std::string& id) { | 662 void ThemeService::SaveThemeID(const std::string& id) { |
676 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); | 663 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); |
677 } | 664 } |
678 | 665 |
679 void ThemeService::BuildFromExtension(const Extension* extension) { | 666 void ThemeService::BuildFromExtension(const Extension* extension) { |
(...skipping 28 matching lines...) Expand all Loading... |
708 void ThemeService::OnInfobarDestroyed() { | 695 void ThemeService::OnInfobarDestroyed() { |
709 number_of_infobars_--; | 696 number_of_infobars_--; |
710 | 697 |
711 if (number_of_infobars_ == 0) | 698 if (number_of_infobars_ == 0) |
712 RemoveUnusedThemes(); | 699 RemoveUnusedThemes(); |
713 } | 700 } |
714 | 701 |
715 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 702 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
716 return theme_syncable_service_.get(); | 703 return theme_syncable_service_.get(); |
717 } | 704 } |
OLD | NEW |