Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Unified Diff: chrome/browser/net/nss_slot_factory.cc

Issue 18121007: *WIP* Store NSS slots per profile. Move keygen to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8743877f1bb64970ecfed832f09fb77aeb04045d
--- /dev/null
+++ b/chrome/browser/net/nss_slot_factory.cc
@@ -0,0 +1,91 @@
+// 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"
+
+// XXX:
+#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 chrome {
+
+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() {
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698