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/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/themes/theme_service.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "extensions/browser/extension_registry.h"
17 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
18 #include "chrome/browser/themes/theme_service_aurax11.h"
19 #include "ui/views/linux_ui/linux_ui.h"
23 ThemeService
* ThemeServiceFactory::GetForProfile(Profile
* profile
) {
24 return static_cast<ThemeService
*>(
25 GetInstance()->GetServiceForBrowserContext(profile
, true));
29 const extensions::Extension
* ThemeServiceFactory::GetThemeForProfile(
31 std::string id
= GetForProfile(profile
)->GetThemeID();
32 if (id
== ThemeService::kDefaultThemeID
)
35 return extensions::ExtensionRegistry::Get(
36 profile
)->enabled_extensions().GetByID(id
);
40 ThemeServiceFactory
* ThemeServiceFactory::GetInstance() {
41 return Singleton
<ThemeServiceFactory
>::get();
44 ThemeServiceFactory::ThemeServiceFactory()
45 : BrowserContextKeyedServiceFactory(
47 BrowserContextDependencyManager::GetInstance()) {}
49 ThemeServiceFactory::~ThemeServiceFactory() {}
51 KeyedService
* ThemeServiceFactory::BuildServiceInstanceFor(
52 content::BrowserContext
* profile
) const {
53 ThemeService
* provider
= NULL
;
54 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
55 provider
= new ThemeServiceAuraX11
;
57 provider
= new ThemeService
;
59 provider
->Init(static_cast<Profile
*>(profile
));
64 void ThemeServiceFactory::RegisterProfilePrefs(
65 user_prefs::PrefRegistrySyncable
* registry
) {
66 #if defined(USE_X11) && !defined(OS_CHROMEOS)
67 bool default_uses_system_theme
= false;
69 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
70 const views::LinuxUI
* linux_ui
= views::LinuxUI::instance();
72 default_uses_system_theme
= linux_ui
->GetDefaultUsesSystemTheme();
75 registry
->RegisterBooleanPref(
76 prefs::kUsesSystemTheme
,
77 default_uses_system_theme
,
78 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
80 registry
->RegisterFilePathPref(
81 prefs::kCurrentThemePackFilename
,
83 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
84 registry
->RegisterStringPref(
85 prefs::kCurrentThemeID
,
86 ThemeService::kDefaultThemeID
,
87 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
88 registry
->RegisterDictionaryPref(
89 prefs::kCurrentThemeImages
,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
91 registry
->RegisterDictionaryPref(
92 prefs::kCurrentThemeColors
,
93 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
94 registry
->RegisterDictionaryPref(
95 prefs::kCurrentThemeTints
,
96 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
97 registry
->RegisterDictionaryPref(
98 prefs::kCurrentThemeDisplayProperties
,
99 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
102 content::BrowserContext
* ThemeServiceFactory::GetBrowserContextToUse(
103 content::BrowserContext
* context
) const {
104 return chrome::GetBrowserContextRedirectedInIncognito(context
);
107 bool ThemeServiceFactory::ServiceIsCreatedWithBrowserContext() const {