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

Side by Side Diff: chrome/browser/ui/crypto_module_delegate_nss.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, format. Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/crypto_module_delegate_nss.h" 5 #include "chrome/browser/ui/crypto_module_delegate_nss.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "chrome/browser/net/nss_context.h" 9 #include "base/callback.h"
10 #include "components/cert_database/public/cert_database_service_io_part.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "net/cert/nss_cert_database.h"
11 13
12 using content::BrowserThread; 14 using content::BrowserThread;
13 15
14 namespace { 16 namespace {
15 17
16 void CreateWithSlot(chrome::CryptoModulePasswordReason reason, 18 void CreateWithSlot(chrome::CryptoModulePasswordReason reason,
tbarzic 2014/10/22 20:38:19 nit: I'd rename this. Maybe to CreateWithPrivateSl
pneubeck (no reviews) 2014/10/24 12:51:37 used NSSCertDB to distinguish it from the public f
17 const net::HostPortPair& server, 19 const net::HostPortPair& server,
18 const base::Callback<void( 20 const base::Callback<void(
19 scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& callback, 21 scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& callback,
20 crypto::ScopedPK11Slot slot) { 22 net::NSSCertDatabase* nss_cert_db) {
23 crypto::ScopedPK11Slot slot;
24 if (nss_cert_db)
25 slot = nss_cert_db->GetPrivateSlot();
21 if (!slot) { 26 if (!slot) {
22 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>()); 27 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>());
23 return; 28 return;
24 } 29 }
25 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>( 30 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>(
26 new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass()))); 31 new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass())));
27 } 32 }
28 33
29 } // namespace 34 } // namespace
30 35
31 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( 36 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate(
32 chrome::CryptoModulePasswordReason reason, 37 chrome::CryptoModulePasswordReason reason,
33 const net::HostPortPair& server, 38 const net::HostPortPair& server,
34 crypto::ScopedPK11Slot slot) 39 crypto::ScopedPK11Slot slot)
35 : reason_(reason), 40 : reason_(reason),
36 server_(server), 41 server_(server),
37 event_(false, false), 42 event_(false, false),
38 cancelled_(false), 43 cancelled_(false),
39 slot_(slot.Pass()) { 44 slot_(slot.Pass()) {
40 } 45 }
41 46
42 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} 47 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {}
43 48
44 // static 49 // static
45 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( 50 void ChromeNSSCryptoModuleDelegate::CreateForCertDatabase(
46 chrome::CryptoModulePasswordReason reason, 51 chrome::CryptoModulePasswordReason reason,
47 const net::HostPortPair& server, 52 const net::HostPortPair& server,
48 content::ResourceContext* context, 53 cert_database::CertDatabaseServiceIOPart* cert_db_io,
49 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& 54 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>&
50 callback) { 55 callback) {
51 DCHECK_CURRENTLY_ON(BrowserThread::IO); 56 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52 DCHECK(!callback.is_null()); 57 DCHECK(!callback.is_null());
53 58
54 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = 59 base::Callback<void(net::NSSCertDatabase*)> get_nssdb_callback =
55 base::Bind(&CreateWithSlot, reason, server, callback); 60 base::Bind(&CreateWithSlot, reason, server, callback);
56 61
57 crypto::ScopedPK11Slot slot = 62 net::NSSCertDatabase* nssdb =
58 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); 63 cert_db_io->GetNSSCertDatabase(get_nssdb_callback);
59 if (slot) 64 if (nssdb)
60 get_slot_callback.Run(slot.Pass()); 65 get_nssdb_callback.Run(nssdb);
61 } 66 }
62 67
63 // TODO(mattm): allow choosing which slot to generate and store the key. 68 // TODO(mattm): allow choosing which slot to generate and store the key.
64 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { 69 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() {
65 return slot_.Pass(); 70 return slot_.Pass();
66 } 71 }
67 72
68 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( 73 std::string ChromeNSSCryptoModuleDelegate::RequestPassword(
69 const std::string& slot_name, 74 const std::string& slot_name,
70 bool retry, 75 bool retry,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 crypto::CryptoModuleBlockingPasswordDelegate* 118 crypto::CryptoModuleBlockingPasswordDelegate*
114 CreateCryptoModuleBlockingPasswordDelegate( 119 CreateCryptoModuleBlockingPasswordDelegate(
115 chrome::CryptoModulePasswordReason reason, 120 chrome::CryptoModulePasswordReason reason,
116 const net::HostPortPair& server) { 121 const net::HostPortPair& server) {
117 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only 122 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only
118 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is 123 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is
119 // unnecessary. 124 // unnecessary.
120 return new ChromeNSSCryptoModuleDelegate( 125 return new ChromeNSSCryptoModuleDelegate(
121 reason, server, crypto::ScopedPK11Slot()); 126 reason, server, crypto::ScopedPK11Slot());
122 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698