OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/net/nss_slot_factory.h" |
| 6 |
| 7 #include "chrome/browser/profiles/incognito_helpers.h" |
| 8 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 9 #include "crypto/nss_util_internal.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 class NSSSlotService : public BrowserContextKeyedService { |
| 14 public: |
| 15 explicit NSSSlotService(content::BrowserContext* context); |
| 16 |
| 17 crypto::ScopedPK11Slot GetPublicNSSKeySlot(); |
| 18 crypto::ScopedPK11Slot GetPrivateNSSKeySlot(); |
| 19 |
| 20 private: |
| 21 crypto::ScopedPK11Slot public_slot_; |
| 22 crypto::ScopedPK11Slot private_slot_; |
| 23 |
| 24 DISALLOW_COPY_AND_ASSIGN(NSSSlotService); |
| 25 }; |
| 26 |
| 27 NSSSlotService::NSSSlotService(content::BrowserContext* context) { |
| 28 // TODO: #ifdef OS_CHROMEOS |
| 29 // load public slot using context->GetPath(). |
| 30 // load private slot using ??? (dbus call to cryptohomed?) |
| 31 // #else |
| 32 public_slot_.reset(crypto::GetPublicNSSKeySlot()); |
| 33 private_slot_.reset(crypto::GetPrivateNSSKeySlot()); |
| 34 } |
| 35 |
| 36 crypto::ScopedPK11Slot NSSSlotService::GetPublicNSSKeySlot() { |
| 37 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(public_slot_.get())); |
| 38 } |
| 39 |
| 40 crypto::ScopedPK11Slot NSSSlotService::GetPrivateNSSKeySlot() { |
| 41 return crypto::ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get())); |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 // static |
| 47 crypto::ScopedPK11Slot NSSSlotFactory::GetPublicSlotForBrowserContext( |
| 48 content::BrowserContext* context) { |
| 49 NSSSlotService* service = static_cast<NSSSlotService*>( |
| 50 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 51 return service->GetPublicNSSKeySlot(); |
| 52 } |
| 53 |
| 54 // static |
| 55 crypto::ScopedPK11Slot NSSSlotFactory::GetPrivateSlotForBrowserContext( |
| 56 content::BrowserContext* context) { |
| 57 NSSSlotService* service = static_cast<NSSSlotService*>( |
| 58 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 59 return service->GetPrivateNSSKeySlot(); |
| 60 } |
| 61 |
| 62 // static |
| 63 NSSSlotFactory* NSSSlotFactory::GetInstance() { |
| 64 return Singleton<NSSSlotFactory>::get(); |
| 65 } |
| 66 |
| 67 BrowserContextKeyedService* NSSSlotFactory::BuildServiceInstanceFor( |
| 68 content::BrowserContext* context) const { |
| 69 NSSSlotService* service = new NSSSlotService(context); |
| 70 |
| 71 return service; |
| 72 } |
| 73 |
| 74 content::BrowserContext* NSSSlotFactory::GetBrowserContextToUse( |
| 75 content::BrowserContext* context) const { |
| 76 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 77 } |
| 78 |
| 79 NSSSlotFactory::NSSSlotFactory() |
| 80 : BrowserContextKeyedServiceFactory( |
| 81 "NSSSlotService", |
| 82 BrowserContextDependencyManager::GetInstance()) { |
| 83 } |
| 84 |
| 85 NSSSlotFactory::~NSSSlotFactory() { |
| 86 } |
OLD | NEW |