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

Unified Diff: content/browser/net/nss_context.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: certdb: handle GetCertTrust and IsUntrusted, failed attempt to handle SetCertTrust Created 7 years, 1 month 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
« no previous file with comments | « content/browser/net/keygen_handler.cc ('k') | content/browser/renderer_host/render_message_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/net/nss_context.cc
diff --git a/content/browser/net/nss_context.cc b/content/browser/net/nss_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d00a45b8e46ac9fb3e80e7a0604d3c7e275fc5b4
--- /dev/null
+++ b/content/browser/net/nss_context.cc
@@ -0,0 +1,97 @@
+// 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 "content/public/browser/nss_context.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_context.h"
+#include "crypto/nss_util_internal.h"
+#include "net/cert/nss_cert_database.h"
+
+#if defined(OS_CHROMEOS)
+#include "net/cert/nss_cert_database_chromeos.h"
+#endif
+
+namespace content {
+
+#if defined(OS_CHROMEOS)
+namespace {
+
+const void* kUserDataKey = &kUserDataKey;
+
+class ChromeOSContextData : public ResourceContext::Data {
+ public:
+ ChromeOSContextData(const std::string username_hash);
+ virtual ~ChromeOSContextData();
+
+ std::string username_hash() const { return username_hash_; }
+
+ private:
+ std::string username_hash_;
+};
+
+ChromeOSContextData::ChromeOSContextData(const std::string username_hash)
+ : username_hash_(username_hash) {}
+ChromeOSContextData::~ChromeOSContextData() {}
+
+} // namespace
+
+void SetChromeOSUserForResourceContext(ResourceContext* context,
+ const std::string username_hash) {
+ DCHECK(!context->GetUserData(kUserDataKey));
+ context->SetUserData(kUserDataKey, new ChromeOSContextData(username_hash));
+}
+
+std::string GetChromeOSUserForResourceContext(ResourceContext* context) {
+ ChromeOSContextData* data = reinterpret_cast<ChromeOSContextData*>(
+ context->GetUserData(kUserDataKey));
+ if (!data)
+ return std::string();
+ return data->username_hash();
+}
+#endif // defined(OS_CHROMEOS)
+
+void OnPrivateNSSKeySlotForResourceContextReady(
+ ResourceContext* context,
+ const base::Callback<void(crypto::ScopedPK11Slot)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+#if defined(OS_CHROMEOS)
+ std::string username_hash = GetChromeOSUserForResourceContext(context);
+ crypto::OnPrivateSlotReadyForChromeOSUser(username_hash, callback);
+#else
+ callback.Run(crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()));
+#endif
+}
+
+void OnNSSKeySlotsForResourceContextReady(
+ ResourceContext* context,
+ const base::Callback<
+ void(crypto::ScopedPK11Slot, crypto::ScopedPK11Slot)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+#if defined(OS_CHROMEOS)
+ std::string username_hash = GetChromeOSUserForResourceContext(context);
+ crypto::OnPrivateSlotReadyForChromeOSUser(
+ username_hash,
+ base::Bind(
+ callback,
+ base::Passed(crypto::GetPublicSlotForChromeOSUser(username_hash))));
+#else
+ callback.Run(crypto::ScopedPK11Slot(crypto::GetPublicNSSKeySlot()),
+ crypto::ScopedPK11Slot(crypto::GetPrivateNSSKeySlot()));
+#endif
+}
+
+void GetNSSCertDatabaseForResourceContext(
+ ResourceContext* context,
+ const base::Callback<void(net::NSSCertDatabase*)>& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+#if defined(OS_CHROMEOS)
+ net::NSSCertDatabaseChromeOS::GetForUser(
+ GetChromeOSUserForResourceContext(context), callback);
+#else
+ callback.Run(NSSCertDatabase::GetInstance());
+#endif
+}
+
+} // namespace content
« no previous file with comments | « content/browser/net/keygen_handler.cc ('k') | content/browser/renderer_host/render_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698