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