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
3 // found in the LICENSE file.
5 #include "chrome/browser/themes/theme_service_factory.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
15 #include "components/user_prefs/pref_registry_syncable.h"
17 #if defined(TOOLKIT_GTK)
18 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
21 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
22 #include "chrome/browser/themes/theme_service_aurax11.h"
23 #include "ui/views/linux_ui/linux_ui.h"
27 ThemeService
* ThemeServiceFactory::GetForProfile(Profile
* profile
) {
28 return static_cast<ThemeService
*>(
29 GetInstance()->GetServiceForBrowserContext(profile
, true));
33 const extensions::Extension
* ThemeServiceFactory::GetThemeForProfile(
35 std::string id
= GetForProfile(profile
)->GetThemeID();
36 if (id
== ThemeService::kDefaultThemeID
)
39 return profile
->GetExtensionService()->GetExtensionById(id
, false);
43 ThemeServiceFactory
* ThemeServiceFactory::GetInstance() {
44 return Singleton
<ThemeServiceFactory
>::get();
47 ThemeServiceFactory::ThemeServiceFactory()
48 : BrowserContextKeyedServiceFactory(
50 BrowserContextDependencyManager::GetInstance()) {}
52 ThemeServiceFactory::~ThemeServiceFactory() {}
54 BrowserContextKeyedService
* ThemeServiceFactory::BuildServiceInstanceFor(
55 content::BrowserContext
* profile
) const {
56 ThemeService
* provider
= NULL
;
57 #if defined(TOOLKIT_GTK)
58 provider
= new GtkThemeService
;
59 #elif defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
60 provider
= new ThemeServiceAuraX11
;
62 provider
= new ThemeService
;
64 provider
->Init(static_cast<Profile
*>(profile
));
69 void ThemeServiceFactory::RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable
* registry
) {
71 #if defined(USE_X11) && !defined(OS_CHROMEOS)
72 bool default_uses_system_theme
= false;
74 #if defined(TOOLKIT_GTK)
75 default_uses_system_theme
= GtkThemeService::DefaultUsesSystemTheme();
76 #elif defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
77 const views::LinuxUI
* linux_ui
= views::LinuxUI::instance();
79 default_uses_system_theme
= linux_ui
->GetDefaultUsesSystemTheme();
82 registry
->RegisterBooleanPref(
83 prefs::kUsesSystemTheme
,
84 default_uses_system_theme
,
85 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
87 registry
->RegisterFilePathPref(
88 prefs::kCurrentThemePackFilename
,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
91 registry
->RegisterStringPref(
92 prefs::kCurrentThemeID
,
93 ThemeService::kDefaultThemeID
,
94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
95 registry
->RegisterDictionaryPref(
96 prefs::kCurrentThemeImages
,
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
98 registry
->RegisterDictionaryPref(
99 prefs::kCurrentThemeColors
,
100 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
101 registry
->RegisterDictionaryPref(
102 prefs::kCurrentThemeTints
,
103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
104 registry
->RegisterDictionaryPref(
105 prefs::kCurrentThemeDisplayProperties
,
106 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
109 content::BrowserContext
* ThemeServiceFactory::GetBrowserContextToUse(
110 content::BrowserContext
* context
) const {
111 return chrome::GetBrowserContextRedirectedInIncognito(context
);
114 bool ThemeServiceFactory::ServiceIsCreatedWithBrowserContext() const {