OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/platform_keys/platform_keys.h" | 5 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
19 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h" | 19 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h" |
20 #include "chrome/browser/net/nss_context.h" | 20 #include "chrome/browser/net/cert_database_service_factory.h" |
21 #include "components/cert_database/public/cert_database_service.h" | |
22 #include "components/cert_database/public/cert_database_service_io_part.h" | |
21 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
23 #include "crypto/rsa_private_key.h" | 25 #include "crypto/rsa_private_key.h" |
24 #include "net/base/crypto_module.h" | 26 #include "net/base/crypto_module.h" |
25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
26 #include "net/cert/cert_database.h" | 28 #include "net/cert/cert_database.h" |
27 #include "net/cert/nss_cert_database.h" | 29 #include "net/cert/nss_cert_database.h" |
28 #include "net/cert/x509_certificate.h" | 30 #include "net/cert/x509_certificate.h" |
29 | 31 |
30 using content::BrowserContext; | 32 using content::BrowserContext; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 if (!state->slot_) { | 98 if (!state->slot_) { |
97 LOG(ERROR) << "Slot for token id '" << token_id << "' not available."; | 99 LOG(ERROR) << "Slot for token id '" << token_id << "' not available."; |
98 state->OnError(FROM_HERE, kErrorInternal); | 100 state->OnError(FROM_HERE, kErrorInternal); |
99 return; | 101 return; |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 callback.Run(cert_db); | 105 callback.Run(cert_db); |
104 } | 106 } |
105 | 107 |
106 // Retrieves the NSSCertDatabase from |context| and, if |token_id| is not empty, | 108 // Retrieves the NSSCertDatabase from |db_io_part| and, if |token_id| is not |
107 // the slot for |token_id|. | 109 // empty, the slot for |token_id|. |
108 // Must be called on the IO thread. | 110 // Must be called on the IO thread. |
109 void GetCertDatabaseOnIOThread(const std::string& token_id, | 111 void GetCertDatabaseOnIOThread( |
110 const GetCertDBCallback& callback, | 112 const std::string& token_id, |
111 content::ResourceContext* context, | 113 const GetCertDBCallback& callback, |
112 NSSOperationState* state) { | 114 const base::WeakPtr<cert_database::CertDatabaseServiceIOPart>& db_io_part, |
115 NSSOperationState* state) { | |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
stevenjb
2014/10/29 18:43:51
nit: DCHECK(state) since we pass state to other me
pneubeck (no reviews)
2014/11/05 14:53:36
Done.
| |
114 net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext( | 117 if (!db_io_part) { |
115 context, base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state)); | 118 LOG(ERROR) << "CertDatabase shutdown."; |
119 state->OnError(FROM_HERE, kErrorInternal); | |
120 return; | |
121 } | |
122 net::NSSCertDatabase* cert_db = db_io_part->GetNSSCertDatabase( | |
123 base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state)); | |
116 | 124 |
117 if (cert_db) | 125 if (cert_db) |
118 DidGetCertDBOnIOThread(token_id, callback, state, cert_db); | 126 DidGetCertDBOnIOThread(token_id, callback, state, cert_db); |
119 } | 127 } |
120 | 128 |
121 // Asynchronously fetches the NSSCertDatabase for |browser_context| and, if | 129 // Asynchronously fetches the NSSCertDatabase for |browser_context| and, if |
122 // |token_id| is not empty, the slot for |token_id|. Stores the slot in |state| | 130 // |token_id| is not empty, the slot for |token_id|. Stores the slot in |state| |
123 // and passes the database to |callback|. Will run |callback| on the IO thread. | 131 // and passes the database to |callback|. Will run |callback| on the IO thread. |
124 void GetCertDatabase(const std::string& token_id, | 132 void GetCertDatabase(const std::string& token_id, |
125 const GetCertDBCallback& callback, | 133 const GetCertDBCallback& callback, |
126 BrowserContext* browser_context, | 134 BrowserContext* browser_context, |
127 NSSOperationState* state) { | 135 NSSOperationState* state) { |
136 // TODO(pneubeck): Pass in the CertDatabaseService instead of the | |
137 // BrowserContext. | |
138 cert_database::CertDatabaseService* cert_db_service = | |
139 cert_database::CertDatabaseServiceFactory::GetForBrowserContext( | |
140 browser_context); | |
128 BrowserThread::PostTask(BrowserThread::IO, | 141 BrowserThread::PostTask(BrowserThread::IO, |
129 FROM_HERE, | 142 FROM_HERE, |
130 base::Bind(&GetCertDatabaseOnIOThread, | 143 base::Bind(&GetCertDatabaseOnIOThread, |
131 token_id, | 144 token_id, |
132 callback, | 145 callback, |
133 browser_context->GetResourceContext(), | 146 cert_db_service->GetIOPart(), |
134 state)); | 147 state)); |
135 } | 148 } |
136 | 149 |
137 class GenerateRSAKeyState : public NSSOperationState { | 150 class GenerateRSAKeyState : public NSSOperationState { |
138 public: | 151 public: |
139 GenerateRSAKeyState(unsigned int modulus_length_bits, | 152 GenerateRSAKeyState(unsigned int modulus_length_bits, |
140 const subtle::GenerateKeyCallback& callback); | 153 const subtle::GenerateKeyCallback& callback); |
141 virtual ~GenerateRSAKeyState() {} | 154 virtual ~GenerateRSAKeyState() {} |
142 | 155 |
143 virtual void OnError(const tracked_objects::Location& from, | 156 virtual void OnError(const tracked_objects::Location& from, |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 NSSOperationState* state_ptr = state.get(); | 669 NSSOperationState* state_ptr = state.get(); |
657 GetCertDatabase(std::string() /* don't get any specific slot */, | 670 GetCertDatabase(std::string() /* don't get any specific slot */, |
658 base::Bind(&GetTokensWithDB, base::Passed(&state)), | 671 base::Bind(&GetTokensWithDB, base::Passed(&state)), |
659 browser_context, | 672 browser_context, |
660 state_ptr); | 673 state_ptr); |
661 } | 674 } |
662 | 675 |
663 } // namespace platform_keys | 676 } // namespace platform_keys |
664 | 677 |
665 } // namespace chromeos | 678 } // namespace chromeos |
OLD | NEW |