| Index: chrome/browser/net/nss_slot_factory.cc
|
| diff --git a/chrome/browser/net/nss_slot_factory.cc b/chrome/browser/net/nss_slot_factory.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a811c5f6c2c84331a97b73edafb0eda1264758d5
|
| --- /dev/null
|
| +++ b/chrome/browser/net/nss_slot_factory.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 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 "chrome/browser/net/nss_slot_factory.h"
|
| +
|
| +#include "chrome/browser/profiles/incognito_helpers.h"
|
| +#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
|
| +#include "crypto/nss_util_internal.h"
|
| +
|
| +namespace {
|
| +
|
| +class NSSSlotService : public BrowserContextKeyedService {
|
| + public:
|
| + explicit NSSSlotService(content::BrowserContext* context);
|
| +
|
| + crypto::ScopedPK11Slot GetPublicNSSKeySlot();
|
| + crypto::ScopedPK11Slot GetPrivateNSSKeySlot();
|
| +
|
| + private:
|
| + crypto::ScopedPK11Slot public_slot_;
|
| + crypto::ScopedPK11Slot private_slot_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NSSSlotService);
|
| +};
|
| +
|
| +NSSSlotService::NSSSlotService(content::BrowserContext* context) {
|
| + // TODO: #ifdef OS_CHROMEOS
|
| + // load public slot using context->GetPath().
|
| + // load private slot using ??? (dbus call to cryptohomed?)
|
| + // #else
|
| + public_slot_.reset(crypto::GetPublicNSSKeySlot());
|
| + private_slot_.reset(crypto::GetPrivateNSSKeySlot());
|
| +}
|
| +
|
| +crypto::ScopedPK11Slot NSSSlotService::GetPublicNSSKeySlot() {
|
| + return crypto::ScopedPK11Slot(PK11_ReferenceSlot(public_slot_.get()));
|
| +}
|
| +
|
| +crypto::ScopedPK11Slot NSSSlotService::GetPrivateNSSKeySlot() {
|
| + return crypto::ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get()));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +crypto::ScopedPK11Slot NSSSlotFactory::GetPublicSlotForBrowserContext(
|
| + content::BrowserContext* context) {
|
| + NSSSlotService* service = static_cast<NSSSlotService*>(
|
| + GetInstance()->GetServiceForBrowserContext(context, true));
|
| + return service->GetPublicNSSKeySlot();
|
| +}
|
| +
|
| +// static
|
| +crypto::ScopedPK11Slot NSSSlotFactory::GetPrivateSlotForBrowserContext(
|
| + content::BrowserContext* context) {
|
| + NSSSlotService* service = static_cast<NSSSlotService*>(
|
| + GetInstance()->GetServiceForBrowserContext(context, true));
|
| + return service->GetPrivateNSSKeySlot();
|
| +}
|
| +
|
| +// static
|
| +NSSSlotFactory* NSSSlotFactory::GetInstance() {
|
| + return Singleton<NSSSlotFactory>::get();
|
| +}
|
| +
|
| +BrowserContextKeyedService* NSSSlotFactory::BuildServiceInstanceFor(
|
| + content::BrowserContext* context) const {
|
| + NSSSlotService* service = new NSSSlotService(context);
|
| +
|
| + return service;
|
| +}
|
| +
|
| +content::BrowserContext* NSSSlotFactory::GetBrowserContextToUse(
|
| + content::BrowserContext* context) const {
|
| + return chrome::GetBrowserContextRedirectedInIncognito(context);
|
| +}
|
| +
|
| +NSSSlotFactory::NSSSlotFactory()
|
| + : BrowserContextKeyedServiceFactory(
|
| + "NSSSlotService",
|
| + BrowserContextDependencyManager::GetInstance()) {
|
| +}
|
| +
|
| +NSSSlotFactory::~NSSSlotFactory() {
|
| +}
|
|
|