1 // Copyright (c) 2013 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 "base/command_line.h"
6 #include "base/prefs/pref_service.h"
7 #include "chrome/browser/extensions/extension_pref_value_map.h"
8 #include "chrome/browser/extensions/extension_pref_value_map_factory.h"
9 #include "chrome/browser/extensions/extension_prefs.h"
10 #include "chrome/browser/extensions/extension_prefs_factory.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
14 #include "content/public/browser/browser_context.h"
15 #include "extensions/browser/extensions_browser_client.h"
16 #include "extensions/common/constants.h"
18 namespace extensions
{
21 ExtensionPrefs
* ExtensionPrefsFactory::GetForBrowserContext(
22 content::BrowserContext
* context
) {
23 return static_cast<ExtensionPrefs
*>(
24 GetInstance()->GetServiceForBrowserContext(context
, true));
28 ExtensionPrefsFactory
* ExtensionPrefsFactory::GetInstance() {
29 return Singleton
<ExtensionPrefsFactory
>::get();
32 void ExtensionPrefsFactory::SetInstanceForTesting(
33 content::BrowserContext
* context
, ExtensionPrefs
* prefs
) {
34 Associate(context
, prefs
);
37 ExtensionPrefsFactory::ExtensionPrefsFactory()
38 : BrowserContextKeyedServiceFactory(
40 BrowserContextDependencyManager::GetInstance()) {
43 ExtensionPrefsFactory::~ExtensionPrefsFactory() {
46 BrowserContextKeyedService
* ExtensionPrefsFactory::BuildServiceInstanceFor(
47 content::BrowserContext
* context
) const {
48 ExtensionsBrowserClient
* client
= ExtensionsBrowserClient::Get();
49 return ExtensionPrefs::Create(
50 client
->GetPrefServiceForContext(context
),
51 context
->GetPath().AppendASCII(extensions::kInstallDirectoryName
),
52 ExtensionPrefValueMapFactory::GetForBrowserContext(context
),
53 client
->CreateAppSorting().Pass(),
54 client
->AreExtensionsDisabled(
55 *CommandLine::ForCurrentProcess(), context
));
58 content::BrowserContext
* ExtensionPrefsFactory::GetBrowserContextToUse(
59 content::BrowserContext
* context
) const {
60 return ExtensionsBrowserClient::Get()->GetOriginalContext(context
);
63 } // namespace extensions