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/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chromeos/network/network_handler.h" | |
| 15 #include "chromeos/network/network_profile_handler.h" | 16 #include "chromeos/network/network_profile_handler.h" |
| 16 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
| 18 #include "chromeos/network/network_state_handler.h" | |
| 17 #include "chromeos/network/network_util.h" | 19 #include "chromeos/network/network_util.h" |
| 18 #include "chromeos/network/onc/onc_signature.h" | 20 #include "chromeos/network/onc/onc_signature.h" |
| 19 #include "chromeos/network/onc/onc_translation_tables.h" | 21 #include "chromeos/network/onc/onc_translation_tables.h" |
| 20 #include "chromeos/network/shill_property_util.h" | 22 #include "chromeos/network/shill_property_util.h" |
| 21 #include "components/onc/onc_constants.h" | 23 #include "components/onc/onc_constants.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 25 |
| 24 namespace chromeos { | 26 namespace chromeos { |
| 25 namespace onc { | 27 namespace onc { |
| 26 | 28 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 value = base::JSONReader::Read(str); | 39 value = base::JSONReader::Read(str); |
| 38 } | 40 } |
| 39 | 41 |
| 40 if (value == NULL || value->GetType() != type) { | 42 if (value == NULL || value->GetType() != type) { |
| 41 delete value; | 43 delete value; |
| 42 value = NULL; | 44 value = NULL; |
| 43 } | 45 } |
| 44 return make_scoped_ptr(value); | 46 return make_scoped_ptr(value); |
| 45 } | 47 } |
| 46 | 48 |
| 49 const NetworkState* GetNetworkStateFromGuid(const std::string& guid) { | |
| 50 if (!NetworkHandler::IsInitialized()) | |
|
pneubeck (no reviews)
2015/04/14 09:32:16
This is not explicit though.
If at all, please pas
| |
| 51 return nullptr; | |
| 52 return NetworkHandler::Get() | |
| 53 ->network_state_handler() | |
| 54 ->GetNetworkStateFromGuid(guid); | |
| 55 } | |
| 56 | |
| 47 // This class implements the translation of properties from the given | 57 // This class implements the translation of properties from the given |
| 48 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using | 58 // |shill_dictionary| to a new ONC object of signature |onc_signature|. Using |
| 49 // recursive calls to CreateTranslatedONCObject of new instances, nested objects | 59 // recursive calls to CreateTranslatedONCObject of new instances, nested objects |
| 50 // are translated. | 60 // are translated. |
| 51 class ShillToONCTranslator { | 61 class ShillToONCTranslator { |
| 52 public: | 62 public: |
| 53 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, | 63 ShillToONCTranslator(const base::DictionaryValue& shill_dictionary, |
| 54 ::onc::ONCSource onc_source, | 64 ::onc::ONCSource onc_source, |
| 55 const OncValueSignature& onc_signature) | 65 const OncValueSignature& onc_signature) |
| 56 : shill_dictionary_(&shill_dictionary), | 66 : shill_dictionary_(&shill_dictionary), |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 } | 477 } |
| 468 onc_object_->SetStringWithoutPathExpansion( | 478 onc_object_->SetStringWithoutPathExpansion( |
| 469 ::onc::network_config::kConnectionState, onc_state); | 479 ::onc::network_config::kConnectionState, onc_state); |
| 470 // Only set 'RestrictedConnectivity' if captive portal state is true. | 480 // Only set 'RestrictedConnectivity' if captive portal state is true. |
| 471 if (NetworkState::NetworkStateIsCaptivePortal(*shill_dictionary_)) { | 481 if (NetworkState::NetworkStateIsCaptivePortal(*shill_dictionary_)) { |
| 472 onc_object_->SetBooleanWithoutPathExpansion( | 482 onc_object_->SetBooleanWithoutPathExpansion( |
| 473 ::onc::network_config::kRestrictedConnectivity, true); | 483 ::onc::network_config::kRestrictedConnectivity, true); |
| 474 } | 484 } |
| 475 } | 485 } |
| 476 | 486 |
| 487 // 'ErrorState' reflects the most recent error maintained in NetworkState | |
| 488 // (which may not match Shill's Error or PreviousError properties). Non | |
| 489 // visible networks (with no NetworkState) do not set ErrorState. | |
| 490 std::string guid; | |
| 491 if (shill_dictionary_->GetStringWithoutPathExpansion(shill::kGuidProperty, | |
| 492 &guid)) { | |
| 493 const NetworkState* network_state = GetNetworkStateFromGuid(guid); | |
| 494 if (network_state) { | |
| 495 onc_object_->SetStringWithoutPathExpansion( | |
| 496 ::onc::network_config::kErrorState, network_state->GetErrorState()); | |
| 497 } | |
| 498 } | |
| 499 | |
| 477 std::string profile_path; | 500 std::string profile_path; |
| 478 if (onc_source_ != ::onc::ONC_SOURCE_UNKNOWN && | 501 if (onc_source_ != ::onc::ONC_SOURCE_UNKNOWN && |
| 479 shill_dictionary_->GetStringWithoutPathExpansion(shill::kProfileProperty, | 502 shill_dictionary_->GetStringWithoutPathExpansion(shill::kProfileProperty, |
| 480 &profile_path)) { | 503 &profile_path)) { |
| 481 std::string source; | 504 std::string source; |
| 482 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) | 505 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY) |
| 483 source = ::onc::network_config::kSourceDevicePolicy; | 506 source = ::onc::network_config::kSourceDevicePolicy; |
| 484 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY) | 507 else if (onc_source_ == ::onc::ONC_SOURCE_USER_POLICY) |
| 485 source = ::onc::network_config::kSourceUserPolicy; | 508 source = ::onc::network_config::kSourceUserPolicy; |
| 486 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath()) | 509 else if (profile_path == NetworkProfileHandler::GetSharedProfilePath()) |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 ::onc::ONCSource onc_source, | 753 ::onc::ONCSource onc_source, |
| 731 const OncValueSignature* onc_signature) { | 754 const OncValueSignature* onc_signature) { |
| 732 CHECK(onc_signature != NULL); | 755 CHECK(onc_signature != NULL); |
| 733 | 756 |
| 734 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); | 757 ShillToONCTranslator translator(shill_dictionary, onc_source, *onc_signature); |
| 735 return translator.CreateTranslatedONCObject(); | 758 return translator.CreateTranslatedONCObject(); |
| 736 } | 759 } |
| 737 | 760 |
| 738 } // namespace onc | 761 } // namespace onc |
| 739 } // namespace chromeos | 762 } // namespace chromeos |
| OLD | NEW |