| 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/network_state.h" | 5 #include "chromeos/network/network_state.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_encoding_detection.h" | 7 #include "base/i18n/icu_encoding_detection.h" |
| 8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
| 9 #include "base/json/json_reader.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversion_utils.h" | 13 #include "base/strings/utf_string_conversion_utils.h" |
| 13 #include "base/values.h" | |
| 14 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.h" |
| 15 #include "chromeos/network/network_ui_data.h" |
| 16 #include "chromeos/network/onc/onc_utils.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 const char kLogModule[] = "NetworkState"; | 21 const char kLogModule[] = "NetworkState"; |
| 20 | 22 |
| 21 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 23 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
| 22 std::vector<std::string>* result) { | 24 std::vector<std::string>* result) { |
| 23 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 25 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
| 24 std::string str; | 26 std::string str; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 | 53 |
| 52 } // namespace | 54 } // namespace |
| 53 | 55 |
| 54 namespace chromeos { | 56 namespace chromeos { |
| 55 | 57 |
| 56 NetworkState::NetworkState(const std::string& path) | 58 NetworkState::NetworkState(const std::string& path) |
| 57 : ManagedState(MANAGED_TYPE_NETWORK, path), | 59 : ManagedState(MANAGED_TYPE_NETWORK, path), |
| 58 auto_connect_(false), | 60 auto_connect_(false), |
| 59 favorite_(false), | 61 favorite_(false), |
| 60 priority_(0), | 62 priority_(0), |
| 63 onc_source_(onc::ONC_SOURCE_NONE), |
| 61 signal_strength_(0), | 64 signal_strength_(0), |
| 62 activate_over_non_cellular_networks_(false), | 65 activate_over_non_cellular_networks_(false), |
| 63 cellular_out_of_credits_(false) { | 66 cellular_out_of_credits_(false) { |
| 64 } | 67 } |
| 65 | 68 |
| 66 NetworkState::~NetworkState() { | 69 NetworkState::~NetworkState() { |
| 67 } | 70 } |
| 68 | 71 |
| 69 bool NetworkState::PropertyChanged(const std::string& key, | 72 bool NetworkState::PropertyChanged(const std::string& key, |
| 70 const base::Value& value) { | 73 const base::Value& value) { |
| 71 // Keep care that these properties are the same as in |GetProperties|. | 74 // Keep care that these properties are the same as in |GetProperties|. |
| 72 if (ManagedStatePropertyChanged(key, value)) | 75 if (ManagedStatePropertyChanged(key, value)) |
| 73 return true; | 76 return true; |
| 74 if (key == flimflam::kSignalStrengthProperty) { | 77 if (key == flimflam::kSignalStrengthProperty) { |
| 75 return GetIntegerValue(key, value, &signal_strength_); | 78 return GetIntegerValue(key, value, &signal_strength_); |
| 76 } else if (key == flimflam::kStateProperty) { | 79 } else if (key == flimflam::kStateProperty) { |
| 77 return GetStringValue(key, value, &connection_state_); | 80 return GetStringValue(key, value, &connection_state_); |
| 78 } else if (key == flimflam::kErrorProperty) { | 81 } else if (key == flimflam::kErrorProperty) { |
| 79 return GetStringValue(key, value, &error_); | 82 return GetStringValue(key, value, &error_); |
| 80 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 83 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
| 81 return GetStringValue(key, value, &ip_address_); | 84 return GetStringValue(key, value, &ip_address_); |
| 82 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 85 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
| 83 dns_servers_.clear(); | 86 dns_servers_.clear(); |
| 84 const base::ListValue* dns_servers; | 87 const base::ListValue* dns_servers; |
| 85 if (value.GetAsList(&dns_servers) && | 88 if (value.GetAsList(&dns_servers)) |
| 86 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) | 89 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
| 87 return true; | 90 return true; |
| 88 } else if (key == flimflam::kActivationStateProperty) { | 91 } else if (key == flimflam::kActivationStateProperty) { |
| 89 return GetStringValue(key, value, &activation_state_); | 92 return GetStringValue(key, value, &activation_state_); |
| 90 } else if (key == flimflam::kRoamingStateProperty) { | 93 } else if (key == flimflam::kRoamingStateProperty) { |
| 91 return GetStringValue(key, value, &roaming_); | 94 return GetStringValue(key, value, &roaming_); |
| 92 } else if (key == flimflam::kSecurityProperty) { | 95 } else if (key == flimflam::kSecurityProperty) { |
| 93 return GetStringValue(key, value, &security_); | 96 return GetStringValue(key, value, &security_); |
| 94 } else if (key == flimflam::kAutoConnectProperty) { | 97 } else if (key == flimflam::kAutoConnectProperty) { |
| 95 return GetBooleanValue(key, value, &auto_connect_); | 98 return GetBooleanValue(key, value, &auto_connect_); |
| 96 } else if (key == flimflam::kFavoriteProperty) { | 99 } else if (key == flimflam::kFavoriteProperty) { |
| 97 return GetBooleanValue(key, value, &favorite_); | 100 return GetBooleanValue(key, value, &favorite_); |
| 98 } else if (key == flimflam::kPriorityProperty) { | 101 } else if (key == flimflam::kPriorityProperty) { |
| 99 return GetIntegerValue(key, value, &priority_); | 102 return GetIntegerValue(key, value, &priority_); |
| 103 } else if (key == flimflam::kProxyConfigProperty) { |
| 104 std::string proxy_config_str; |
| 105 if (!GetStringValue(key, value, &proxy_config_str)) |
| 106 return false; |
| 107 |
| 108 proxy_config_.Clear(); |
| 109 if (proxy_config_str.empty()) |
| 110 return true; |
| 111 |
| 112 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
| 113 onc::ReadDictionaryFromJson(proxy_config_str)); |
| 114 if (proxy_config_dict) |
| 115 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
| 116 else |
| 117 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 118 return true; |
| 119 } else if (key == flimflam::kUIDataProperty) { |
| 120 std::string ui_data_str; |
| 121 if (!GetStringValue(key, value, &ui_data_str)) |
| 122 return false; |
| 123 |
| 124 onc_source_ = onc::ONC_SOURCE_NONE; |
| 125 if (ui_data_str.empty()) |
| 126 return true; |
| 127 |
| 128 scoped_ptr<base::DictionaryValue> ui_data_dict( |
| 129 onc::ReadDictionaryFromJson(ui_data_str)); |
| 130 if (ui_data_dict) |
| 131 onc_source_ = NetworkUIData(*ui_data_dict).onc_source(); |
| 132 else |
| 133 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 134 return true; |
| 100 } else if (key == flimflam::kNetworkTechnologyProperty) { | 135 } else if (key == flimflam::kNetworkTechnologyProperty) { |
| 101 return GetStringValue(key, value, &technology_); | 136 return GetStringValue(key, value, &technology_); |
| 102 } else if (key == flimflam::kDeviceProperty) { | 137 } else if (key == flimflam::kDeviceProperty) { |
| 103 return GetStringValue(key, value, &device_path_); | 138 return GetStringValue(key, value, &device_path_); |
| 104 } else if (key == flimflam::kGuidProperty) { | 139 } else if (key == flimflam::kGuidProperty) { |
| 105 return GetStringValue(key, value, &guid_); | 140 return GetStringValue(key, value, &guid_); |
| 106 } else if (key == flimflam::kProfileProperty) { | 141 } else if (key == flimflam::kProfileProperty) { |
| 107 return GetStringValue(key, value, &profile_path_); | 142 return GetStringValue(key, value, &profile_path_); |
| 108 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 143 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
| 109 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 144 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 185 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
| 151 roaming()); | 186 roaming()); |
| 152 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 187 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
| 153 security()); | 188 security()); |
| 154 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 189 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
| 155 auto_connect()); | 190 auto_connect()); |
| 156 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 191 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
| 157 favorite()); | 192 favorite()); |
| 158 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 193 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
| 159 priority()); | 194 priority()); |
| 195 // Proxy config and ONC source is intentionally omitted: These properties are |
| 196 // placed in NetworkState to transition ProxyConfigServiceImpl from |
| 197 // NetworkLibrary to the new network stack. The networking extension API |
| 198 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
| 199 // is used instead of NetworkLibrary, we can remove them again. |
| 160 dictionary->SetStringWithoutPathExpansion( | 200 dictionary->SetStringWithoutPathExpansion( |
| 161 flimflam::kNetworkTechnologyProperty, | 201 flimflam::kNetworkTechnologyProperty, |
| 162 technology()); | 202 technology()); |
| 163 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 203 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
| 164 device_path()); | 204 device_path()); |
| 165 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid()); | 205 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid()); |
| 166 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 206 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 167 profile_path()); | 207 profile_path()); |
| 168 dictionary->SetBooleanWithoutPathExpansion( | 208 dictionary->SetBooleanWithoutPathExpansion( |
| 169 shill::kActivateOverNonCellularNetworkProperty, | 209 shill::kActivateOverNonCellularNetworkProperty, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 connection_state == flimflam::kStateConfiguration || | 296 connection_state == flimflam::kStateConfiguration || |
| 257 connection_state == flimflam::kStateCarrier); | 297 connection_state == flimflam::kStateCarrier); |
| 258 } | 298 } |
| 259 | 299 |
| 260 // static | 300 // static |
| 261 std::string NetworkState::IPConfigProperty(const char* key) { | 301 std::string NetworkState::IPConfigProperty(const char* key) { |
| 262 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 302 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
| 263 } | 303 } |
| 264 | 304 |
| 265 } // namespace chromeos | 305 } // namespace chromeos |
| OLD | NEW |