1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef CHROME_BROWSER_NET_NSS_CONTEXT_H_ 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define CHROME_BROWSER_NET_NSS_CONTEXT_H_ 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <string> 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/callback.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/compiler_specific.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "crypto/scoped_nss_types.h" 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Profile; 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace net { 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NSSCertDatabase; 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace content { 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class ResourceContext; 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} // namespace content 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Returns a reference to the public slot for the user associated with 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// |context|. Should be called only on the IO thread. 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)crypto::ScopedPK11Slot GetPublicNSSKeySlotForResourceContext( 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) content::ResourceContext* context); 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Returns a reference to the private slot for the user associated with 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// |context|, if it is loaded. If it is not loaded and |callback| is non-null, 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the |callback| will be run once the slot is loaded. 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Should be called only on the IO thread. 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)crypto::ScopedPK11Slot GetPrivateNSSKeySlotForResourceContext( 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) content::ResourceContext* context, 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::Callback<void(crypto::ScopedPK11Slot)>& callback) 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) WARN_UNUSED_RESULT; 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns a pointer to the NSSCertDatabase for the user associated with 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// |context|, if it is ready. If it is not ready and |callback| is non-null, the 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// |callback| will be run once the DB is initialized. Ownership is not 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// transferred, but the caller may save the pointer, which will remain valid for 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the lifetime of the ResourceContext. 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Must be called only on the IO thread. 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext( 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::ResourceContext* context, 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Callback<void(net::NSSCertDatabase*)>& callback) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WARN_UNUSED_RESULT; 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_CHROMEOS) 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Enables the system key slot in the NSSCertDatabase for the user associated 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// with |context|. 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Must be called only on the IO thread. 535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void EnableNSSSystemKeySlotForResourceContext( 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) content::ResourceContext* context); 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Gets a pointer to the NSSCertDatabase for the user associated with |context|. 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It's a wrapper around |GetNSSCertDatabaseForResourceContext| which makes 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// sure it's called on IO thread (with |profile|'s resource context). The 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// callback will be called on the originating message loop. 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It's accessing profile, so it should be called on the UI thread. 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GetNSSCertDatabaseForProfile( 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Callback<void(net::NSSCertDatabase*)>& callback); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // CHROME_BROWSER_NET_NSS_CONTEXT_H_ 67