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

Side by Side Diff: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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
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/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h" 5 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 EnterprisePlatformKeysInternalGenerateKeyFunction:: 44 EnterprisePlatformKeysInternalGenerateKeyFunction::
45 ~EnterprisePlatformKeysInternalGenerateKeyFunction() { 45 ~EnterprisePlatformKeysInternalGenerateKeyFunction() {
46 } 46 }
47 47
48 ExtensionFunction::ResponseAction 48 ExtensionFunction::ResponseAction
49 EnterprisePlatformKeysInternalGenerateKeyFunction::Run() { 49 EnterprisePlatformKeysInternalGenerateKeyFunction::Run() {
50 scoped_ptr<api_epki::GenerateKey::Params> params( 50 std::unique_ptr<api_epki::GenerateKey::Params> params(
51 api_epki::GenerateKey::Params::Create(*args_)); 51 api_epki::GenerateKey::Params::Create(*args_));
52 // TODO(pneubeck): Add support for unsigned integers to IDL. 52 // TODO(pneubeck): Add support for unsigned integers to IDL.
53 EXTENSION_FUNCTION_VALIDATE(params && params->modulus_length >= 0); 53 EXTENSION_FUNCTION_VALIDATE(params && params->modulus_length >= 0);
54 std::string platform_keys_token_id; 54 std::string platform_keys_token_id;
55 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) 55 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id))
56 return RespondNow(Error(platform_keys::kErrorInvalidToken)); 56 return RespondNow(Error(platform_keys::kErrorInvalidToken));
57 57
58 chromeos::PlatformKeysService* service = 58 chromeos::PlatformKeysService* service =
59 chromeos::PlatformKeysServiceFactory::GetForBrowserContext( 59 chromeos::PlatformKeysServiceFactory::GetForBrowserContext(
60 browser_context()); 60 browser_context());
(...skipping 20 matching lines...) Expand all
81 Respond(Error(error_message)); 81 Respond(Error(error_message));
82 } 82 }
83 } 83 }
84 84
85 EnterprisePlatformKeysGetCertificatesFunction:: 85 EnterprisePlatformKeysGetCertificatesFunction::
86 ~EnterprisePlatformKeysGetCertificatesFunction() { 86 ~EnterprisePlatformKeysGetCertificatesFunction() {
87 } 87 }
88 88
89 ExtensionFunction::ResponseAction 89 ExtensionFunction::ResponseAction
90 EnterprisePlatformKeysGetCertificatesFunction::Run() { 90 EnterprisePlatformKeysGetCertificatesFunction::Run() {
91 scoped_ptr<api_epk::GetCertificates::Params> params( 91 std::unique_ptr<api_epk::GetCertificates::Params> params(
92 api_epk::GetCertificates::Params::Create(*args_)); 92 api_epk::GetCertificates::Params::Create(*args_));
93 EXTENSION_FUNCTION_VALIDATE(params); 93 EXTENSION_FUNCTION_VALIDATE(params);
94 std::string platform_keys_token_id; 94 std::string platform_keys_token_id;
95 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) 95 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id))
96 return RespondNow(Error(platform_keys::kErrorInvalidToken)); 96 return RespondNow(Error(platform_keys::kErrorInvalidToken));
97 97
98 chromeos::platform_keys::GetCertificates( 98 chromeos::platform_keys::GetCertificates(
99 platform_keys_token_id, 99 platform_keys_token_id,
100 base::Bind( 100 base::Bind(
101 &EnterprisePlatformKeysGetCertificatesFunction::OnGotCertificates, 101 &EnterprisePlatformKeysGetCertificatesFunction::OnGotCertificates,
102 this), 102 this),
103 browser_context()); 103 browser_context());
104 return RespondLater(); 104 return RespondLater();
105 } 105 }
106 106
107 void EnterprisePlatformKeysGetCertificatesFunction::OnGotCertificates( 107 void EnterprisePlatformKeysGetCertificatesFunction::OnGotCertificates(
108 scoped_ptr<net::CertificateList> certs, 108 std::unique_ptr<net::CertificateList> certs,
109 const std::string& error_message) { 109 const std::string& error_message) {
110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
111 if (!error_message.empty()) { 111 if (!error_message.empty()) {
112 Respond(Error(error_message)); 112 Respond(Error(error_message));
113 return; 113 return;
114 } 114 }
115 115
116 scoped_ptr<base::ListValue> client_certs(new base::ListValue()); 116 std::unique_ptr<base::ListValue> client_certs(new base::ListValue());
117 for (net::CertificateList::const_iterator it = certs->begin(); 117 for (net::CertificateList::const_iterator it = certs->begin();
118 it != certs->end(); 118 it != certs->end();
119 ++it) { 119 ++it) {
120 std::string der_encoding; 120 std::string der_encoding;
121 net::X509Certificate::GetDEREncoded((*it)->os_cert_handle(), &der_encoding); 121 net::X509Certificate::GetDEREncoded((*it)->os_cert_handle(), &der_encoding);
122 client_certs->Append(base::BinaryValue::CreateWithCopiedBuffer( 122 client_certs->Append(base::BinaryValue::CreateWithCopiedBuffer(
123 der_encoding.data(), der_encoding.size())); 123 der_encoding.data(), der_encoding.size()));
124 } 124 }
125 125
126 scoped_ptr<base::ListValue> results(new base::ListValue()); 126 std::unique_ptr<base::ListValue> results(new base::ListValue());
127 results->Append(client_certs.release()); 127 results->Append(client_certs.release());
128 Respond(ArgumentList(std::move(results))); 128 Respond(ArgumentList(std::move(results)));
129 } 129 }
130 130
131 EnterprisePlatformKeysImportCertificateFunction:: 131 EnterprisePlatformKeysImportCertificateFunction::
132 ~EnterprisePlatformKeysImportCertificateFunction() { 132 ~EnterprisePlatformKeysImportCertificateFunction() {
133 } 133 }
134 134
135 ExtensionFunction::ResponseAction 135 ExtensionFunction::ResponseAction
136 EnterprisePlatformKeysImportCertificateFunction::Run() { 136 EnterprisePlatformKeysImportCertificateFunction::Run() {
137 scoped_ptr<api_epk::ImportCertificate::Params> params( 137 std::unique_ptr<api_epk::ImportCertificate::Params> params(
138 api_epk::ImportCertificate::Params::Create(*args_)); 138 api_epk::ImportCertificate::Params::Create(*args_));
139 EXTENSION_FUNCTION_VALIDATE(params); 139 EXTENSION_FUNCTION_VALIDATE(params);
140 std::string platform_keys_token_id; 140 std::string platform_keys_token_id;
141 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) 141 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id))
142 return RespondNow(Error(platform_keys::kErrorInvalidToken)); 142 return RespondNow(Error(platform_keys::kErrorInvalidToken));
143 143
144 const std::vector<char>& cert_der = params->certificate; 144 const std::vector<char>& cert_der = params->certificate;
145 scoped_refptr<net::X509Certificate> cert_x509 = 145 scoped_refptr<net::X509Certificate> cert_x509 =
146 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); 146 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size());
147 if (!cert_x509.get()) 147 if (!cert_x509.get())
(...skipping 17 matching lines...) Expand all
165 else 165 else
166 Respond(Error(error_message)); 166 Respond(Error(error_message));
167 } 167 }
168 168
169 EnterprisePlatformKeysRemoveCertificateFunction:: 169 EnterprisePlatformKeysRemoveCertificateFunction::
170 ~EnterprisePlatformKeysRemoveCertificateFunction() { 170 ~EnterprisePlatformKeysRemoveCertificateFunction() {
171 } 171 }
172 172
173 ExtensionFunction::ResponseAction 173 ExtensionFunction::ResponseAction
174 EnterprisePlatformKeysRemoveCertificateFunction::Run() { 174 EnterprisePlatformKeysRemoveCertificateFunction::Run() {
175 scoped_ptr<api_epk::RemoveCertificate::Params> params( 175 std::unique_ptr<api_epk::RemoveCertificate::Params> params(
176 api_epk::RemoveCertificate::Params::Create(*args_)); 176 api_epk::RemoveCertificate::Params::Create(*args_));
177 EXTENSION_FUNCTION_VALIDATE(params); 177 EXTENSION_FUNCTION_VALIDATE(params);
178 std::string platform_keys_token_id; 178 std::string platform_keys_token_id;
179 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id)) 179 if (!platform_keys::ValidateToken(params->token_id, &platform_keys_token_id))
180 return RespondNow(Error(platform_keys::kErrorInvalidToken)); 180 return RespondNow(Error(platform_keys::kErrorInvalidToken));
181 181
182 const std::vector<char>& cert_der = params->certificate; 182 const std::vector<char>& cert_der = params->certificate;
183 scoped_refptr<net::X509Certificate> cert_x509 = 183 scoped_refptr<net::X509Certificate> cert_x509 =
184 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); 184 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size());
185 if (!cert_x509.get()) 185 if (!cert_x509.get())
(...skipping 27 matching lines...) Expand all
213 EXTENSION_FUNCTION_VALIDATE(args_->empty()); 213 EXTENSION_FUNCTION_VALIDATE(args_->empty());
214 214
215 chromeos::platform_keys::GetTokens( 215 chromeos::platform_keys::GetTokens(
216 base::Bind(&EnterprisePlatformKeysInternalGetTokensFunction::OnGotTokens, 216 base::Bind(&EnterprisePlatformKeysInternalGetTokensFunction::OnGotTokens,
217 this), 217 this),
218 browser_context()); 218 browser_context());
219 return RespondLater(); 219 return RespondLater();
220 } 220 }
221 221
222 void EnterprisePlatformKeysInternalGetTokensFunction::OnGotTokens( 222 void EnterprisePlatformKeysInternalGetTokensFunction::OnGotTokens(
223 scoped_ptr<std::vector<std::string> > platform_keys_token_ids, 223 std::unique_ptr<std::vector<std::string>> platform_keys_token_ids,
224 const std::string& error_message) { 224 const std::string& error_message) {
225 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 225 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
226 if (!error_message.empty()) { 226 if (!error_message.empty()) {
227 Respond(Error(error_message)); 227 Respond(Error(error_message));
228 return; 228 return;
229 } 229 }
230 230
231 std::vector<std::string> token_ids; 231 std::vector<std::string> token_ids;
232 for (std::vector<std::string>::const_iterator it = 232 for (std::vector<std::string>::const_iterator it =
233 platform_keys_token_ids->begin(); 233 platform_keys_token_ids->begin();
(...skipping 17 matching lines...) Expand all
251 EnterprisePlatformKeysChallengeMachineKeyFunction:: 251 EnterprisePlatformKeysChallengeMachineKeyFunction::
252 EnterprisePlatformKeysChallengeMachineKeyFunction( 252 EnterprisePlatformKeysChallengeMachineKeyFunction(
253 EPKPChallengeMachineKey* impl_for_testing) 253 EPKPChallengeMachineKey* impl_for_testing)
254 : impl_(impl_for_testing) {} 254 : impl_(impl_for_testing) {}
255 255
256 EnterprisePlatformKeysChallengeMachineKeyFunction:: 256 EnterprisePlatformKeysChallengeMachineKeyFunction::
257 ~EnterprisePlatformKeysChallengeMachineKeyFunction() = default; 257 ~EnterprisePlatformKeysChallengeMachineKeyFunction() = default;
258 258
259 ExtensionFunction::ResponseAction 259 ExtensionFunction::ResponseAction
260 EnterprisePlatformKeysChallengeMachineKeyFunction::Run() { 260 EnterprisePlatformKeysChallengeMachineKeyFunction::Run() {
261 scoped_ptr<api_epk::ChallengeMachineKey::Params> params( 261 std::unique_ptr<api_epk::ChallengeMachineKey::Params> params(
262 api_epk::ChallengeMachineKey::Params::Create(*args_)); 262 api_epk::ChallengeMachineKey::Params::Create(*args_));
263 EXTENSION_FUNCTION_VALIDATE(params); 263 EXTENSION_FUNCTION_VALIDATE(params);
264 ChallengeKeyCallback callback = base::Bind( 264 ChallengeKeyCallback callback = base::Bind(
265 &EnterprisePlatformKeysChallengeMachineKeyFunction::OnChallengedKey, 265 &EnterprisePlatformKeysChallengeMachineKeyFunction::OnChallengedKey,
266 this); 266 this);
267 // base::Unretained is safe on impl_ since its life-cycle matches |this| and 267 // base::Unretained is safe on impl_ since its life-cycle matches |this| and
268 // |callback| holds a reference to |this|. 268 // |callback| holds a reference to |this|.
269 base::Closure task = base::Bind( 269 base::Closure task = base::Bind(
270 &EPKPChallengeMachineKey::Run, base::Unretained(impl_), 270 &EPKPChallengeMachineKey::Run, base::Unretained(impl_),
271 scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()), 271 scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()),
(...skipping 20 matching lines...) Expand all
292 EnterprisePlatformKeysChallengeUserKeyFunction:: 292 EnterprisePlatformKeysChallengeUserKeyFunction::
293 EnterprisePlatformKeysChallengeUserKeyFunction( 293 EnterprisePlatformKeysChallengeUserKeyFunction(
294 EPKPChallengeUserKey* impl_for_testing) 294 EPKPChallengeUserKey* impl_for_testing)
295 : impl_(impl_for_testing) {} 295 : impl_(impl_for_testing) {}
296 296
297 EnterprisePlatformKeysChallengeUserKeyFunction:: 297 EnterprisePlatformKeysChallengeUserKeyFunction::
298 ~EnterprisePlatformKeysChallengeUserKeyFunction() = default; 298 ~EnterprisePlatformKeysChallengeUserKeyFunction() = default;
299 299
300 ExtensionFunction::ResponseAction 300 ExtensionFunction::ResponseAction
301 EnterprisePlatformKeysChallengeUserKeyFunction::Run() { 301 EnterprisePlatformKeysChallengeUserKeyFunction::Run() {
302 scoped_ptr<api_epk::ChallengeUserKey::Params> params( 302 std::unique_ptr<api_epk::ChallengeUserKey::Params> params(
303 api_epk::ChallengeUserKey::Params::Create(*args_)); 303 api_epk::ChallengeUserKey::Params::Create(*args_));
304 EXTENSION_FUNCTION_VALIDATE(params); 304 EXTENSION_FUNCTION_VALIDATE(params);
305 ChallengeKeyCallback callback = base::Bind( 305 ChallengeKeyCallback callback = base::Bind(
306 &EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey, this); 306 &EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey, this);
307 // base::Unretained is safe on impl_ since its life-cycle matches |this| and 307 // base::Unretained is safe on impl_ since its life-cycle matches |this| and
308 // |callback| holds a reference to |this|. 308 // |callback| holds a reference to |this|.
309 base::Closure task = base::Bind( 309 base::Closure task = base::Bind(
310 &EPKPChallengeUserKey::Run, base::Unretained(impl_), 310 &EPKPChallengeUserKey::Run, base::Unretained(impl_),
311 scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()), 311 scoped_refptr<UIThreadExtensionFunction>(AsUIThreadExtensionFunction()),
312 callback, StringFromVector(params->challenge), params->register_key); 312 callback, StringFromVector(params->challenge), params->register_key);
313 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, task); 313 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, task);
314 return RespondLater(); 314 return RespondLater();
315 } 315 }
316 316
317 void EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey( 317 void EnterprisePlatformKeysChallengeUserKeyFunction::OnChallengedKey(
318 bool success, 318 bool success,
319 const std::string& data) { 319 const std::string& data) {
320 if (success) { 320 if (success) {
321 Respond(ArgumentList( 321 Respond(ArgumentList(
322 api_epk::ChallengeUserKey::Results::Create(VectorFromString(data)))); 322 api_epk::ChallengeUserKey::Results::Create(VectorFromString(data))));
323 } else { 323 } else {
324 Respond(Error(data)); 324 Respond(Error(data));
325 } 325 }
326 } 326 }
327 327
328 } // namespace extensions 328 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698