• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 "components/keyed_service/content/browser_context_dependency_manager.h"
8 #include "content/public/browser/browser_context.h"
9 #include "extensions/browser/extension_pref_value_map.h"
10 #include "extensions/browser/extension_pref_value_map_factory.h"
11 #include "extensions/browser/extension_prefs.h"
12 #include "extensions/browser/extension_prefs_factory.h"
13 #include "extensions/browser/extensions_browser_client.h"
14 #include "extensions/common/constants.h"
15 
16 namespace extensions {
17 
18 // static
GetForBrowserContext(content::BrowserContext * context)19 ExtensionPrefs* ExtensionPrefsFactory::GetForBrowserContext(
20     content::BrowserContext* context) {
21   return static_cast<ExtensionPrefs*>(
22       GetInstance()->GetServiceForBrowserContext(context, true));
23 }
24 
25 // static
GetInstance()26 ExtensionPrefsFactory* ExtensionPrefsFactory::GetInstance() {
27   return Singleton<ExtensionPrefsFactory>::get();
28 }
29 
SetInstanceForTesting(content::BrowserContext * context,ExtensionPrefs * prefs)30 void ExtensionPrefsFactory::SetInstanceForTesting(
31     content::BrowserContext* context, ExtensionPrefs* prefs) {
32   Associate(context, prefs);
33 }
34 
ExtensionPrefsFactory()35 ExtensionPrefsFactory::ExtensionPrefsFactory()
36     : BrowserContextKeyedServiceFactory(
37           "ExtensionPrefs",
38           BrowserContextDependencyManager::GetInstance()) {
39 }
40 
~ExtensionPrefsFactory()41 ExtensionPrefsFactory::~ExtensionPrefsFactory() {
42 }
43 
BuildServiceInstanceFor(content::BrowserContext * context) const44 KeyedService* ExtensionPrefsFactory::BuildServiceInstanceFor(
45     content::BrowserContext* context) const {
46   ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get();
47   std::vector<ExtensionPrefsObserver*> prefs_observers;
48   client->GetEarlyExtensionPrefsObservers(context, &prefs_observers);
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(*CommandLine::ForCurrentProcess(), context),
55       prefs_observers);
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