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

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

Issue 1085993002: Revert of Use networkingPrivate.startConnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_430115_internet_options_cellular
Patch Set: Created 5 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
« no previous file with comments | « chromeos/network/onc/onc_translator.h ('k') | chromeos/network/onc/onc_translator_unittest.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 #include "chromeos/network/onc/onc_translator.h" 5 #include "chromeos/network/onc/onc_translator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 // This class implements the translation of properties from the given 47 // This class implements the translation of properties from the given
48 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using 48 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using
49 // recursive calls to CreateTranslatedONCObject of new instances, nested objects 49 // recursive calls to CreateTranslatedONCObject of new instances, nested objects
50 // are translated. 50 // are translated.
51 class ShillToONCTranslator { 51 class ShillToONCTranslator {
52 public: 52 public:
53 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, 53 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary,
54 ::onc::ONCSource onc_source, 54 ::onc::ONCSource onc_source,
55 const OncValueSignature& onc_signature, 55 const OncValueSignature& onc_signature)
56 const NetworkState* network_state)
57 : shill_dictionary_(&shill_dictionary), 56 : shill_dictionary_(&shill_dictionary),
58 onc_source_(onc_source), 57 onc_source_(onc_source),
59 onc_signature_(&onc_signature), 58 onc_signature_(&onc_signature) {
60 network_state_(network_state) {
61 field_translation_table_ = GetFieldTranslationTable(onc_signature); 59 field_translation_table_ = GetFieldTranslationTable(onc_signature);
62 } 60 }
63 61
64 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, 62 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary,
65 ::onc::ONCSource onc_source, 63 ::onc::ONCSource onc_source,
66 const OncValueSignature& onc_signature, 64 const OncValueSignature& onc_signature,
67 const FieldTranslationEntry* field_translation_table, 65 const FieldTranslationEntry* field_translation_table)
68 const NetworkState* network_state)
69 : shill_dictionary_(&shill_dictionary), 66 : shill_dictionary_(&shill_dictionary),
70 onc_source_(onc_source), 67 onc_source_(onc_source),
71 onc_signature_(&onc_signature), 68 onc_signature_(&onc_signature),
72 field_translation_table_(field_translation_table), 69 field_translation_table_(field_translation_table) {}
73 network_state_(network_state) {}
74 70
75 // Translates the associated Shill dictionary and creates an ONC object of the 71 // Translates the associated Shill dictionary and creates an ONC object of the
76 // given signature. 72 // given signature.
77 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject(); 73 scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
78 74
79 private: 75 private:
80 void TranslateEthernet(); 76 void TranslateEthernet();
81 void TranslateOpenVPN(); 77 void TranslateOpenVPN();
82 void TranslateIPsec(); 78 void TranslateIPsec();
83 void TranslateThirdPartyVPN(); 79 void TranslateThirdPartyVPN();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 135
140 // Returns the name of the Shill service provided in |shill_dictionary_| 136 // Returns the name of the Shill service provided in |shill_dictionary_|
141 // for debugging. 137 // for debugging.
142 std::string GetName(); 138 std::string GetName();
143 139
144 const base::DictionaryValue* shill_dictionary_; 140 const base::DictionaryValue* shill_dictionary_;
145 ::onc::ONCSource onc_source_; 141 ::onc::ONCSource onc_source_;
146 const OncValueSignature* onc_signature_; 142 const OncValueSignature* onc_signature_;
147 const FieldTranslationEntry* field_translation_table_; 143 const FieldTranslationEntry* field_translation_table_;
148 scoped_ptr<base::DictionaryValue> onc_object_; 144 scoped_ptr<base::DictionaryValue> onc_object_;
149 const NetworkState* network_state_;
150 145
151 DISALLOW_COPY_AND_ASSIGN(ShillToONCTranslator); 146 DISALLOW_COPY_AND_ASSIGN(ShillToONCTranslator);
152 }; 147 };
153 148
154 scoped_ptr<base::DictionaryValue> 149 scoped_ptr<base::DictionaryValue>
155 ShillToONCTranslator::CreateTranslatedONCObject() { 150 ShillToONCTranslator::CreateTranslatedONCObject() {
156 onc_object_.reset(new base::DictionaryValue); 151 onc_object_.reset(new base::DictionaryValue);
157 if (onc_signature_ == &kNetworkWithStateSignature) { 152 if (onc_signature_ == &kNetworkWithStateSignature) {
158 TranslateNetworkWithState(); 153 TranslateNetworkWithState();
159 } else if (onc_signature_ == &kEthernetSignature) { 154 } else if (onc_signature_ == &kEthernetSignature) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 TranslateAndAddNestedObject(::onc::cellular::kPaymentPortal, *dictionary); 375 TranslateAndAddNestedObject(::onc::cellular::kPaymentPortal, *dictionary);
381 } 376 }
382 377
383 const base::DictionaryValue* device_dictionary = NULL; 378 const base::DictionaryValue* device_dictionary = NULL;
384 bool requires_roaming = false; 379 bool requires_roaming = false;
385 shill_dictionary_->GetDictionaryWithoutPathExpansion(shill::kDeviceProperty, 380 shill_dictionary_->GetDictionaryWithoutPathExpansion(shill::kDeviceProperty,
386 &device_dictionary); 381 &device_dictionary);
387 if (device_dictionary) { 382 if (device_dictionary) {
388 // Merge the Device dictionary with this one (Cellular) using the 383 // Merge the Device dictionary with this one (Cellular) using the
389 // CellularDevice signature. 384 // CellularDevice signature.
390 ShillToONCTranslator nested_translator( 385 ShillToONCTranslator nested_translator(*device_dictionary, onc_source_,
391 *device_dictionary, onc_source_, kCellularWithStateSignature, 386 kCellularWithStateSignature,
392 kCellularDeviceTable, network_state_); 387 kCellularDeviceTable);
393 scoped_ptr<base::DictionaryValue> nested_object = 388 scoped_ptr<base::DictionaryValue> nested_object =
394 nested_translator.CreateTranslatedONCObject(); 389 nested_translator.CreateTranslatedONCObject();
395 onc_object_->MergeDictionary(nested_object.get()); 390 onc_object_->MergeDictionary(nested_object.get());
396 391
397 /// Get the requires_roaming from the Device dictionary. 392 /// Get the requires_roaming from the Device dictionary.
398 device_dictionary->GetBooleanWithoutPathExpansion( 393 device_dictionary->GetBooleanWithoutPathExpansion(
399 shill::kProviderRequiresRoamingProperty, &requires_roaming); 394 shill::kProviderRequiresRoamingProperty, &requires_roaming);
400 } 395 }
401 if (requires_roaming) { 396 if (requires_roaming) {
402 onc_object_->SetStringWithoutPathExpansion( 397 onc_object_->SetStringWithoutPathExpansion(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 467 }
473 onc_object_->SetStringWithoutPathExpansion( 468 onc_object_->SetStringWithoutPathExpansion(
474 ::onc::network_config::kConnectionState, onc_state); 469 ::onc::network_config::kConnectionState, onc_state);
475 // Only set 'RestrictedConnectivity' if captive portal state is true. 470 // Only set 'RestrictedConnectivity' if captive portal state is true.
476 if (NetworkState::NetworkStateIsCaptivePortal(*shill_dictionary_)) { 471 if (NetworkState::NetworkStateIsCaptivePortal(*shill_dictionary_)) {
477 onc_object_->SetBooleanWithoutPathExpansion( 472 onc_object_->SetBooleanWithoutPathExpansion(
478 ::onc::network_config::kRestrictedConnectivity, true); 473 ::onc::network_config::kRestrictedConnectivity, true);
479 } 474 }
480 } 475 }
481 476
482 // 'ErrorState' reflects the most recent error maintained in NetworkState
483 // (which may not match Shill's Error or PreviousError properties). Non
484 // visible networks (with null network_state_) do not set ErrorState.
485 if (network_state_) {
486 std::string error_state = network_state_->GetErrorState();
487 if (!error_state.empty()) {
488 onc_object_->SetStringWithoutPathExpansion(
489 ::onc::network_config::kErrorState, error_state);
490 }
491 }
492
493 std::string profile_path; 477 std::string profile_path;
494 if (onc_source_ != ::onc::ONC_SOURCE_UNKNOWN && 478 if (onc_source_ != ::onc::ONC_SOURCE_UNKNOWN &&
495 shill_dictionary_->GetStringWithoutPathExpansion(shill::kProfileProperty, 479 shill_dictionary_->GetStringWithoutPathExpansion(shill::kProfileProperty,
496 &profile_path)) { 480 &profile_path)) {
497 std::string source; 481 std::string source;
498 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) 482 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY)
499 source = ::onc::network_config::kSourceDevicePolicy; 483 source = ::onc::network_config::kSourceDevicePolicy;
500 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY) 484 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY)
501 source = ::onc::network_config::kSourceUserPolicy; 485 source = ::onc::network_config::kSourceUserPolicy;
502 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath()) 486 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath())
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 void ShillToONCTranslator::TranslateAndAddNestedObject( 594 void ShillToONCTranslator::TranslateAndAddNestedObject(
611 const std::string& onc_field_name, 595 const std::string& onc_field_name,
612 const base::DictionaryValue& dictionary) { 596 const base::DictionaryValue& dictionary) {
613 const OncFieldSignature* field_signature = 597 const OncFieldSignature* field_signature =
614 GetFieldSignature(*onc_signature_, onc_field_name); 598 GetFieldSignature(*onc_signature_, onc_field_name);
615 if (!field_signature) { 599 if (!field_signature) {
616 NOTREACHED() << "Unable to find signature for field: " << onc_field_name; 600 NOTREACHED() << "Unable to find signature for field: " << onc_field_name;
617 return; 601 return;
618 } 602 }
619 ShillToONCTranslator nested_translator(dictionary, onc_source_, 603 ShillToONCTranslator nested_translator(dictionary, onc_source_,
620 *field_signature->value_signature, 604 *field_signature->value_signature);
621 network_state_);
622 scoped_ptr<base::DictionaryValue> nested_object = 605 scoped_ptr<base::DictionaryValue> nested_object =
623 nested_translator.CreateTranslatedONCObject(); 606 nested_translator.CreateTranslatedONCObject();
624 if (nested_object->empty()) 607 if (nested_object->empty())
625 return; 608 return;
626 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release()); 609 onc_object_->SetWithoutPathExpansion(onc_field_name, nested_object.release());
627 } 610 }
628 611
629 void ShillToONCTranslator::SetNestedOncValue( 612 void ShillToONCTranslator::SetNestedOncValue(
630 const std::string& onc_dictionary_name, 613 const std::string& onc_dictionary_name,
631 const std::string& onc_field_name, 614 const std::string& onc_field_name,
(...skipping 20 matching lines...) Expand all
652 } 635 }
653 DCHECK(field_signature->value_signature->onc_array_entry_signature); 636 DCHECK(field_signature->value_signature->onc_array_entry_signature);
654 scoped_ptr<base::ListValue> result(new base::ListValue()); 637 scoped_ptr<base::ListValue> result(new base::ListValue());
655 for (base::ListValue::const_iterator it = list.begin(); it != list.end(); 638 for (base::ListValue::const_iterator it = list.begin(); it != list.end();
656 ++it) { 639 ++it) {
657 const base::DictionaryValue* shill_value = NULL; 640 const base::DictionaryValue* shill_value = NULL;
658 if (!(*it)->GetAsDictionary(&shill_value)) 641 if (!(*it)->GetAsDictionary(&shill_value))
659 continue; 642 continue;
660 ShillToONCTranslator nested_translator( 643 ShillToONCTranslator nested_translator(
661 *shill_value, onc_source_, 644 *shill_value, onc_source_,
662 *field_signature->value_signature->onc_array_entry_signature, 645 *field_signature->value_signature->onc_array_entry_signature);
663 network_state_);
664 scoped_ptr<base::DictionaryValue> nested_object = 646 scoped_ptr<base::DictionaryValue> nested_object =
665 nested_translator.CreateTranslatedONCObject(); 647 nested_translator.CreateTranslatedONCObject();
666 // If the nested object couldn't be parsed, simply omit it. 648 // If the nested object couldn't be parsed, simply omit it.
667 if (nested_object->empty()) 649 if (nested_object->empty())
668 continue; 650 continue;
669 result->Append(nested_object.release()); 651 result->Append(nested_object.release());
670 } 652 }
671 // If there are no entries in the list, there is no need to expose this field. 653 // If there are no entries in the list, there is no need to expose this field.
672 if (result->empty()) 654 if (result->empty())
673 return; 655 return;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 std::string name; 721 std::string name;
740 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name); 722 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, &name);
741 return name; 723 return name;
742 } 724 }
743 725
744 } // namespace 726 } // namespace
745 727
746 scoped_ptr<base::DictionaryValue> TranslateShillServiceToONCPart( 728 scoped_ptr<base::DictionaryValue> TranslateShillServiceToONCPart(
747 const base::DictionaryValue& shill_dictionary, 729 const base::DictionaryValue& shill_dictionary,
748 ::onc::ONCSource onc_source, 730 ::onc::ONCSource onc_source,
749 const OncValueSignature* onc_signature, 731 const OncValueSignature* onc_signature) {
750 const NetworkState* network_state) {
751 CHECK(onc_signature != NULL); 732 CHECK(onc_signature != NULL);
752 733
753 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature, 734 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature);
754 network_state);
755 return translator.CreateTranslatedONCObject(); 735 return translator.CreateTranslatedONCObject();
756 } 736 }
757 737
758 } // namespace onc 738 } // namespace onc
759 } // namespace chromeos 739 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_translator.h ('k') | chromeos/network/onc/onc_translator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698