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.
4
5 #include "chrome/browser/plugins/plugin_prefs_factory.h"
6
7 #include "base/path_service.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/plugins/plugin_prefs.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17
18 // static
GetInstance()19 PluginPrefsFactory* PluginPrefsFactory::GetInstance() {
20 return Singleton<PluginPrefsFactory>::get();
21 }
22
23 // static
GetPrefsForProfile(Profile * profile)24 scoped_refptr<PluginPrefs> PluginPrefsFactory::GetPrefsForProfile(
25 Profile* profile) {
26 return static_cast<PluginPrefs*>(
27 GetInstance()->GetServiceForBrowserContext(profile, true).get());
28 }
29
30 // static
31 scoped_refptr<RefcountedBrowserContextKeyedService>
CreateForTestingProfile(content::BrowserContext * profile)32 PluginPrefsFactory::CreateForTestingProfile(content::BrowserContext* profile) {
33 return static_cast<PluginPrefs*>(
34 GetInstance()->BuildServiceInstanceFor(profile).get());
35 }
36
PluginPrefsFactory()37 PluginPrefsFactory::PluginPrefsFactory()
38 : RefcountedBrowserContextKeyedServiceFactory(
39 "PluginPrefs", BrowserContextDependencyManager::GetInstance()) {
40 }
41
~PluginPrefsFactory()42 PluginPrefsFactory::~PluginPrefsFactory() {}
43
44 scoped_refptr<RefcountedBrowserContextKeyedService>
BuildServiceInstanceFor(content::BrowserContext * context) const45 PluginPrefsFactory::BuildServiceInstanceFor(
46 content::BrowserContext* context) const {
47 Profile* profile = static_cast<Profile*>(context);
48 scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs());
49 plugin_prefs->set_profile(profile->GetOriginalProfile());
50 plugin_prefs->SetPrefs(profile->GetPrefs());
51 return plugin_prefs;
52 }
53
RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)54 void PluginPrefsFactory::RegisterProfilePrefs(
55 user_prefs::PrefRegistrySyncable* registry) {
56 base::FilePath internal_dir;
57 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
58 registry->RegisterFilePathPref(
59 prefs::kPluginsLastInternalDirectory,
60 internal_dir,
61 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
62 registry->RegisterBooleanPref(
63 prefs::kPluginsMigratedToPepperFlash,
64 false,
65 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
66 registry->RegisterBooleanPref(
67 prefs::kPluginsRemovedOldComponentPepperFlashSettings,
68 false,
69 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
70 registry->RegisterListPref(prefs::kPluginsPluginsList,
71 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
72 registry->RegisterListPref(prefs::kPluginsDisabledPlugins,
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
74 registry->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions,
75 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
76 registry->RegisterListPref(prefs::kPluginsEnabledPlugins,
77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
78 }
79
GetBrowserContextToUse(content::BrowserContext * context) const80 content::BrowserContext* PluginPrefsFactory::GetBrowserContextToUse(
81 content::BrowserContext* context) const {
82 return chrome::GetBrowserContextRedirectedInIncognito(context);
83 }
84
ServiceIsNULLWhileTesting() const85 bool PluginPrefsFactory::ServiceIsNULLWhileTesting() const {
86 return true;
87 }
88
ServiceIsCreatedWithBrowserContext() const89 bool PluginPrefsFactory::ServiceIsCreatedWithBrowserContext() const {
90 return true;
91 }
92