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_factory.h" | 5 #include "chrome/browser/themes/theme_service_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_dependency_manager.h" | 11 #include "chrome/browser/profiles/profile_dependency_manager.h" |
12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 | 14 |
15 #if defined(TOOLKIT_GTK) | 15 #if defined(TOOLKIT_GTK) |
16 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 16 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
17 #endif | 17 #endif |
18 | 18 |
19 // static | 19 // static |
20 ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) { | 20 ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) { |
21 return static_cast<ThemeService*>( | 21 return static_cast<ThemeService*>( |
22 GetInstance()->GetServiceForProfile(profile, true /* create */)); | 22 GetInstance()->GetServiceForProfile(profile, true)); |
| 23 } |
| 24 |
| 25 // static |
| 26 const extensions::Extension* ThemeServiceFactory::GetThemeForProfile( |
| 27 Profile* profile) { |
| 28 std::string id = GetForProfile(profile)->GetThemeID(); |
| 29 if (id == ThemeService::kDefaultThemeID) |
| 30 return NULL; |
| 31 |
| 32 return profile->GetExtensionService()->GetExtensionById(id, false); |
23 } | 33 } |
24 | 34 |
25 // static | 35 // static |
26 ThemeServiceFactory* ThemeServiceFactory::GetInstance() { | 36 ThemeServiceFactory* ThemeServiceFactory::GetInstance() { |
27 return Singleton<ThemeServiceFactory>::get(); | 37 return Singleton<ThemeServiceFactory>::get(); |
28 } | 38 } |
29 | 39 |
30 // static | |
31 void ThemeServiceFactory::SetThemeForProfile( | |
32 Profile* profile, | |
33 const extensions::Extension* theme) { | |
34 ThemeService* theme_service = | |
35 static_cast<ThemeService*>( | |
36 GetInstance()->GetServiceForProfile(profile, false /* create */)); | |
37 if (theme_service) { | |
38 theme_service->SetTheme(theme); | |
39 } else { | |
40 // The theme service will pick up the new theme when it's created. | |
41 ThemeService::SaveThemeIDForProfile(profile, theme->id()); | |
42 } | |
43 } | |
44 | |
45 ThemeServiceFactory::ThemeServiceFactory() | 40 ThemeServiceFactory::ThemeServiceFactory() |
46 : ProfileKeyedServiceFactory("ThemeService", | 41 : ProfileKeyedServiceFactory("ThemeService", |
47 ProfileDependencyManager::GetInstance()) {} | 42 ProfileDependencyManager::GetInstance()) {} |
48 | 43 |
49 ThemeServiceFactory::~ThemeServiceFactory() {} | 44 ThemeServiceFactory::~ThemeServiceFactory() {} |
50 | 45 |
51 ProfileKeyedService* ThemeServiceFactory::BuildServiceInstanceFor( | 46 ProfileKeyedService* ThemeServiceFactory::BuildServiceInstanceFor( |
52 Profile* profile) const { | 47 Profile* profile) const { |
53 ThemeService* provider = NULL; | 48 ThemeService* provider = NULL; |
54 #if defined(TOOLKIT_GTK) | 49 #if defined(TOOLKIT_GTK) |
(...skipping 24 matching lines...) Expand all Loading... |
79 PrefService::UNSYNCABLE_PREF); | 74 PrefService::UNSYNCABLE_PREF); |
80 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints, | 75 prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints, |
81 PrefService::UNSYNCABLE_PREF); | 76 PrefService::UNSYNCABLE_PREF); |
82 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties, | 77 prefs->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties, |
83 PrefService::UNSYNCABLE_PREF); | 78 PrefService::UNSYNCABLE_PREF); |
84 } | 79 } |
85 | 80 |
86 bool ThemeServiceFactory::ServiceRedirectedInIncognito() const { | 81 bool ThemeServiceFactory::ServiceRedirectedInIncognito() const { |
87 return true; | 82 return true; |
88 } | 83 } |
OLD | NEW |