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

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

Issue 2843813002: Remove SetWithoutPathExpansion (Closed)
Patch Set: Fix CrOS Error Created 3 years, 7 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
« no previous file with comments | « chromeos/network/onc/onc_merger.cc ('k') | chromeos/network/onc/onc_translator_shill_to_onc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The implementation of TranslateONCObjectToShill is structured in two parts: 5 // The implementation of TranslateONCObjectToShill is structured in two parts:
6 // - The recursion through the existing ONC hierarchy 6 // - The recursion through the existing ONC hierarchy
7 // see TranslateONCHierarchy 7 // see TranslateONCHierarchy
8 // - The local translation of an object depending on the associated signature 8 // - The local translation of an object depending on the associated signature
9 // see LocalTranslator::TranslateFields 9 // see LocalTranslator::TranslateFields
10 10
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 std::string ip_address_config_type, name_servers_config_type; 281 std::string ip_address_config_type, name_servers_config_type;
282 onc_object_->GetStringWithoutPathExpansion( 282 onc_object_->GetStringWithoutPathExpansion(
283 ::onc::network_config::kIPAddressConfigType, &ip_address_config_type); 283 ::onc::network_config::kIPAddressConfigType, &ip_address_config_type);
284 onc_object_->GetStringWithoutPathExpansion( 284 onc_object_->GetStringWithoutPathExpansion(
285 ::onc::network_config::kNameServersConfigType, &name_servers_config_type); 285 ::onc::network_config::kNameServersConfigType, &name_servers_config_type);
286 if ((ip_address_config_type == ::onc::network_config::kIPConfigTypeDHCP) || 286 if ((ip_address_config_type == ::onc::network_config::kIPConfigTypeDHCP) ||
287 (name_servers_config_type == ::onc::network_config::kIPConfigTypeDHCP)) { 287 (name_servers_config_type == ::onc::network_config::kIPConfigTypeDHCP)) {
288 // If either type is set to DHCP, provide an empty dictionary to ensure 288 // If either type is set to DHCP, provide an empty dictionary to ensure
289 // that any unset properties are cleared. Note: if either type is specified, 289 // that any unset properties are cleared. Note: if either type is specified,
290 // the other type defaults to DHCP if not specified. 290 // the other type defaults to DHCP if not specified.
291 shill_dictionary_->SetWithoutPathExpansion(shill::kStaticIPConfigProperty, 291 shill_dictionary_->SetWithoutPathExpansion(
292 new base::DictionaryValue); 292 shill::kStaticIPConfigProperty,
293 base::MakeUnique<base::DictionaryValue>());
293 } 294 }
294 295
295 const base::DictionaryValue* proxy_settings = nullptr; 296 const base::DictionaryValue* proxy_settings = nullptr;
296 if (onc_object_->GetDictionaryWithoutPathExpansion( 297 if (onc_object_->GetDictionaryWithoutPathExpansion(
297 ::onc::network_config::kProxySettings, &proxy_settings)) { 298 ::onc::network_config::kProxySettings, &proxy_settings)) {
298 std::unique_ptr<base::DictionaryValue> proxy_config = 299 std::unique_ptr<base::DictionaryValue> proxy_config =
299 ConvertOncProxySettingsToProxyConfig(*proxy_settings); 300 ConvertOncProxySettingsToProxyConfig(*proxy_settings);
300 std::string proxy_config_str; 301 std::string proxy_config_str;
301 base::JSONWriter::Write(*proxy_config.get(), &proxy_config_str); 302 base::JSONWriter::Write(*proxy_config.get(), &proxy_config_str);
302 shill_dictionary_->SetStringWithoutPathExpansion( 303 shill_dictionary_->SetStringWithoutPathExpansion(
(...skipping 27 matching lines...) Expand all
330 LOG(ERROR) << "Found field " << onc_field_name << " of type " 331 LOG(ERROR) << "Found field " << onc_field_name << " of type "
331 << value->GetType() << " but expected type " << expected_type; 332 << value->GetType() << " but expected type " << expected_type;
332 return; 333 return;
333 } 334 }
334 } else { 335 } else {
335 LOG(ERROR) 336 LOG(ERROR)
336 << "Attempt to translate a field that is not part of the ONC format."; 337 << "Attempt to translate a field that is not part of the ONC format.";
337 return; 338 return;
338 } 339 }
339 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, 340 shill_dictionary_->SetWithoutPathExpansion(shill_property_name,
340 value->DeepCopy()); 341 value->CreateDeepCopy());
341 } 342 }
342 343
343 void LocalTranslator::AddValueAccordingToSignature( 344 void LocalTranslator::AddValueAccordingToSignature(
344 const std::string& onc_name, 345 const std::string& onc_name,
345 std::unique_ptr<base::Value> value) { 346 std::unique_ptr<base::Value> value) {
346 if (!value || !field_translation_table_) 347 if (!value || !field_translation_table_)
347 return; 348 return;
348 std::string shill_property_name; 349 std::string shill_property_name;
349 if (!GetShillPropertyName(onc_name, field_translation_table_, 350 if (!GetShillPropertyName(onc_name, field_translation_table_,
350 &shill_property_name)) { 351 &shill_property_name)) {
351 return; 352 return;
352 } 353 }
353 354
354 shill_dictionary_->SetWithoutPathExpansion(shill_property_name, 355 shill_dictionary_->SetWithoutPathExpansion(shill_property_name,
355 value.release()); 356 std::move(value));
356 } 357 }
357 358
358 void LocalTranslator::TranslateWithTableAndSet( 359 void LocalTranslator::TranslateWithTableAndSet(
359 const std::string& onc_value, 360 const std::string& onc_value,
360 const StringTranslationEntry table[], 361 const StringTranslationEntry table[],
361 const std::string& shill_property_name) { 362 const std::string& shill_property_name) {
362 std::string shill_value; 363 std::string shill_value;
363 if (TranslateStringToShill(table, onc_value, &shill_value)) { 364 if (TranslateStringToShill(table, onc_value, &shill_value)) {
364 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name, 365 shill_dictionary_->SetStringWithoutPathExpansion(shill_property_name,
365 shill_value); 366 shill_value);
(...skipping 16 matching lines...) Expand all
382 base::DictionaryValue* target_shill_dictionary = shill_dictionary; 383 base::DictionaryValue* target_shill_dictionary = shill_dictionary;
383 std::vector<std::string> path_to_shill_dictionary = 384 std::vector<std::string> path_to_shill_dictionary =
384 GetPathToNestedShillDictionary(signature); 385 GetPathToNestedShillDictionary(signature);
385 for (std::vector<std::string>::const_iterator it = 386 for (std::vector<std::string>::const_iterator it =
386 path_to_shill_dictionary.begin(); 387 path_to_shill_dictionary.begin();
387 it != path_to_shill_dictionary.end(); ++it) { 388 it != path_to_shill_dictionary.end(); ++it) {
388 base::DictionaryValue* nested_shill_dict = NULL; 389 base::DictionaryValue* nested_shill_dict = NULL;
389 target_shill_dictionary->GetDictionaryWithoutPathExpansion( 390 target_shill_dictionary->GetDictionaryWithoutPathExpansion(
390 *it, &nested_shill_dict); 391 *it, &nested_shill_dict);
391 if (!nested_shill_dict) { 392 if (!nested_shill_dict) {
392 nested_shill_dict = new base::DictionaryValue; 393 target_shill_dictionary->SetWithoutPathExpansion(
393 target_shill_dictionary->SetWithoutPathExpansion(*it, nested_shill_dict); 394 *it, base::MakeUnique<base::DictionaryValue>());
395 target_shill_dictionary->GetDictionaryWithoutPathExpansion(
396 *it, &nested_shill_dict);
394 } 397 }
395 target_shill_dictionary = nested_shill_dict; 398 target_shill_dictionary = nested_shill_dict;
396 } 399 }
397 // Translates fields of |onc_object| and writes them to 400 // Translates fields of |onc_object| and writes them to
398 // |target_shill_dictionary_| nested in |shill_dictionary|. 401 // |target_shill_dictionary_| nested in |shill_dictionary|.
399 LocalTranslator translator(signature, onc_object, target_shill_dictionary); 402 LocalTranslator translator(signature, onc_object, target_shill_dictionary);
400 translator.TranslateFields(); 403 translator.TranslateFields();
401 404
402 // Recurse into nested objects. 405 // Recurse into nested objects.
403 for (base::DictionaryValue::Iterator it(onc_object); !it.IsAtEnd(); 406 for (base::DictionaryValue::Iterator it(onc_object); !it.IsAtEnd();
(...skipping 17 matching lines...) Expand all
421 const base::DictionaryValue& onc_object) { 424 const base::DictionaryValue& onc_object) {
422 CHECK(onc_signature != NULL); 425 CHECK(onc_signature != NULL);
423 std::unique_ptr<base::DictionaryValue> shill_dictionary( 426 std::unique_ptr<base::DictionaryValue> shill_dictionary(
424 new base::DictionaryValue); 427 new base::DictionaryValue);
425 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); 428 TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get());
426 return shill_dictionary; 429 return shill_dictionary;
427 } 430 }
428 431
429 } // namespace onc 432 } // namespace onc
430 } // namespace chromeos 433 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_merger.cc ('k') | chromeos/network/onc/onc_translator_shill_to_onc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698