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.
4
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"
17
18 namespace extensions {
19
20 // static
GetForBrowserContext(content::BrowserContext * context)21 ExtensionPrefs* ExtensionPrefsFactory::GetForBrowserContext(
22 content::BrowserContext* context) {
23 return static_cast<ExtensionPrefs*>(
24 GetInstance()->GetServiceForBrowserContext(context, true));
25 }
26
27 // static
GetInstance()28 ExtensionPrefsFactory* ExtensionPrefsFactory::GetInstance() {
29 return Singleton<ExtensionPrefsFactory>::get();
30 }
31
SetInstanceForTesting(content::BrowserContext * context,ExtensionPrefs * prefs)32 void ExtensionPrefsFactory::SetInstanceForTesting(
33 content::BrowserContext* context, ExtensionPrefs* prefs) {
34 Associate(context, prefs);
35 }
36
ExtensionPrefsFactory()37 ExtensionPrefsFactory::ExtensionPrefsFactory()
38 : BrowserContextKeyedServiceFactory(
39 "ExtensionPrefs",
40 BrowserContextDependencyManager::GetInstance()) {
41 }
42
~ExtensionPrefsFactory()43 ExtensionPrefsFactory::~ExtensionPrefsFactory() {
44 }
45
BuildServiceInstanceFor(content::BrowserContext * context) const46 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));
56 }
57
GetBrowserContextToUse(content::BrowserContext * context) const58 content::BrowserContext* ExtensionPrefsFactory::GetBrowserContextToUse(
59 content::BrowserContext* context) const {
60 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
61 }
62
63 } // namespace extensions
64