OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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/ui/crypto_module_delegate_nss.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/bind.h" | |
9 #include "chrome/browser/net/nss_context.h" | |
10 #include "content/public/browser/browser_thread.h" | |
11 | |
12 using content::BrowserThread; | |
13 | |
14 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( | |
15 chrome::CryptoModulePasswordReason reason, | |
16 const std::string& server) | |
17 : event_(false, false), | |
18 reason_(reason), | |
19 server_(server), | |
20 cancelled_(false) {} | |
21 | |
22 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} | |
23 | |
24 bool ChromeNSSCryptoModuleDelegate::InitializeSlot( | |
25 content::ResourceContext* context, | |
26 const base::Closure& initialization_complete_callback) { | |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
28 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback; | |
29 if (!initialization_complete_callback.is_null()) | |
30 get_slot_callback = base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot, | |
31 base::Unretained(this), | |
32 initialization_complete_callback); | |
33 | |
34 slot_ = GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); | |
35 return slot_ != NULL; | |
Ryan Sleevi
2013/12/05 00:23:19
"slot_.get() != NULL" or simply "return slot_"
mattm
2013/12/05 04:41:25
done
| |
36 } | |
37 | |
38 // TODO(mattm): allow choosing which slot to generate and store the key. | |
39 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { | |
40 return slot_.Pass(); | |
41 } | |
42 | |
43 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( | |
44 const std::string& slot_name, | |
45 bool retry, | |
46 bool* cancelled) { | |
47 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Ryan Sleevi
2013/12/05 00:23:19
Is this necessary, given that event_.Wait() will c
mattm
2013/12/05 04:41:25
Good point. done.
| |
48 DCHECK(!event_.IsSignaled()); | |
49 event_.Reset(); | |
50 | |
51 if (BrowserThread::PostTask( | |
52 BrowserThread::UI, | |
53 FROM_HERE, | |
54 base::Bind(&ChromeNSSCryptoModuleDelegate::ShowDialog, | |
55 // We block on event_ until the task completes, so | |
56 // there's no need to ref-count. | |
Ryan Sleevi
2013/12/05 00:23:19
comment nit: pronouns
mattm
2013/12/05 04:41:25
Done.
| |
57 base::Unretained(this), | |
58 slot_name, | |
59 retry))) { | |
60 event_.Wait(); | |
61 } | |
62 *cancelled = cancelled_; | |
63 return password_; | |
64 } | |
65 | |
66 void ChromeNSSCryptoModuleDelegate::ShowDialog(const std::string& slot_name, | |
67 bool retry) { | |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
69 ShowCryptoModulePasswordDialog( | |
70 slot_name, | |
71 retry, | |
72 reason_, | |
73 server_, | |
74 NULL, // TODO(mattm): Supply parent window. | |
75 base::Bind(&ChromeNSSCryptoModuleDelegate::GotPassword, | |
76 // We block on event_ until the task completes, so | |
77 // there's no need to ref-count. | |
78 base::Unretained(this))); | |
79 } | |
80 | |
81 void ChromeNSSCryptoModuleDelegate::GotPassword(const char* password) { | |
82 if (password) | |
83 password_ = password; | |
84 else | |
85 cancelled_ = true; | |
86 event_.Signal(); | |
87 } | |
88 | |
89 void ChromeNSSCryptoModuleDelegate::DidGetSlot(const base::Closure& callback, | |
90 crypto::ScopedPK11Slot slot) { | |
91 slot_ = slot.Pass(); | |
92 callback.Run(); | |
93 } | |
94 | |
95 namespace chrome { | |
96 | |
97 crypto::CryptoModuleBlockingPasswordDelegate* | |
98 CreateCryptoModuleBlockingPasswordDelegate(CryptoModulePasswordReason reason, | |
99 const std::string& server) { | |
100 // Returns a ChromeNSSCryptoModuleDelegate without calling InitializeSlot. | |
101 // Since it is only being used as a CreateCryptoModuleBlockingDialogDelegate, | |
102 // initializing the slot handle is unnecessary. | |
103 return new ChromeNSSCryptoModuleDelegate(reason, server); | |
104 } | |
105 | |
106 } // namespace chrome | |
OLD | NEW |