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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversion_utils.h" | 12 #include "base/strings/utf_string_conversion_utils.h" |
13 #include "base/values.h" | |
14 #include "chromeos/network/network_event_log.h" | 13 #include "chromeos/network/network_event_log.h" |
| 14 #include "chromeos/network/network_ui_data.h" |
| 15 #include "chromeos/network/onc/onc_utils.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const char kLogModule[] = "NetworkState"; | 20 const char kLogModule[] = "NetworkState"; |
20 | 21 |
21 bool ConvertListValueToStringVector(const base::ListValue& string_list, | 22 bool ConvertListValueToStringVector(const base::ListValue& string_list, |
22 std::vector<std::string>* result) { | 23 std::vector<std::string>* result) { |
23 for (size_t i = 0; i < string_list.GetSize(); ++i) { | 24 for (size_t i = 0; i < string_list.GetSize(); ++i) { |
24 std::string str; | 25 std::string str; |
(...skipping 26 matching lines...) Expand all Loading... |
51 | 52 |
52 } // namespace | 53 } // namespace |
53 | 54 |
54 namespace chromeos { | 55 namespace chromeos { |
55 | 56 |
56 NetworkState::NetworkState(const std::string& path) | 57 NetworkState::NetworkState(const std::string& path) |
57 : ManagedState(MANAGED_TYPE_NETWORK, path), | 58 : ManagedState(MANAGED_TYPE_NETWORK, path), |
58 auto_connect_(false), | 59 auto_connect_(false), |
59 favorite_(false), | 60 favorite_(false), |
60 priority_(0), | 61 priority_(0), |
| 62 onc_source_(onc::ONC_SOURCE_NONE), |
61 signal_strength_(0), | 63 signal_strength_(0), |
62 connectable_(false), | 64 connectable_(false), |
63 passphrase_required_(false), | 65 passphrase_required_(false), |
64 activate_over_non_cellular_networks_(false), | 66 activate_over_non_cellular_networks_(false), |
65 cellular_out_of_credits_(false) { | 67 cellular_out_of_credits_(false) { |
66 } | 68 } |
67 | 69 |
68 NetworkState::~NetworkState() { | 70 NetworkState::~NetworkState() { |
69 } | 71 } |
70 | 72 |
(...skipping 10 matching lines...) Expand all Loading... |
81 return GetBooleanValue(key, value, &connectable_); | 83 return GetBooleanValue(key, value, &connectable_); |
82 } else if (key == flimflam::kPassphraseRequiredProperty) { | 84 } else if (key == flimflam::kPassphraseRequiredProperty) { |
83 return GetBooleanValue(key, value, &passphrase_required_); | 85 return GetBooleanValue(key, value, &passphrase_required_); |
84 } else if (key == flimflam::kErrorProperty) { | 86 } else if (key == flimflam::kErrorProperty) { |
85 return GetStringValue(key, value, &error_); | 87 return GetStringValue(key, value, &error_); |
86 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { | 88 } else if (key == IPConfigProperty(flimflam::kAddressProperty)) { |
87 return GetStringValue(key, value, &ip_address_); | 89 return GetStringValue(key, value, &ip_address_); |
88 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { | 90 } else if (key == IPConfigProperty(flimflam::kNameServersProperty)) { |
89 dns_servers_.clear(); | 91 dns_servers_.clear(); |
90 const base::ListValue* dns_servers; | 92 const base::ListValue* dns_servers; |
91 if (value.GetAsList(&dns_servers) && | 93 if (value.GetAsList(&dns_servers)) |
92 ConvertListValueToStringVector(*dns_servers, &dns_servers_)) | 94 ConvertListValueToStringVector(*dns_servers, &dns_servers_); |
93 return true; | 95 return true; |
94 } else if (key == flimflam::kActivationStateProperty) { | 96 } else if (key == flimflam::kActivationStateProperty) { |
95 return GetStringValue(key, value, &activation_state_); | 97 return GetStringValue(key, value, &activation_state_); |
96 } else if (key == flimflam::kRoamingStateProperty) { | 98 } else if (key == flimflam::kRoamingStateProperty) { |
97 return GetStringValue(key, value, &roaming_); | 99 return GetStringValue(key, value, &roaming_); |
98 } else if (key == flimflam::kSecurityProperty) { | 100 } else if (key == flimflam::kSecurityProperty) { |
99 return GetStringValue(key, value, &security_); | 101 return GetStringValue(key, value, &security_); |
100 } else if (key == flimflam::kAutoConnectProperty) { | 102 } else if (key == flimflam::kAutoConnectProperty) { |
101 return GetBooleanValue(key, value, &auto_connect_); | 103 return GetBooleanValue(key, value, &auto_connect_); |
102 } else if (key == flimflam::kFavoriteProperty) { | 104 } else if (key == flimflam::kFavoriteProperty) { |
103 return GetBooleanValue(key, value, &favorite_); | 105 return GetBooleanValue(key, value, &favorite_); |
104 } else if (key == flimflam::kPriorityProperty) { | 106 } else if (key == flimflam::kPriorityProperty) { |
105 return GetIntegerValue(key, value, &priority_); | 107 return GetIntegerValue(key, value, &priority_); |
| 108 } else if (key == flimflam::kProxyConfigProperty) { |
| 109 std::string proxy_config_str; |
| 110 if (!GetStringValue(key, value, &proxy_config_str)) |
| 111 return false; |
| 112 |
| 113 proxy_config_.Clear(); |
| 114 if (proxy_config_str.empty()) |
| 115 return true; |
| 116 |
| 117 scoped_ptr<base::DictionaryValue> proxy_config_dict( |
| 118 onc::ReadDictionaryFromJson(proxy_config_str)); |
| 119 if (proxy_config_dict) |
| 120 proxy_config_.MergeDictionary(proxy_config_dict.get()); |
| 121 else |
| 122 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 123 return true; |
| 124 } else if (key == flimflam::kUIDataProperty) { |
| 125 std::string ui_data_str; |
| 126 if (!GetStringValue(key, value, &ui_data_str)) |
| 127 return false; |
| 128 |
| 129 onc_source_ = onc::ONC_SOURCE_NONE; |
| 130 if (ui_data_str.empty()) |
| 131 return true; |
| 132 |
| 133 scoped_ptr<base::DictionaryValue> ui_data_dict( |
| 134 onc::ReadDictionaryFromJson(ui_data_str)); |
| 135 if (ui_data_dict) |
| 136 onc_source_ = NetworkUIData(*ui_data_dict).onc_source(); |
| 137 else |
| 138 LOG(WARNING) << "Failed to parse dictionary value for: " << key; |
| 139 return true; |
106 } else if (key == flimflam::kNetworkTechnologyProperty) { | 140 } else if (key == flimflam::kNetworkTechnologyProperty) { |
107 return GetStringValue(key, value, &technology_); | 141 return GetStringValue(key, value, &technology_); |
108 } else if (key == flimflam::kDeviceProperty) { | 142 } else if (key == flimflam::kDeviceProperty) { |
109 return GetStringValue(key, value, &device_path_); | 143 return GetStringValue(key, value, &device_path_); |
110 } else if (key == flimflam::kGuidProperty) { | 144 } else if (key == flimflam::kGuidProperty) { |
111 return GetStringValue(key, value, &guid_); | 145 return GetStringValue(key, value, &guid_); |
112 } else if (key == flimflam::kProfileProperty) { | 146 } else if (key == flimflam::kProfileProperty) { |
113 return GetStringValue(key, value, &profile_path_); | 147 return GetStringValue(key, value, &profile_path_); |
114 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { | 148 } else if (key == shill::kActivateOverNonCellularNetworkProperty) { |
115 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); | 149 return GetBooleanValue(key, value, &activate_over_non_cellular_networks_); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, | 194 dictionary->SetStringWithoutPathExpansion(flimflam::kRoamingStateProperty, |
161 roaming_); | 195 roaming_); |
162 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, | 196 dictionary->SetStringWithoutPathExpansion(flimflam::kSecurityProperty, |
163 security_); | 197 security_); |
164 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, | 198 dictionary->SetBooleanWithoutPathExpansion(flimflam::kAutoConnectProperty, |
165 auto_connect_); | 199 auto_connect_); |
166 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, | 200 dictionary->SetBooleanWithoutPathExpansion(flimflam::kFavoriteProperty, |
167 favorite_); | 201 favorite_); |
168 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, | 202 dictionary->SetIntegerWithoutPathExpansion(flimflam::kPriorityProperty, |
169 priority_); | 203 priority_); |
| 204 // Proxy config and ONC source is intentionally omitted: These properties are |
| 205 // placed in NetworkState to transition ProxyConfigServiceImpl from |
| 206 // NetworkLibrary to the new network stack. The networking extension API |
| 207 // shouldn't depend on this member. Once ManagedNetworkConfigurationHandler |
| 208 // is used instead of NetworkLibrary, we can remove them again. |
170 dictionary->SetStringWithoutPathExpansion( | 209 dictionary->SetStringWithoutPathExpansion( |
171 flimflam::kNetworkTechnologyProperty, | 210 flimflam::kNetworkTechnologyProperty, |
172 technology_); | 211 technology_); |
173 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, | 212 dictionary->SetStringWithoutPathExpansion(flimflam::kDeviceProperty, |
174 device_path_); | 213 device_path_); |
175 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); | 214 dictionary->SetStringWithoutPathExpansion(flimflam::kGuidProperty, guid_); |
176 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 215 dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
177 profile_path_); | 216 profile_path_); |
178 dictionary->SetBooleanWithoutPathExpansion( | 217 dictionary->SetBooleanWithoutPathExpansion( |
179 shill::kActivateOverNonCellularNetworkProperty, | 218 shill::kActivateOverNonCellularNetworkProperty, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 connection_state == flimflam::kStateConfiguration || | 305 connection_state == flimflam::kStateConfiguration || |
267 connection_state == flimflam::kStateCarrier); | 306 connection_state == flimflam::kStateCarrier); |
268 } | 307 } |
269 | 308 |
270 // static | 309 // static |
271 std::string NetworkState::IPConfigProperty(const char* key) { | 310 std::string NetworkState::IPConfigProperty(const char* key) { |
272 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); | 311 return base::StringPrintf("%s.%s", shill::kIPConfigProperty, key); |
273 } | 312 } |
274 | 313 |
275 } // namespace chromeos | 314 } // namespace chromeos |
OLD | NEW |