普通文本  |  48行  |  1.46 KB

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/extension_registry_factory.h"

#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extensions_browser_client.h"

using content::BrowserContext;

namespace extensions {

// static
ExtensionRegistry* ExtensionRegistryFactory::GetForBrowserContext(
    BrowserContext* context) {
  return static_cast<ExtensionRegistry*>(
      GetInstance()->GetServiceForBrowserContext(context, true));
}

// static
ExtensionRegistryFactory* ExtensionRegistryFactory::GetInstance() {
  return Singleton<ExtensionRegistryFactory>::get();
}

ExtensionRegistryFactory::ExtensionRegistryFactory()
    : BrowserContextKeyedServiceFactory(
          "ExtensionRegistry",
          BrowserContextDependencyManager::GetInstance()) {
  // No dependencies on other services.
}

ExtensionRegistryFactory::~ExtensionRegistryFactory() {}

KeyedService* ExtensionRegistryFactory::BuildServiceInstanceFor(
    content::BrowserContext* context) const {
  return new ExtensionRegistry(context);
}

BrowserContext* ExtensionRegistryFactory::GetBrowserContextToUse(
    BrowserContext* context) const {
  // Redirected in incognito.
  return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
}

}  // namespace extensions