| 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/device_state.h" | 5 #include "chromeos/network/device_state.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" |
| 10 #include "chromeos/network/network_event_log.h" | 12 #include "chromeos/network/network_event_log.h" |
| 11 #include "chromeos/network/shill_property_util.h" | 13 #include "chromeos/network/shill_property_util.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 15 |
| 14 namespace chromeos { | 16 namespace chromeos { |
| 15 | 17 |
| 16 DeviceState::DeviceState(const std::string& path) | 18 DeviceState::DeviceState(const std::string& path) |
| 17 : ManagedState(MANAGED_TYPE_DEVICE, path), | 19 : ManagedState(MANAGED_TYPE_DEVICE, path), |
| 18 allow_roaming_(false), | 20 allow_roaming_(false), |
| 19 provider_requires_roaming_(false), | 21 provider_requires_roaming_(false), |
| 20 support_network_scan_(false), | 22 support_network_scan_(false), |
| 21 scanning_(false), | 23 scanning_(false), |
| 22 sim_retries_left_(0), | 24 sim_retries_left_(0), |
| 23 sim_present_(true), | 25 sim_present_(true), |
| 24 eap_authentication_completed_(false) { | 26 eap_authentication_completed_(false) { |
| 25 } | 27 } |
| 26 | 28 |
| 27 DeviceState::~DeviceState() { | 29 DeviceState::~DeviceState() { |
| 28 } | 30 } |
| 29 | 31 |
| 30 bool DeviceState::PropertyChanged(const std::string& key, | 32 bool DeviceState::PropertyChanged(const std::string& key, |
| 31 const base::Value& value) { | 33 const base::Value& value) { |
| 32 // All property values get stored in |properties_|. | 34 // All property values get stored in |properties_|. |
| 33 properties_.SetWithoutPathExpansion(key, value.DeepCopy()); | 35 properties_.SetWithoutPathExpansion(key, |
| 36 base::MakeUnique<base::Value>(value)); |
| 34 | 37 |
| 35 if (ManagedStatePropertyChanged(key, value)) | 38 if (ManagedStatePropertyChanged(key, value)) |
| 36 return true; | 39 return true; |
| 37 if (key == shill::kAddressProperty) { | 40 if (key == shill::kAddressProperty) { |
| 38 return GetStringValue(key, value, &mac_address_); | 41 return GetStringValue(key, value, &mac_address_); |
| 39 } else if (key == shill::kScanningProperty) { | 42 } else if (key == shill::kScanningProperty) { |
| 40 return GetBooleanValue(key, value, &scanning_); | 43 return GetBooleanValue(key, value, &scanning_); |
| 41 } else if (key == shill::kSupportNetworkScanProperty) { | 44 } else if (key == shill::kSupportNetworkScanProperty) { |
| 42 return GetBooleanValue(key, value, &support_network_scan_); | 45 return GetBooleanValue(key, value, &support_network_scan_); |
| 43 } else if (key == shill::kCellularAllowRoamingProperty) { | 46 } else if (key == shill::kCellularAllowRoamingProperty) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void DeviceState::IPConfigPropertiesChanged( | 118 void DeviceState::IPConfigPropertiesChanged( |
| 116 const std::string& ip_config_path, | 119 const std::string& ip_config_path, |
| 117 const base::DictionaryValue& properties) { | 120 const base::DictionaryValue& properties) { |
| 118 base::DictionaryValue* ip_config = nullptr; | 121 base::DictionaryValue* ip_config = nullptr; |
| 119 if (ip_configs_.GetDictionaryWithoutPathExpansion( | 122 if (ip_configs_.GetDictionaryWithoutPathExpansion( |
| 120 ip_config_path, &ip_config)) { | 123 ip_config_path, &ip_config)) { |
| 121 NET_LOG_EVENT("IPConfig Updated: " + ip_config_path, path()); | 124 NET_LOG_EVENT("IPConfig Updated: " + ip_config_path, path()); |
| 122 ip_config->Clear(); | 125 ip_config->Clear(); |
| 123 } else { | 126 } else { |
| 124 NET_LOG_EVENT("IPConfig Added: " + ip_config_path, path()); | 127 NET_LOG_EVENT("IPConfig Added: " + ip_config_path, path()); |
| 125 ip_config = new base::DictionaryValue; | 128 ip_config = ip_configs_.SetDictionaryWithoutPathExpansion( |
| 126 ip_configs_.SetWithoutPathExpansion(ip_config_path, ip_config); | 129 ip_config_path, base::MakeUnique<base::DictionaryValue>()); |
| 127 } | 130 } |
| 128 ip_config->MergeDictionary(&properties); | 131 ip_config->MergeDictionary(&properties); |
| 129 } | 132 } |
| 130 | 133 |
| 131 std::string DeviceState::GetIpAddressByType(const std::string& type) const { | 134 std::string DeviceState::GetIpAddressByType(const std::string& type) const { |
| 132 for (base::DictionaryValue::Iterator iter(ip_configs_); !iter.IsAtEnd(); | 135 for (base::DictionaryValue::Iterator iter(ip_configs_); !iter.IsAtEnd(); |
| 133 iter.Advance()) { | 136 iter.Advance()) { |
| 134 const base::DictionaryValue* ip_config; | 137 const base::DictionaryValue* ip_config; |
| 135 if (!iter.value().GetAsDictionary(&ip_config)) | 138 if (!iter.value().GetAsDictionary(&ip_config)) |
| 136 continue; | 139 continue; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 } | 150 } |
| 148 } | 151 } |
| 149 return std::string(); | 152 return std::string(); |
| 150 } | 153 } |
| 151 | 154 |
| 152 bool DeviceState::IsSimAbsent() const { | 155 bool DeviceState::IsSimAbsent() const { |
| 153 return technology_family_ == shill::kTechnologyFamilyGsm && !sim_present_; | 156 return technology_family_ == shill::kTechnologyFamilyGsm && !sim_present_; |
| 154 } | 157 } |
| 155 | 158 |
| 156 } // namespace chromeos | 159 } // namespace chromeos |
| OLD | NEW |