Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_util.h" | |
| 15 #include "chromeos/network/onc/onc_signature.h" | 16 #include "chromeos/network/onc/onc_signature.h" |
| 16 #include "chromeos/network/onc/onc_translation_tables.h" | 17 #include "chromeos/network/onc/onc_translation_tables.h" |
| 17 #include "chromeos/network/shill_property_util.h" | 18 #include "chromeos/network/shill_property_util.h" |
| 18 #include "components/onc/onc_constants.h" | 19 #include "components/onc/onc_constants.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 namespace onc { | 23 namespace onc { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 } | 284 } |
| 284 | 285 |
| 285 // Since Name is a read only field in Shill unless it's a VPN, it is copied | 286 // Since Name is a read only field in Shill unless it's a VPN, it is copied |
| 286 // here, but not when going the other direction (if it's not a VPN). | 287 // here, but not when going the other direction (if it's not a VPN). |
| 287 std::string name; | 288 std::string name; |
| 288 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, | 289 shill_dictionary_->GetStringWithoutPathExpansion(shill::kNameProperty, |
| 289 &name); | 290 &name); |
| 290 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName, | 291 onc_object_->SetStringWithoutPathExpansion(::onc::network_config::kName, |
| 291 name); | 292 name); |
| 292 | 293 |
| 294 // Limit ONC state to "NotConnected", "Connected", or "Connecting". | |
| 293 std::string state; | 295 std::string state; |
| 294 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty, | 296 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kStateProperty, |
| 295 &state)) { | 297 &state)) { |
| 296 std::string onc_state = ::onc::connection_state::kNotConnected; | 298 std::string onc_state = ::onc::connection_state::kNotConnected; |
| 297 if (NetworkState::StateIsConnected(state)) { | 299 if (NetworkState::StateIsConnected(state)) { |
| 298 onc_state = ::onc::connection_state::kConnected; | 300 onc_state = ::onc::connection_state::kConnected; |
| 299 } else if (NetworkState::StateIsConnecting(state)) { | 301 } else if (NetworkState::StateIsConnecting(state)) { |
| 300 onc_state = ::onc::connection_state::kConnecting; | 302 onc_state = ::onc::connection_state::kConnecting; |
| 301 } | 303 } |
| 302 onc_object_->SetStringWithoutPathExpansion( | 304 onc_object_->SetStringWithoutPathExpansion( |
| 303 ::onc::network_config::kConnectionState, onc_state); | 305 ::onc::network_config::kConnectionState, onc_state); |
| 304 } | 306 } |
| 305 | 307 |
| 306 // Shill's Service has an IPConfig property (note the singular, and not a | 308 // Use a human-readable aa:bb format for any hardware MAC address. Note: |
| 307 // IPConfigs property). However, we require the caller of the translation to | 309 // this property is provided by the caller| but is not part of the Shill |
|
pneubeck (no reviews)
2014/05/16 07:44:55
typo: remove orphaned '|'
stevenjb
2014/05/16 18:01:58
Done.
| |
| 310 // Service properties (it is copied from the Device properties). | |
| 311 std::string address; | |
| 312 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kAddressProperty, | |
| 313 &address)) { | |
| 314 onc_object_->SetStringWithoutPathExpansion( | |
| 315 ::onc::network_config::kMacAddress, | |
| 316 network_util::FormattedMacAddress(address)); | |
| 317 } | |
| 318 | |
| 319 // Shill's Service has an IPConfig property (note the singular), not an | |
| 320 // IPConfigs property. However, we require the caller of the translation to | |
| 308 // patch the Shill dictionary before passing it to the translator. | 321 // patch the Shill dictionary before passing it to the translator. |
| 309 const base::ListValue* shill_ipconfigs = NULL; | 322 const base::ListValue* shill_ipconfigs = NULL; |
| 310 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, | 323 if (shill_dictionary_->GetListWithoutPathExpansion(shill::kIPConfigsProperty, |
| 311 &shill_ipconfigs)) { | 324 &shill_ipconfigs)) { |
| 312 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, | 325 TranslateAndAddListOfObjects(::onc::network_config::kIPConfigs, |
| 313 *shill_ipconfigs); | 326 *shill_ipconfigs); |
| 314 } | 327 } |
| 315 } | 328 } |
| 316 | 329 |
| 317 void ShillToONCTranslator::TranslateIPConfig() { | 330 void ShillToONCTranslator::TranslateIPConfig() { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 const base::DictionaryValue& shill_dictionary, | 466 const base::DictionaryValue& shill_dictionary, |
| 454 const OncValueSignature* onc_signature) { | 467 const OncValueSignature* onc_signature) { |
| 455 CHECK(onc_signature != NULL); | 468 CHECK(onc_signature != NULL); |
| 456 | 469 |
| 457 ShillToONCTranslator translator(shill_dictionary, *onc_signature); | 470 ShillToONCTranslator translator(shill_dictionary, *onc_signature); |
| 458 return translator.CreateTranslatedONCObject(); | 471 return translator.CreateTranslatedONCObject(); |
| 459 } | 472 } |
| 460 | 473 |
| 461 } // namespace onc | 474 } // namespace onc |
| 462 } // namespace chromeos | 475 } // namespace chromeos |
| OLD | NEW |