Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / themes / theme_service_factory.cc
blob0ec15cd620f02a7ef38a255f87db86c3581e9251
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"
16 #include "extensions/browser/extension_registry_factory.h"
18 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
19 #include "chrome/browser/themes/theme_service_aurax11.h"
20 #include "ui/views/linux_ui/linux_ui.h"
21 #endif
23 // static
24 ThemeService* ThemeServiceFactory::GetForProfile(Profile* profile) {
25 return static_cast<ThemeService*>(
26 GetInstance()->GetServiceForBrowserContext(profile, true));
29 // static
30 const extensions::Extension* ThemeServiceFactory::GetThemeForProfile(
31 Profile* profile) {
32 std::string id = GetForProfile(profile)->GetThemeID();
33 if (id == ThemeService::kDefaultThemeID)
34 return NULL;
36 return extensions::ExtensionRegistry::Get(
37 profile)->enabled_extensions().GetByID(id);
40 // static
41 ThemeServiceFactory* ThemeServiceFactory::GetInstance() {
42 return base::Singleton<ThemeServiceFactory>::get();
45 ThemeServiceFactory::ThemeServiceFactory()
46 : BrowserContextKeyedServiceFactory(
47 "ThemeService",
48 BrowserContextDependencyManager::GetInstance()) {
49 DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
52 ThemeServiceFactory::~ThemeServiceFactory() {}
54 KeyedService* ThemeServiceFactory::BuildServiceInstanceFor(
55 content::BrowserContext* profile) const {
56 ThemeService* provider = NULL;
57 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
58 provider = new ThemeServiceAuraX11;
59 #else
60 provider = new ThemeService;
61 #endif
62 provider->Init(static_cast<Profile*>(profile));
64 return provider;
67 void ThemeServiceFactory::RegisterProfilePrefs(
68 user_prefs::PrefRegistrySyncable* registry) {
69 #if defined(USE_X11) && !defined(OS_CHROMEOS)
70 bool default_uses_system_theme = false;
72 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
73 const views::LinuxUI* linux_ui = views::LinuxUI::instance();
74 if (linux_ui)
75 default_uses_system_theme = linux_ui->GetDefaultUsesSystemTheme();
76 #endif
78 registry->RegisterBooleanPref(prefs::kUsesSystemTheme,
79 default_uses_system_theme);
80 #endif
81 registry->RegisterFilePathPref(prefs::kCurrentThemePackFilename,
82 base::FilePath());
83 registry->RegisterStringPref(prefs::kCurrentThemeID,
84 ThemeService::kDefaultThemeID);
85 registry->RegisterDictionaryPref(prefs::kCurrentThemeImages);
86 registry->RegisterDictionaryPref(prefs::kCurrentThemeColors);
87 registry->RegisterDictionaryPref(prefs::kCurrentThemeTints);
88 registry->RegisterDictionaryPref(prefs::kCurrentThemeDisplayProperties);
91 content::BrowserContext* ThemeServiceFactory::GetBrowserContextToUse(
92 content::BrowserContext* context) const {
93 return chrome::GetBrowserContextRedirectedInIncognito(context);
96 bool ThemeServiceFactory::ServiceIsCreatedWithBrowserContext() const {
97 return true;