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

Side by Side Diff: chromeos/network/onc/onc_utils.cc

Issue 2000803003: Use std::unique_ptr for base::DictionaryValue and base::ListValue's internal store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix various builds. Created 4 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chromeos/network/onc/onc_utils.h" 5 #include "chromeos/network/onc/onc_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (!field_signature) 231 if (!field_signature)
232 continue; 232 continue;
233 233
234 ExpandStringsInOncObject(*field_signature->value_signature, 234 ExpandStringsInOncObject(*field_signature->value_signature,
235 substitution, inner_object); 235 substitution, inner_object);
236 } 236 }
237 } 237 }
238 238
239 void ExpandStringsInNetworks(const StringSubstitution& substitution, 239 void ExpandStringsInNetworks(const StringSubstitution& substitution,
240 base::ListValue* network_configs) { 240 base::ListValue* network_configs) {
241 for (base::Value* entry : *network_configs) { 241 for (const auto& entry : *network_configs) {
242 base::DictionaryValue* network = nullptr; 242 base::DictionaryValue* network = nullptr;
243 entry->GetAsDictionary(&network); 243 entry->GetAsDictionary(&network);
244 DCHECK(network); 244 DCHECK(network);
245 ExpandStringsInOncObject( 245 ExpandStringsInOncObject(
246 kNetworkConfigurationSignature, substitution, network); 246 kNetworkConfigurationSignature, substitution, network);
247 } 247 }
248 } 248 }
249 249
250 void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature, 250 void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature,
251 base::DictionaryValue* onc_object) { 251 base::DictionaryValue* onc_object) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 LOG(ERROR) << "Unable to base64 decode X509 data: " << pem_encoded; 355 LOG(ERROR) << "Unable to base64 decode X509 data: " << pem_encoded;
356 return std::string(); 356 return std::string();
357 } 357 }
358 } 358 }
359 return decoded; 359 return decoded;
360 } 360 }
361 361
362 CertPEMsByGUIDMap GetServerAndCACertsByGUID( 362 CertPEMsByGUIDMap GetServerAndCACertsByGUID(
363 const base::ListValue& certificates) { 363 const base::ListValue& certificates) {
364 CertPEMsByGUIDMap certs_by_guid; 364 CertPEMsByGUIDMap certs_by_guid;
365 for (const base::Value* entry : certificates) { 365 for (const auto& entry : certificates) {
366 const base::DictionaryValue* cert = nullptr; 366 const base::DictionaryValue* cert = nullptr;
367 entry->GetAsDictionary(&cert); 367 entry->GetAsDictionary(&cert);
368 DCHECK(cert);
danakj 2016/05/24 20:08:35 how about DCHECK the return of GetAsDictionary ins
dcheng 2016/05/24 20:39:02 Done.
368 369
369 std::string guid; 370 std::string guid;
370 cert->GetStringWithoutPathExpansion(certificate::kGUID, &guid); 371 cert->GetStringWithoutPathExpansion(certificate::kGUID, &guid);
371 std::string cert_type; 372 std::string cert_type;
372 cert->GetStringWithoutPathExpansion(certificate::kType, &cert_type); 373 cert->GetStringWithoutPathExpansion(certificate::kType, &cert_type);
373 if (cert_type != certificate::kServer && 374 if (cert_type != certificate::kServer &&
374 cert_type != certificate::kAuthority) { 375 cert_type != certificate::kAuthority) {
375 continue; 376 continue;
376 } 377 }
377 std::string x509_data; 378 std::string x509_data;
378 cert->GetStringWithoutPathExpansion(certificate::kX509, &x509_data); 379 cert->GetStringWithoutPathExpansion(certificate::kX509, &x509_data);
379 380
380 std::string der = DecodePEM(x509_data); 381 std::string der = DecodePEM(x509_data);
381 std::string pem; 382 std::string pem;
382 if (der.empty() || !net::X509Certificate::GetPEMEncodedFromDER(der, &pem)) { 383 if (der.empty() || !net::X509Certificate::GetPEMEncodedFromDER(der, &pem)) {
383 LOG(ERROR) << "Certificate with GUID " << guid 384 LOG(ERROR) << "Certificate with GUID " << guid
384 << " is not in PEM encoding."; 385 << " is not in PEM encoding.";
385 continue; 386 continue;
386 } 387 }
387 certs_by_guid[guid] = pem; 388 certs_by_guid[guid] = pem;
388 } 389 }
389 390
390 return certs_by_guid; 391 return certs_by_guid;
391 } 392 }
392 393
393 void FillInHexSSIDFieldsInNetworks(base::ListValue* network_configs) { 394 void FillInHexSSIDFieldsInNetworks(base::ListValue* network_configs) {
394 for (base::Value* entry : *network_configs) { 395 for (const auto& entry : *network_configs) {
395 base::DictionaryValue* network = nullptr; 396 base::DictionaryValue* network = nullptr;
396 entry->GetAsDictionary(&network); 397 entry->GetAsDictionary(&network);
397 DCHECK(network); 398 DCHECK(network);
398 FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, network); 399 FillInHexSSIDFieldsInOncObject(kNetworkConfigurationSignature, network);
399 } 400 }
400 } 401 }
401 402
402 } // namespace 403 } // namespace
403 404
404 bool ParseAndValidateOncForImport(const std::string& onc_blob, 405 bool ParseAndValidateOncForImport(const std::string& onc_blob,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 const std::string& key_guid_ref_list, 551 const std::string& key_guid_ref_list,
551 const std::string& key_pem_list, 552 const std::string& key_pem_list,
552 base::DictionaryValue* onc_object) { 553 base::DictionaryValue* onc_object) {
553 const base::ListValue* guid_ref_list = nullptr; 554 const base::ListValue* guid_ref_list = nullptr;
554 if (!onc_object->GetListWithoutPathExpansion(key_guid_ref_list, 555 if (!onc_object->GetListWithoutPathExpansion(key_guid_ref_list,
555 &guid_ref_list)) { 556 &guid_ref_list)) {
556 return true; 557 return true;
557 } 558 }
558 559
559 std::unique_ptr<base::ListValue> pem_list(new base::ListValue); 560 std::unique_ptr<base::ListValue> pem_list(new base::ListValue);
560 for (const base::Value* entry : *guid_ref_list) { 561 for (const auto& entry : *guid_ref_list) {
561 std::string guid_ref; 562 std::string guid_ref;
562 entry->GetAsString(&guid_ref); 563 if (!entry->GetAsString(&guid_ref))
danakj 2016/05/24 20:08:35 nitto
dcheng 2016/05/24 20:39:02 Done.
564 NOTREACHED();
563 565
564 std::string pem_encoded; 566 std::string pem_encoded;
565 if (!GUIDRefToPEMEncoding(certs_by_guid, guid_ref, &pem_encoded)) 567 if (!GUIDRefToPEMEncoding(certs_by_guid, guid_ref, &pem_encoded))
566 return false; 568 return false;
567 569
568 pem_list->AppendString(pem_encoded); 570 pem_list->AppendString(pem_encoded);
569 } 571 }
570 572
571 onc_object->RemoveWithoutPathExpansion(key_guid_ref_list, nullptr); 573 onc_object->RemoveWithoutPathExpansion(key_guid_ref_list, nullptr);
572 onc_object->SetWithoutPathExpansion(key_pem_list, pem_list.release()); 574 onc_object->SetWithoutPathExpansion(key_pem_list, pem_list.release());
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 default: { 987 default: {
986 LOG(ERROR) << "Unexpected proxy mode in Shill config: " << mode; 988 LOG(ERROR) << "Unexpected proxy mode in Shill config: " << mode;
987 return nullptr; 989 return nullptr;
988 } 990 }
989 } 991 }
990 return proxy_settings; 992 return proxy_settings;
991 } 993 }
992 994
993 } // namespace onc 995 } // namespace onc
994 } // namespace chromeos 996 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698