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 |