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

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys_nss.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Flattened components/cert_database folders. Created 6 years, 1 month 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 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/cert_database_service.h"
22 #include "components/cert_database/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
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));
114 net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext( 117 DCHECK(state);
115 context, base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state)); 118 if (!db_io_part) {
119 LOG(ERROR) << "CertDatabase shutdown.";
120 state->OnError(FROM_HERE, kErrorInternal);
121 return;
122 }
123 net::NSSCertDatabase* cert_db = db_io_part->GetNSSCertDatabase(
124 base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state));
116 125
117 if (cert_db) 126 if (cert_db)
118 DidGetCertDBOnIOThread(token_id, callback, state, cert_db); 127 DidGetCertDBOnIOThread(token_id, callback, state, cert_db);
119 } 128 }
120 129
121 // Asynchronously fetches the NSSCertDatabase for |browser_context| and, if 130 // 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| 131 // |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. 132 // and passes the database to |callback|. Will run |callback| on the IO thread.
124 void GetCertDatabase(const std::string& token_id, 133 void GetCertDatabase(const std::string& token_id,
125 const GetCertDBCallback& callback, 134 const GetCertDBCallback& callback,
126 BrowserContext* browser_context, 135 BrowserContext* browser_context,
127 NSSOperationState* state) { 136 NSSOperationState* state) {
137 DCHECK(state);
138 // TODO(pneubeck): Pass in the CertDatabaseService instead of the
139 // BrowserContext.
140 cert_database::CertDatabaseService* cert_db_service =
141 cert_database::CertDatabaseServiceFactory::GetForBrowserContext(
142 browser_context);
128 BrowserThread::PostTask(BrowserThread::IO, 143 BrowserThread::PostTask(BrowserThread::IO,
129 FROM_HERE, 144 FROM_HERE,
130 base::Bind(&GetCertDatabaseOnIOThread, 145 base::Bind(&GetCertDatabaseOnIOThread,
131 token_id, 146 token_id,
132 callback, 147 callback,
133 browser_context->GetResourceContext(), 148 cert_db_service->GetIOPart(),
134 state)); 149 state));
135 } 150 }
136 151
137 class GenerateRSAKeyState : public NSSOperationState { 152 class GenerateRSAKeyState : public NSSOperationState {
138 public: 153 public:
139 GenerateRSAKeyState(unsigned int modulus_length_bits, 154 GenerateRSAKeyState(unsigned int modulus_length_bits,
140 const subtle::GenerateKeyCallback& callback); 155 const subtle::GenerateKeyCallback& callback);
141 virtual ~GenerateRSAKeyState() {} 156 virtual ~GenerateRSAKeyState() {}
142 157
143 virtual void OnError(const tracked_objects::Location& from, 158 virtual void OnError(const tracked_objects::Location& from,
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 NSSOperationState* state_ptr = state.get(); 671 NSSOperationState* state_ptr = state.get();
657 GetCertDatabase(std::string() /* don't get any specific slot */, 672 GetCertDatabase(std::string() /* don't get any specific slot */,
658 base::Bind(&GetTokensWithDB, base::Passed(&state)), 673 base::Bind(&GetTokensWithDB, base::Passed(&state)),
659 browser_context, 674 browser_context,
660 state_ptr); 675 state_ptr);
661 } 676 }
662 677
663 } // namespace platform_keys 678 } // namespace platform_keys
664 679
665 } // namespace chromeos 680 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698