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/plugins/plugin_prefs_factory.h"
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"
19 PluginPrefsFactory
* PluginPrefsFactory::GetInstance() {
20 return Singleton
<PluginPrefsFactory
>::get();
24 scoped_refptr
<PluginPrefs
> PluginPrefsFactory::GetPrefsForProfile(
26 return static_cast<PluginPrefs
*>(
27 GetInstance()->GetServiceForBrowserContext(profile
, true).get());
31 scoped_refptr
<RefcountedKeyedService
>
32 PluginPrefsFactory::CreateForTestingProfile(content::BrowserContext
* profile
) {
33 return static_cast<PluginPrefs
*>(
34 GetInstance()->BuildServiceInstanceFor(profile
).get());
37 PluginPrefsFactory::PluginPrefsFactory()
38 : RefcountedBrowserContextKeyedServiceFactory(
39 "PluginPrefs", BrowserContextDependencyManager::GetInstance()) {
42 PluginPrefsFactory::~PluginPrefsFactory() {}
44 scoped_refptr
<RefcountedKeyedService
>
45 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());
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(prefs::kPluginsLastInternalDirectory
,
60 registry
->RegisterBooleanPref(prefs::kNpapiFlashMigratedToPepperFlash
, false);
61 registry
->RegisterListPref(prefs::kPluginsPluginsList
);
62 registry
->RegisterListPref(prefs::kPluginsDisabledPlugins
);
63 registry
->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions
);
64 registry
->RegisterListPref(prefs::kPluginsEnabledPlugins
);
67 content::BrowserContext
* PluginPrefsFactory::GetBrowserContextToUse(
68 content::BrowserContext
* context
) const {
69 return chrome::GetBrowserContextRedirectedInIncognito(context
);
72 bool PluginPrefsFactory::ServiceIsNULLWhileTesting() const {
76 bool PluginPrefsFactory::ServiceIsCreatedWithBrowserContext() const {